Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telegram BotApi, Send message to multiple chat_id

I was wondering if I could send a message with my bot on telegram bot api, to multiple chat_id, but I cant figure it out. that's totally because of telegram apis are so hard to understand. I have used this for send a message to one chat_id:

https://api.telegram.org/botTOKKEN/sendMessage?chat_id=xxxxxxx&text=Hi+John

like image 478
Omid Avatar asked Sep 05 '15 22:09

Omid


People also ask

How can I send a message to multiple contacts in Telegram?

SEND TO TELEGRAM USERNAMES or PHONE NUMBERS: once the message is ready, go to SEND TO USERS LIST tab. Here you can import a list of usernames (like @username) or a list of phone numbers (with country code) and then send a message to all of them in just one click. After that you click on START a new window will open.

Can Telegram BOT send message to channel?

Create a Telegram bot NOTE: Bots can't message people first, but can message channels.

How many messages can a telegram BOT send?

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.

What is the limit of Telegram message?

So far, Telegram allowed users to send up to 1.5GB of files on the platform. The latest update has now increased the limit to 2GB. This means users can now send media and files of any kind up to 2GB each.


1 Answers

The problem with foreach or any other massive sendMessage is that the API will not allow more than ~30 messages to different users per second.

According to Bots FAQ in telegram site:

How can I message all of my bot's subscribers at once?
Unfortunately, at this moment we don't have methods for sending bulk messages, e.g. notifications. We may add something along these lines in the future.
In order to avoid hitting our limits when sending out mass notifications, consider spreading them over longer intervals, e.g. 8-12 hours. The API will not allow more than ~30 messages to different users per second, if you go over that, you'll start getting 429 errors. You can't send message this way to all user.

and solution in Bots FAQ page:

My bot is hitting limits, how do I avoid 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.

like image 198
Sadegh PM Avatar answered Oct 05 '22 07:10

Sadegh PM