gringobot
gringobot copied to clipboard
Handle 429 response codes when running message recycling
Describe the bug
When there are too many messages to be deleted, the server triggers too many calls at once to Telegram API and reaches the rate limit, which then makes it start to reply with the following:
(node:1) UnhandledPromiseRejectionWarning: Error: 429: Too Many Requests: retry after 6
at Telegram.callApi (/app/node_modules/telegraf/lib/core/network/client.js:258:19)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
To Reproduce Steps to reproduce the behaviour:
- Get the bot running and added into a channel
- Trigger multiple messages that are candidates for message recycling very quickly
- Wait until the next message recycling cycle
- See errors
Expected behaviour The message recycling logic should consider that the rate limits might be reached and should defer message deletion according to the suggestions given by the Telegram API (e.g.: retry in 6 as told by the example)