Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telegram sendMessage too slow for certain bot

I have two telegram bots and last time I have noticed, that 2nd bot became to slow.

My research shows that sendMessage call has different time for two of them.

curl "https://api.telegram.org/bot123456789:AAAAAAAAABBBBBBBBCCCCCCC/sendMessage?chat_id=987654321&text=HI"

Here is output for the two different bots:

Call to the first one (fast)

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   224  100   224    0     0    491      0 --:--:-- --:--:-- --:--:--   492

Call to the second bot (slow)

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   227  100   227    0     0     43      0  0:00:05  0:00:05 --:--:--    59

The first sendMessage runs instantly.

For second comes with a Time spend = 5 seconds !!

And its always 2-6 seconds. Does anyone know the reason?

Sorry for my English.

like image 289
tenta4 Avatar asked Jun 22 '18 11:06

tenta4


2 Answers

If both of your bots are hosted on the same place then we can exclude networking/routing issue.

What kind are those sendMessage calls? Bulk messages? If you attempted sending the same batch through both of your bots to same set of chat IDs then keep in mind that requests to users that didn't start the chat with the bot will be instantly denied.

Something I noticed in the past is that hitting API limits can cause slowdowns like this, are your bots popular or doing a lot of requests to the API?

Per documentation:

When sending messages inside a particular chat, avoid sending more than one message per second.

If you're sending bulk notifications to multiple users, the API will not allow more than 30 messages per second or so (..)

(..) your bot will not be able to send more than 20 messages per minute to the same group

like image 91
Jack'lul Avatar answered Oct 06 '22 16:10

Jack'lul


try curl -v ..... to see if those slow requests went through ipv6. I've experienced a similar issue, and found out all ipv4 requests to telegram api sever work fine, but some ipv6 calls took long time to wait.

lf that's the cause of the problem you met, just limit your server to ipv4 only.

like image 30
teleme.io Avatar answered Oct 06 '22 14:10

teleme.io