Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopping a receiving messages when an error occurs #1107

Open
SijyKijy opened this issue Aug 12, 2021 · 6 comments
Open

Stopping a receiving messages when an error occurs #1107

SijyKijy opened this issue Aug 12, 2021 · 6 comments

Comments

@SijyKijy
Copy link

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

@tuscen
Copy link
Member

tuscen commented Aug 12, 2021

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.

@SijyKijy
Copy link
Author

SijyKijy commented Aug 12, 2021

How should I restart receiver when an exception throwing?

@LIFEfreedom
Copy link

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

@tuscen tuscen transferred this issue from TelegramBots/Telegram.Bot.Extensions.Polling Jun 18, 2022
@lorenzo93
Copy link

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?

@karb0f0s
Copy link
Member

#1106

@mostafafayyaz
Copy link

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants