AnyEvent-SlackRTM
view release on metacpan or search on metacpan
1.3 2022-07-29 12:41:25-05:00 America/Chicago
* Switch from rtm.start to rtm.connect. (HT: @afresh1)
* Add keep-alive watchdog timer to keep the connection up. (HT: @afresh1)
1.1 2019-10-03 14:01:15-05:00 America/Chicago
* Adding client options to constructor to allow options to be passed through
to the underlying AnyEvent::WebSocket::Client connection. (HT: ibutorin)
1.0 2017-09-21 21:56:14-05:00 America/Chicago
* Fixed a bug where errors weren't quieted when the quiet flag was set by
the developer.
lib/AnyEvent/SlackRTM.pm view on Meta::CPAN
delete $self->{finished};
$self->{started}++;
$self->{id} = 1;
my $conn = $self->{conn} = $client->recv;
$conn->on( each_message => sub { $self->_handle_incoming(@_) } );
$conn->on( finish => sub { $self->_handle_finish(@_) } );
my $started = localtime;
$self->{_last_keep_alive} = time;
$self->{keep_alive} = AnyEvent->timer(
after => 15,
interval => 15,
cb => sub {
my $id = $self->{id};
my $now = time;
my $since = $now - $self->{_last_keep_alive};
if ( $since > 30 ) {
# will trigger a finish, which will reconnect
# if $self->{closed} is not set.
$conn->close;
lib/AnyEvent/SlackRTM.pm view on Meta::CPAN
my $cond = AnyEvent->condvar;
my $rtm = AnyEvent::SlackRTM->new($access_token);
my $i = 1;
my $keep_alive;
my $counter;
$rtm->on('hello' => sub {
print "Ready\n";
$keep_alive = AnyEvent->timer(interval => 60, cb => sub {
print "Ping\n";
$rtm->ping;
});
$counter = AnyEvent->timer(interval => 5, cb => sub {
print "Send\n";
$rtm->send({
type => 'message',
channel => $channel_id,
text => "".$i++,
});
});
});
$rtm->on('message' => sub {
my ($rtm, $message) = @_;
lib/AnyEvent/SlackRTM.pm view on Meta::CPAN
The C<$client_opts> is an optional HashRef of L<AnyEvent::WebSocket::Client>'s configuration options, e.g. C<env_proxy>, C<max_payload_size>, C<timeout>, etc.
=head2 start
method start()
This will establish the WebSocket connection to the Slack RTM service.
You should have registered any events using L</on> before doing this or you may miss some events that arrive immediately.
Sets up a "keep alive" timer,
which triggers every 15 seconds to send a C<ping> message
if there hasn't been any activity in the past 10 seconds.
The C<ping> will trigger a C<pong> response,
so there should be at least one message every 15 seconds.
This will disconnect if no messages have been received in the past 30 seconds;
however, it should trigger an automatic reconnect to keep the connection alive.
=head2 metadata
method metadata() returns HashRef
( run in 1.473 second using v1.01-cache-2.11-cpan-49f99fa48dc )