EatMoreCode / Telegram-Bot

Perl module to make creating new Telegram bots easy
4 stars 6 forks source link

If there is no permission to send message to chat, Telegram-Bot dies, when tries to do so. #3

Open eleksir opened 4 years ago

eleksir commented 4 years ago

Looks like user says something in polska mova and bot dies with

Mojo::Reactor::Poll: I/O watcher failed: Failed to post: Bad Request at vendor_perl/lib/perl5/Telegram/Bot/Brain.pm line 240.

It happens until i change

elsif ($res->is_error)   { die "Failed to post: " . $res->message; }

to

  elsif ($res->is_error)   {
        warn "Failed to post: " . $res->message;
        return $res->json->{result};
  }

I'll fish a bit what can possibly go wrong, but it looks like utf-8 issue.

Maybe change hard die to soft warn is not that bad idea?

eleksir commented 4 years ago

Ah! I pin down root of this issue.

That is not a private chat, it is public chat that have very strict policy: members are not allowed to send messages, so bot is unable to send message to this group and dies! They add bot to admins and everything becomes okay.

Can we make a check in bot that it can send messages in group it participating? or we have to do it not directly in framework, but in script that uses this Telegram-Bot?

It looks like in Telegram/Bot/Brain.pm in _post_request() we should not die, but return to caller an error, and on caller side, in case of error we should check that bot have permissions ~to send nudes~, sorry, to send messages, voice messages, photos, videos, etc. And if there is no permission, Telegram-Bot should warn about it and do not die, just do nothing.