td icon indicating copy to clipboard operation
td copied to clipboard

About telegram rate limit for sendMessage and editMessage

Open felipepimsil opened this issue 1 year ago • 5 comments

Hi!

I wanted to know about rate limits for the requests sendMessage, editMessage and deleteMessage.

What I find when searching for rate limit is: Global: 30 requests / second. User: 20 requests / min.

Are the limits shared between these requests? I tested a simple BOT where:

  • User sends a message.
  • Bot opens a menu. That menu refreshes every 5 seconds (triggers a editMessage)
  • That menu has some buttons that would trigger sendMessage
  • My BOT has a throttle that limits only sendMessage • 20 reqs / min (User) • 1 req / second (User) • 30 reqs / second (Global).

With few users I came across RetryAfter error. So seems that editMessage uses the same limit. But I know some BOTs with 4k users/day and with a same menu that refreshes every X seconds and seems hey don't get rate limited.

felipepimsil avatar Aug 27 '24 18:08 felipepimsil

Limits for message editing and sending are shared, but well-behaving bots that don't constantly send/edit messages without user interaction can hardly exceed them. There is no global limit on the number of sent messages for bots, but see https://core.telegram.org/bots/faq#broadcasting-to-users. Also, for bots you would better use Bot API.

levlam avatar Aug 27 '24 19:08 levlam

Oh sorry, I was reading both repositories and I though I opened the issue at telegram-bot-api.

So are the limits grouped by chat and count only if don't have user interaction?

My bot only opens the menu when the user use /start. But that menu stay updating every 5 seconds with a editMessage. In this path, the user interaction counts only to the first sendMessage right after the start, right?

As I'm updating the message every 5 seconds, I will have 12 reqs / min. This menu has some buttons that trigger tasks and my BOT use sendMessage to warn the user about the task result, while the menu stay updating. As the user pressed the button, will these sendMessage requests count?

About the bulk notifications, I was concerned because as I said, if 20 users hit the /start, my bot will send 20 sendMessage and it will stay updating that message, sending 20 editMessage every 5 seconds. Does it count as a passive notification?

felipepimsil avatar Aug 27 '24 21:08 felipepimsil

This is a bad behavior pattern, which creates a lot of unneeded traffic and is bad both for the bot and the user. Such behavior is supposed to be limited. Instead, you can add a button and refresh the state only after the user pressed it. Alternatively, you can use a mini app, which is updated only while opened.

levlam avatar Aug 28 '24 07:08 levlam

I know that letting it refreshing forever it's a bad behavior, but is it even for a short period? I was thinking in an auto refresh for a short period only.

Example: User press Refresh -> Bot auto refreshes 5x only and stop. If user press Refresh again, the auto refreshes restart again for 5x...

felipepimsil avatar Aug 29 '24 00:08 felipepimsil

This isn't that bad, but still can be significantly limited.

levlam avatar Aug 29 '24 04:08 levlam