Telegram Bot API for setWebhook says
Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts.
My Telegram bot webhook was unreachable due to maintenance, during this lapse of time users sent a lot of message requests that my bot doesn't process immediately. When the bot was available again Telegram sent all of the pending POST requests to the webhook causing a few issues to the server and the users.
Is it possible to ignore these requests or to say Telegram to give up instantly after the first unsuccessful request?
Unfortunately, They don't provide any way to stop the requests temporarily. They'll keep sending until you send them back a confirmation with a status code 200.
When you go into maintenance mode, If you can respond Telegram with status code 200 and accept the incoming update (Probably store it in your pending messages table to later process it or just ignore them), then you should be good.
If that isn't possible, what you can do instead is, remove webhook using the removeWebhook() method before going into maintenance mode and when you return, use the getUpdates() method to process any pending requests until they're all cleared manually.
Once you see there are no pending updates, you can then set the webhook again which will re-enable Telegram API to send any new incoming updates to your server.
Hope that helps!
Most helpful comment
Unfortunately, They don't provide any way to stop the requests temporarily. They'll keep sending until you send them back a confirmation with a status code 200.
When you go into maintenance mode, If you can respond Telegram with status code 200 and accept the incoming update (Probably store it in your pending messages table to later process it or just ignore them), then you should be good.
If that isn't possible, what you can do instead is, remove webhook using the
removeWebhook()method before going into maintenance mode and when you return, use thegetUpdates()method to process any pending requests until they're all cleared manually.Once you see there are no pending updates, you can then set the webhook again which will re-enable Telegram API to send any new incoming updates to your server.
Hope that helps!