Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About telegram rate limit for sendMessage and editMessage #3034

Closed
felipepimsil opened this issue Aug 27, 2024 · 5 comments
Closed

About telegram rate limit for sendMessage and editMessage #3034

felipepimsil opened this issue Aug 27, 2024 · 5 comments

Comments

@felipepimsil
Copy link

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.

@levlam
Copy link
Contributor

levlam commented Aug 27, 2024

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.

@felipepimsil
Copy link
Author

felipepimsil commented Aug 27, 2024

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?

@levlam
Copy link
Contributor

levlam commented Aug 28, 2024

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.

@felipepimsil
Copy link
Author

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...

@levlam
Copy link
Contributor

levlam commented Aug 29, 2024

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

@levlam levlam closed this as completed Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants