Bot-ChatBots-Telegram
view release on metacpan or search on metacpan
lib/Bot/ChatBots/Telegram/LongPoll.pm view on Meta::CPAN
);
my $sender = $self->sender;
$sender->telegram->agent->connect_timeout($self->connect_timeout)
->inactivity_timeout($update_timeout + 5)
->max_redirects($self->max_redirects);
# this flag tells us whether we're in a call already, avoiding
# duplicates. It is set before sending a request, and reset when the
# response is managed
my $is_busy;
my $on_data = sub {
my ($ua, $tx) = @_;
my @updates;
try {
@updates = $self->parse_response($tx->res, $query{offset});
}
catch {
$log->error(bleep $_);
lib/Bot/ChatBots/Telegram/LongPoll.pm view on Meta::CPAN
defined(my $outcome = $item->{outcome}) or next;
defined(my $message = $outcome->{send_response}) or next;
$sender->send_message($message, record => $record);
}
# if we get here, somehow me managed to get past this call... Get
# ready for the next one. Just to be on the safe side, we will
# advance $query{offset} anyway
$query{offset} = 1 + max map { $_->{update_id} } @updates
if @updates;
$is_busy = 0;
};
return sub {
return if $is_busy;
$is_busy = 1; # $on_data below will reset $is_busy when ready
$sender->send_message(\%query, callback => $on_data);
};
} ## end sub callback
around process => sub {
my ($orig, $self, $record) = @_;
my $outcome = $orig->($self, $record);
$record->{source}{query}{offset} = $record->{update}{update_id} + 1;
return $outcome;
};
( run in 0.424 second using v1.01-cache-2.11-cpan-87723dcf8b7 )