Good afternoon people! I'm building a bot and started receiving

429 errors. Could you please help me clarify the following: 20 messages per minute limit applies to groups and not individual chats with a bot, or if my bot's user sends /start 20 times inside a 60 seconds period this will result in 429 as well? Sending less than 30 messages per second (my bot works with 1-on-1 chats, not groups) and getting 429 error. Could you please advise on how to approach this issue?

7 ответов

14 просмотров

Obviously, use queue or several queues for message sending

Victor-Khodalov Автор вопроса
Sery
Obviously, use queue or several queues for message...

how would you do this? my current solution: im using aws for my telegram bot, I have webhooks delivered to rest api gateway-> inbound fifo queue->inbound lambda (sends 200 status to telegram)->outbound fifo queue->outbound lambda (sends messages to users). The documention says this: When sending messages inside a particular 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. 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. Also note that your bot will not be able to send more than 20 messages per minute to the same group. Does the 20 messages per minute limit also apply to individual chats with a bot, not just groups? I'm trying to understand what caused the 429 error in my case. Looks like im sending less than 30 messages per second to all users at any given second. So i wonder if it's the 1 message per second or 20 messages per limit (if this limit applies to the individual chats with the bot) that I'm hitting.

Victor Khodalov
how would you do this? my current solution: im usi...

I don`t use webhooks. My current implementation includes one queue for all users and one per chat for chats. All queues connected to own and shared limiters. But it is overengineering, my bot never reaches limits

Victor Khodalov
how would you do this? my current solution: im usi...

Even if you prefer webhooks you can try this way: When update is received, it is added to queue (first in, first out). Then your bot begins parsing updates in this queue. It polls the update and processes it. Then it waits some time (51ms will guarantee you not sending more than 20 messages in different chats within 1 second) before processing next request. If the current request didn't result into 200, you add it's update back to query

Victor-Khodalov Автор вопроса
s0m31 🇷🇺
Even if you prefer webhooks you can try this way: ...

could you please clarify. there are 3 types of limits i can hit: 1. 30 messages per second (to all users or to one user at a time) 2. 20 messages per minute (to a given chat with the user) 3. 1 message per second (to a given chat with a user. Do I get it right or the second limit (20 msgs per minute only applies to groups and not individual chats? I got this info from the bots faq section, here's the text: When sending messages inside a particular 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. 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. Also note that your bot will not be able to send more than 20 messages per minute to the same group.

Victor Khodalov
could you please clarify. there are 3 types of lim...

If you will process updates this way even if you will run to limits your bot will still work. Maybe just be slowed down a little

Victor-Khodalov Автор вопроса
s0m31 🇷🇺
If you will process updates this way even if you w...

Could you please explain? When a user sends 20 /start messages within a short period. Even if I add a 1 second delay before sending the reply message to /start command, this will still result in hitting the 20 messages per minute limit. Do I get it right?

Похожие вопросы

Карта сайта