NAME
Net::MyPeople::Bot - Implements MyPeople-Bot.
VERSION
version 0.1
SYNOPSIS
use Net::MyPeople::Bot;
use AnyEvent::HTTPD;
use Data::Dumper;
my $bot = Net::MyPeople::Bot({apikey=>'MYPEOPLE_BOT_APIKEY'});
# You can get MYPEOPLE_BOT_APIKEY at http://dna.daum.net/myapi/authapi/mypeople
# You should set up CALLBACK URL with below informations. ex) http://MYSERVER:8080/callback
my $httpd = AnyEvent::HTTPD->new (port => 8080);
$httpd->reg_cb (
'/callback' => sub {
my ($httpd, $req) = @_;
my $action = $req->parm('action');
my $buddyId = $req->parm('buddyId');
my $groupId = $req->parm('groupId');
my $content = $req->parm('content');
callback( $action, $buddyId, $groupId, $content );
}
);
sub callback{
my ($action, $buddyId, $groupId, $content ) = @_;
if ( $action eq 'addBuddy' ){ # when someone add this bot as a buddy.
my $buddy = $bot->buddy($buddyId); # hashref
my $buddy_name = $buddy->{buddys}->{name};
my $res = $bot->send($buddyId, "Nice to meet you, $buddy_name");
}
elsif( $action eq 'sendFromMessage' ){ # when someone send a message to this bot.
if($content =~ /^myp_pci:/){
$bot->fileDownload($content,'./sample.jpg');
}
elsif($content =~ /sendtest/){
$bot->send($buddyId,undef,'./sample.jpg');
}
else{
my @res = $bot->send($buddyId, "$content");
}
}
elsif( $action eq 'createGroup' ){ # when this bot invited to a group chat channel.
my $res = $bot->groupSend($groupId, 'Nice to meet you, guys.');
# CONTENT
# [
# {"buddyId":"BU_ey3aPnSCpzx3ccwqidwdfg00","isBot":"Y","name":"testbot","photoId":"myp_pub:51A586C2074DB00010"},
# {"buddyId":"BU_ey3aPnSCpzx3ccwqidwdfg00","isBot":"Y","name":"testbot","photoId":"myp_pub:51A586C2074DB00010"}
# ]
}
elsif( $action eq 'inviteToGroup' ){ # when someone in a group chat channel invites user to the channel.
my $buddy_name = $content->[0]->{name};
my $is_bot = $content->[0]->{is_bot} eq 'Y';
# CONTENT
# [
# {"buddyId":"BU_ey3aPnSCpzx3ccwqidwdfg00","isBot":"Y","name":"testbot","photoId":"myp_pub:51A586C2074DB00010"}
# ]
if( $is_bot ){ # bot self
my $res = $bot->groupSend($groupId, 'Nide to meet you, guys');
}
else{ # other guy
my $res = $bot->groupSend($groupId, "$buddy_name, Can you introduce your self?");
}
}
elsif( $action eq 'exitFromGroup' ){ # when someone in a group chat channel leaves.
my $buddy = $bot->buddy($buddyId); # hashref
my $buddy_name = $buddy->{buddys}->[0]->{name};
my $res = $bot->sendGroup($groupId, "I'll miss $buddy_name ...");
}
elsif( $action eq 'sendFromGroup'){ # when received from group chat channel
if( $content eq 'bot.goout' ){ # a reaction for an user defined command, 'bot.goout'
my $res = $bot->groupSend($groupId, 'Bye~');
$res = $bot->groupExit($groupId);
}
else{
my $res = $bot->groupSend($groupId, "(GROUP_ECHO) $content");
}
}
}
$httpd->run;
Description
MyPeople is an instant messenger service of Daum Communications in Republic of Korea (South Korea).
MyPeople Bot is API interface of MyPeople.
If you want to use this bot API, Unfortunately,you must have an account for http://www.daum.net. And you can understand Korean.
Other details will be updated soon. Sorry :-)
See Also
MyPeople Bot API Home : http://dna.daum.net/apis/mypeople
AUTHOR
khs <sng2nara@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by khs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 300:
'=item' outside of any '=over'
- Around line 308:
You forgot a '=back' before '=head1'