|
|
@@ -175,22 +175,26 @@ sub incoming_message
|
|
|
unless ($sub)
|
|
|
{
|
|
|
$log->error("Unknown message: ".$rk);
|
|
|
+ $rabbit->reply($m, "Unknown message") if $m->{header}->{reply_to};
|
|
|
$rabbit->reject($m);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ my $res;
|
|
|
eval {
|
|
|
- $sub->($body,$m);
|
|
|
+ $res = $sub->($body,$m);
|
|
|
};
|
|
|
|
|
|
if ($@)
|
|
|
{
|
|
|
$log->error(Dumper $@);
|
|
|
+ $rabbit->reply($m, $@) if $m->{header}->{reply_to};
|
|
|
$rabbit->reject($m);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
$rabbit->ack($m);
|
|
|
+ $rabbit->reply($m, $res) if $m->{header}->{reply_to};
|
|
|
$log->debug("acknowledged") if $config->{debug};
|
|
|
}
|
|
|
}
|
|
|
@@ -201,10 +205,23 @@ sub notify::telegram::send
|
|
|
my $to = $body->{to};
|
|
|
$to = [ $to ] unless ref($to) eq "ARRAY";
|
|
|
|
|
|
+ my @results;
|
|
|
+
|
|
|
foreach (@$to)
|
|
|
{
|
|
|
- notify($_, $body->{message}, $body);
|
|
|
+ notify($_, $body->{message}, $body)->then(sub
|
|
|
+ {
|
|
|
+ my $reply = shift;
|
|
|
+ push @results, { success=>1, msgid=>$reply->{result}->{message_id}, chat=>$reply->{chat}->{id} };
|
|
|
+ })
|
|
|
+ ->catch(sub
|
|
|
+ {
|
|
|
+ my $reply = shift;
|
|
|
+ push @results, {success=>0, error => ref($reply) ? "$reply->{code}: $reply->{body}->{description}" : $reply};
|
|
|
+ })
|
|
|
}
|
|
|
+
|
|
|
+ return \@results;
|
|
|
}
|
|
|
|
|
|
############################
|