How to get messages that were not delivered while Telegram Bot web-server was down?

1.6k Views Asked by At

Curious, if there is way to avoid skipping messages sent from Telegram Bot while web-server that accepts Webhooks is down (because of redeploy, failure or maintenance).

When you use polling - Telegram API sends messages starting from last retrieved and no message are skipped.

But how to be with Webhooks? Use polling or there are some special mechanism for that?

2

There are 2 best solutions below

2
On BEST ANSWER

Telegram keeps the incoming message for 24hrs, if you are Webhook is down (ie redeploying) then the message will be delivered once it is again online.

It works on Heroku for example where your Dyno is down: as soon as it starts the Chatbot will register again with Telegram and will receive the messages still available in the queue.

There are two mutually exclusive ways of receiving updates for your bot — the getUpdates method on one hand and Webhooks on the other. Incoming updates are stored on the server until the bot receives them either way, but they will not be kept longer than 24 hours.

See Telegram documentation for more details.

1
On

I had the same problem recently but I just resolved it by when the server starts save the started time to a variable and then use Telegrambot.Message.date and compare the time if it was sent before the server start time or not.