telegram-bot-api icon indicating copy to clipboard operation
telegram-bot-api copied to clipboard

Provide 429 exception for webhook updates on inline query

Open chaslain opened this issue 1 year ago • 8 comments

When several users are active on my bot at one time, mostly interacting with callback queries, I am getting a 429 error sending the update back. I believe if my bot is receiving one callback query, a 1:1 ratio of requests in to requests out should not trigger the 429 rate limiter, especially in reference to the same inline message id, as this cannot be used to spam.

chaslain avatar Oct 08 '24 21:10 chaslain

You can call answerCallbackQuery without any limits, editing of the message in question is still subject to per chat limits.

levlam avatar Oct 09 '24 09:10 levlam

@levlam I have rewritten the bot to edit the message in the http response, but when mutliple users are simultaneously using the bot, I still sometimes get drops, only now there is no error to inspect.

What are the "per chat limits"? With the state of the bot being changed, the users enter an irredeemable loop where they cannot proceed.

chaslain avatar Nov 29 '24 18:11 chaslain

Per chat limits are documented at https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this:

In a single chat, avoid sending more than one message per second. We may allow short bursts that go over this limit, but eventually you'll begin receiving 429 errors. In a group, bots are not be able to send more than 20 messages per minute.

levlam avatar Dec 01 '24 23:12 levlam

@levlam does this include editing messages? I saw this FAQ but it does not mention that, and I'm still surprised to be running into limits like this.

chaslain avatar Dec 01 '24 23:12 chaslain

Yes, it includes message editing.

levlam avatar Dec 01 '24 23:12 levlam

@levlam in that case, my thought is this: If I receive an inline query, and send back an edit for that same message, there is no way to abuse the system with those kind of updates, especially with it being 1:1 with user interaction. Couple that with cutting down traffic by giving a webhook response rather than a separate request, and it seems reasonable that these not be rated.

Is there some other consideration I am missing?

chaslain avatar Dec 01 '24 23:12 chaslain

This is possible, but it would require harder limits for callback query sending by users.

levlam avatar Dec 01 '24 23:12 levlam

@levlam that is my suggestion then, especially because responding to a webhook query yields no way to know if the action was successful.

I cannot picture a use case where a bot would require more than, say, 1 interaction per second per message with callback queries, and the bot I am asking about is a game- which would be more interaction than most bots.

chaslain avatar Dec 01 '24 23:12 chaslain