telegram-bot-ruby
telegram-bot-ruby copied to clipboard
Bot kick from chat exception
Hi When some users add bot to chat and after that chat admins remove bot , script stop working and show error "bot kick from chat" . how can i resolve this issue? this is showstopper for me and my bot is going down.
Please assist me.
Hi @sinaeftekhari I had the same problem, please read here the story: http://stackoverflow.com/questions/34040277/telegram-bot-api-errors-codes-integrating-groups-and-channels BTW, if you feel useful my question & my answer on stackoverflow, please vote them :)
So, IMMO this issue is NOT related with this gem, but it's instead a Telegram Bot internal server "bug"/issue (this is my temporary conclusion).
I'm also discussing with telegram.me/BotSupport: they say is not a bug, I say is it a bug/issue! So please expose you too the problem to @BotSupport Telegram support account.
I believe this issue have to be closed here.
BTW, let us know (here or on my stackoverflow question), if you discover a solution giorgio
Hi @solyaris
Yes ,i know this issue , bot we need to define some exception to handle this issue , i check some other Gems and all of them handle , they have a silence_faild and with this function we can handle this exceptions .
@sinaeftekhari Yes, adding such option might be a good idea, will work on it in future versions.
I have encountered this issue too. With the example here this happens, but I have figured that if you comment the action in the else block (_ bot.api.send_message(chat_id: message.chat.id, text: "I don't understand you :(")_) the exception is ignored.
I think that is a workaround for that specific code structure. I have had success avoiding this error also by surrounding all the code in which the messages from the chat are treated by a begin/rescue block . I'm not sure if this a good behaviour but it seems to work for now.
@manglasape I suspect the exception is ignored just because commenting the send_message ... you don't send_message :) or i'm wrong ?
@sinaeftekhari this gem could implement some nice exception handling, but still remain the fact that if you get a 400 code (Bad Request: group is deactivated) or a 403 code (Bot was kicked from a chat), when callling a send_message, this is, IMMO a Telegram Server BUG that happens when you remove a bot from a group, as I documented in my stackoverflow complain. In this unclear scenario, unfortunately there is no way to use the same Bot (name) anymore (at least this have been my experience). I complained about it with Telegram support but I did't get a clear answer.
Last but not least, unfortunately there is no a Telegram error code explanation doc, as far as i know. Isnt'it ?
@manglasape Yes, you have to rescue from ResponseError manually, like this:
Telegram::Bot::Client.run(token, logger: Logger.new($stdout)) do |bot|
begin
bot.listen do |message|
# Do something
end
rescue Telegram::Bot::Exceptions::ResponseError => e
retry
end
end
I'm still not sure if it's a good idea to hide errors like this from user. It may make debugging your bot harder.
@atipugin yes, but unfortunately the retry statement just keep the stall; the issue I experienced was systematic: when i started to get these 400/403 error codes, the bot became no more usable :-(
off-topic: thanks for your again for this gem and your updates for inline mode. I mentioned it on my pseudo-article about a possible "business" usage of the new feature: https://gist.github.com/solyaris/b83a3cbc14d2be9a5cef#programming-in-ruby
regards
@atipugin Yes, that's exactly what I've done, thanks!
@solyaris thanks, inline bots are great, i really like this feature.
Regarding your issue with retry statement - i can't reproduce your error, retry works for me. Could your tell me a little more what your try to do and show your code?
@atipugin Hi Alexander I reported the scenario here: http://stackoverflow.com/questions/34040277/telegram-bot-api-errors-codes-integrating-groups-and-channels
I used your APis in my project BOTServer. Here the specific code: https://github.com/solyaris/BOTServer/blob/master/templates/app.rb.template (nothing special: is an update received through a webhoock, that elaborate somewhere the received message and do a send:message ... it seems perverse because the code here is a template ... part of the BOTServer framework: app code is generate as like a Rails scaffold..., but all in all is just a simple request/reply REPL...)
As I said in previous comment, the point is not related to your gem and the exception handling you proposed here (rescue/retry) is ok for me.
IMMO the issue happens after some Telegram server internal "wrong" state of a bot, that make the bot no more usable :-( In past I experienced these 400/403 errors with a certain bot name I created months before. After inserting/removing that bot in/out a group, the bot started to reject send_messages with these error codes. I solved ... no more using that bot name that gone in this strange no-exit state. I believe that something wrong happened inside the telegram server db. I don't know. I solved just no more use that specific bot. Let me know if my explanation have been clear :)
I had a similar issue where I get the error whenever the bot is added then removed from a group and was able to fix it just by manually fetching the message using https://api.telegram.org/bot
Handling the exception with retry as @atipugin mentioned works fine with me as well, not sure if the retry statement forced the message to be consumed and jumped to the next one. In any case, do you think we can do the same with webhooks implementation or include the exception handling in the gem itself?
I'm experiencing the same issue too, but I don't understand what you guys mean when you say that you must delete and crete a new bot with another name. Do you mean that I should do this only if I wanted my bot back in a group? Because right now it's still working normally when you send commands to it.
UPDATE = Actually I just created a group and it seems to work just fine.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.
please take open the issue
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.