26

We have a Telegram bot. It has around 1.2 million subscribers.

Now we're facing a problem in sending messages to these number of subscribers.

Telegram bot API does not provide any batch message functionality and we'd have to send individual requests to Telegram. The problem is, after a few thousand messages, Telegram starts responding with Error 429: too many requests, and does not accept any requests for a while.

How can we effectively message our subscribers?

Pang
  • 9,564
  • 146
  • 81
  • 122
Pooya Saberian
  • 971
  • 2
  • 9
  • 16
  • 2
    1.2 Million subscribers ?! bot name ? :) As noted by @user3313781 answer, Telegram bot servers use this "antispam" limit startegy, at the moment. Do you solved sending message in a opportune bigger time elapse? By example sending each message every max 50 milliseconds ? – Giorgio Robino Dec 02 '15 at 10:00
  • 1
    This was short before channels were introduced in Sept. 2015. Today you should send to channels and not via private message – PythoNic May 21 '22 at 10:07

5 Answers5

12

You should simply implement a global rate limiter to ensure no single user gets above a fixed number of messages per second. to be safe, set your limiter at lower than 30, maybe even to 5 msgs per second.

Really anything higher than 5 messages per second to a single user quickly becomes an annoyance.

cheers.

Charles Okwuagwu
  • 10,538
  • 16
  • 87
  • 157
  • 2
    What can be the reason if I get this error as well but only if I try to sendContact via telegram. I am using Telegraf Framework. I don't have subscribers now. Just learning the framework. What can make a loop what I could miss? – Valary o May 22 '20 at 17:00
  • 1
    @Valaryo It feels like Telegram has another rate limit only for sending contacts. It might not even be on purpose, as this is not so common. – TechWisdom May 06 '23 at 12:19
8

I'm the owner of Ramona Bot. There is a limit for sending message to users. as they said ~30 message per second. Otherwise you will get that Error 429.

alixrx
  • 151
  • 7
  • Do you maybe tested what happens after having received an Error 429 ? Do you solved sending messages in a opportune time elapse (after the 429 Reject) sending each message every max 50 milliseconds ? Do you used maybe and output message queue ? thanks – Giorgio Robino Dec 02 '15 at 10:01
6

Based on the Telegram Bots FAQ for sending messages, you should consider this:

If you're sending bulk notifications to multiple users, the API will not allow more than 30 messages per second or so. Consider spreading out notifications over large intervals of 8—12 hours for best results.

Pang
  • 9,564
  • 146
  • 81
  • 122
Hossein
  • 828
  • 1
  • 9
  • 31
2

I had similar problems with messages, the pause between which was 0.5 seconds (this is much less than 30 messages per second!). The problem was only associated with messages, the content of which I tried to change. So when you try to use "edit_message_text" or "edit_message_media" take more pause between messages.

0

It can happen also if a Telegram group is in the slow mode and the bot tries to send more that one message at once to that group. I fixed this by adding a delay to the bot trigger mechanism.

Saeed Mohtasham
  • 1,693
  • 16
  • 27