Telegram.Bot icon indicating copy to clipboard operation
Telegram.Bot copied to clipboard

Stopping a receiving messages when an error occurs

Open SijyKijy opened this issue 4 years ago • 6 comments

When an error occurs in HandleUpdateAsync and HandleErrorAsync methods, bot stop receiving messages. Is that how it's supposed to work?

https://github.com/TelegramBots/Telegram.Bot.Extensions.Polling/blob/52c1edf4ff13d97c0b6d5ed8a62631cceadd9210/src/Telegram.Bot.Extensions.Polling/DefaultUpdateReceiver.cs#L99-L115

SijyKijy avatar Aug 12 '21 13:08 SijyKijy

Yes, that's the expected behaviour, it's the same as with previous events in the client.

If there's an exception in user code we can't do anything other than stop execution.

tuscen avatar Aug 12 '21 13:08 tuscen

How should I restart receiver when an exception throwing?

SijyKijy avatar Aug 12 '21 13:08 SijyKijy

If there is an exception in the user code, then we will fall into updateHandler.HandleErrorAsync, which is called in https://github.com/TelegramBots/Telegram.Bot.Extensions.Polling/blob/52c1edf4ff13d97c0b6d5ed8a62631cceadd9210/src/Telegram.Bot.Extensions.Polling/Extensions/TelegramBotClientPollingExtensions.cs#L158. It turns out that HandleErrorAsync will be called not only to handle receiving updates, but also to handle custom code in updateHandler.HandleUpdateAsync

LIFEfreedom avatar Aug 12 '21 13:08 LIFEfreedom

There is a way to automatically restart the bot after an exception? I also have the same problem, but I'm receiving exception because a user has blocked the bot. I don't want to wrap each call to sendMessageAsync with a try-catch to avoid interruption, is there another way?

lorenzo93 avatar Mar 22 '23 14:03 lorenzo93

#1106

karb0f0s avatar Mar 22 '23 15:03 karb0f0s

i have this problem, my bot stop receiving messages for any problem and after restarting bot , it working fine again. how i can restart bot automatically when an error occur ?

mostafafayyaz avatar Jul 24 '23 14:07 mostafafayyaz