AnyEvent-SparkBot
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/AnyEvent/SparkBot.pm view on Meta::CPAN
no namespace::clean;
with 'HTTP::MultiGet::Role', 'AnyEvent::SparkBot::SharedRole';
}
=head1 NAME
AnyEvent::SparkBot - Cisco Spark WebSocket Client for the AnyEvent Loop
=head1 SYNOPSIS
use Modern::Perl;
use Data::Dumper;
use AnyEvent::SparkBot;
use AnyEvent::Loop;
$|=1;
our $obj=new AnyEvent::SparkBot(token=>$ENV{SPARK_TOKEN},on_message=>\&cb);
$obj->que_getWsUrl(sub {
my ($agent,$id,$result)=@_;
# start here if we got a valid connection
return $obj->start_connection if $result;
$obj->handle_reconnect;
});
$obj->agent->run_next;
AnyEvent::Loop::run;
sub cb {
my ($sb,$result,$eventType,$verb,$json)=@_;
return unless $eventType eq 'conversation.activity' and $verb eq 'post';
# Data::Result Object is False when combination of EvenType and Verb are unsupprted
if($result) {
my $data=$result->get_data;
my $response={
roomId=>$data->{roomId},
personId=>$data->{personId},
text=>"ya.. ya ya.. I'm on it!"
};
# Proxy our lookup in a Retry-After ( prevents a lot of errors )
$obj->run_lookup('que_createMessage',(sub {},$response);
} else {
print "Error: $result\n";
}
}
=head1 DESCRIPTION
Connects to cisco spark via a websocket. By itself this class only provides connectivty to Spark, the on_message callback is used to handle events that come in. By default No hanlder is provided.
=head1 Moo Role(s)
This module uses the following Moo role(s)
HTTP::MultiGet::Role
AnyEvent::SparkBot::SharedRole
=cut
has retryTimeout=>(
is=>'ro',
isa=>Int,
default=>10,
lazy=>1,
);
has retryCount=>(
is=>'ro',
isa=>Int,
default=>1,
lazy=>1,
);
has retries=>(
is=>'ro',
isa=>HashRef,
lazy=>1,
default=>sub { {} },
required=>0,
);
has reconnect_sleep=>(
is=>'ro',
isa=>Int,
default=>10,
required=>1,
);
has reconnect=>(
is=>'ro',
isa=>Bool,
default=>1,
required=>1,
);
has pingEvery=>(
is=>'ro',
isa=>Int,
default=>60,
);
has pingWait=>(
is=>'ro',
isa=>Int,
default=>10,
);
has ping=>(
is=>'rw',
);
has lastPing=>(
is=>'rw',
isa=>Str,
lazy=>1,
);
has connInfo=>(
is=>'rw',
lazy=>1,
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.950 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )