R
R
r1dddy4sv2020-12-30 11:21:35
Bots
r1dddy4sv, 2020-12-30 11:21:35

How to limit the number of requests in Telegram BOT API?

I have a written, working, most common telegram bot. But the fact is that the user can click on the inline button in a very short period of time several times before the possibility of pressing this button disappears, and thus several responses are sent to the user, which, accordingly, I would like to avoid.

Is it possible to somehow limit the number of inline requests from the user per second? For example, up to one request per second.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2020-12-30
@fox_12

store the user id in the cache for 60 seconds
if there is a request from this user - update the cache data for another 60 seconds and ignore the request
if the user id is not in the cache - then answer the request and add it to the cache,
or a label with the user id and a temporary a label in the database, on a disk in a file, on a fence...
and check the current time with the last user label
less than 60 seconds - ignore and update the label
more - answer and make a label

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question