AnyEvent-SlackBot
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/AnyEvent/SlackBot.pm view on Meta::CPAN
package AnyEvent::SlackBot;
use Modern::Perl;
use Moo;
use MooX::Types::MooseLike::Base qw(:all);
use namespace::clean;
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Request;
use URI::Escape;
use HTTP::Request::Common qw(POST);
use AnyEvent::HTTP::MultiGet;
use AnyEvent::WebSocket::Client;
use JSON;
use namespace::clean;
use IO::Socket::SSL;
our $VERSION='1.0005';
BEGIN {
no namespace::clean;
with 'Log::LogMethods','Data::Result::Moo';
}
=head1 NAME
AnyEvent::SlackBot - AnyEvent Driven Slack Bot Interface
=head1 SYNOPSIS
use Modern::Perl;
use Data::Dumper;
use AnyEvent::SlackBot;
use AnyEvent::Loop;
$|=1;
my $sb=AnyEvent::SlackBot->new(
on_event=>sub {
my ($sb,$json,$conn_data)=@_;
if(exists $json->{type} and $json->{type} eq 'desktop_notification') {
my $ref={
type=>'message',
bot_id=>$sb->bot_id,
channel=>$json->{channel},
text=>'this is a test',
subtype=>'bot_message',
};
print Dumper($json,$ref);
$sb->send($ref);
}
},
);
my $result=$sb->connect_and_run;
die $result unless $result;
AnyEvent::Loop::run;
=head1 DESCRIPTION
Slack client. Handles Ping Pong on idle conntions, and transparrently reconnects as needed. The guts of the module wrap AnyEvent::WebSocket::Client, keeping the code base very light.
=head1 OO Arguments and accessors
Required Arguments
on_event: code refrence for handling events
sub { my ($self,$connection,$message,$startup_info)=@_ }
Optional Arguments
on_idle: code refrence for use in idle time
sub { my ($self)=@_ }
on_reply: code refrence called when the server responds to a post
sub { my ($self,$json,$connection_data)=@_ }
agent: Sets the AnyEvent::HTTP::MultiGet Object
logger: sets the logging object, DOES( Log::Log4perl::Logger )
rtm_start_url: the url used to fetch the websockets connection from
token: the authentication token used by rtm_start_url
auto_reconnect: if true ( default ) reconnects when a connection fails
unknown_que: array ref of objects that may be repeats from us
Set at Run time
connection: The connection object
bot_id: The Bot ID defined at runtime
stats: An anonyous hash ref of useful stats
=cut
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.613 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )