D
D
dani1il2020-07-25 23:03:41
Python
dani1il, 2020-07-25 23:03:41

Telegram bot spam protection?

How can I implement spam protection for a telegram bot? Since if a user sends a lot of requests in a short time, the script crashes and gives an error - request to the Telegram API was unsuccessful. The server returned HTTP 429 Too Many Requests. response body...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-07-26
@dani1il

If the problem is that the bot sends a telegram to api more than 30 hits per second:
Store the time of the user's last hit and on a new hit check the difference between the current time and the time of the last hit, if it's less than the limit, then just ignore this message.
An example of the implementation of anti-flood through the decorator can be seen at aiogram
. Also, a similar error occurs when quickly removing-setting a webhook, when, on the advice of a thread of the guide, you re-hang the webhook every time you start the bot and before that you remove it just in case. If so, then between these actions you need to put a delay.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question