1

I'm trying to implement something "looks like" animated countdown in my telegram bot:

sent=bot.send_message(message.chat.id,'5')
time.sleep(1)
bot.edit_message_text('4',message.chat.id,sent.message_id)
time.sleep(1)
bot.edit_message_text('3',message.chat.id,sent.message_id)
time.sleep(1)
bot.edit_message_text('2',message.chat.id,sent.message_id)
time.sleep(1)
bot.edit_message_text('1',message.chat.id,sent.message_id)
time.sleep(1)
bot.edit_message_text('0',message.chat.id,sent.message_id)

Sometimes it works well, but sometimes I get the error:

A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:error_code:400,description:"Bad Request: message is not modified

Tibebes. M
  • 6,940
  • 5
  • 15
  • 36
Ilya
  • 25
  • 1
  • 6
  • well known issue, take a look at [this question](https://stackoverflow.com/questions/41373752/telegram-bot-api-error-when-try-to-edit-message-bad-request-message-not-found) – anatol Apr 20 '17 at 02:28
  • I have "message is not modified" not "message not found" - it is a different issue – Ilya Apr 20 '17 at 05:27
  • No so different as you can assume - only on the description point of view. I had meant editing messages issue in common. It's often happened and rarely solved. – anatol Apr 20 '17 at 05:46

1 Answers1

0

I personally don't recommend you to send requests to telegram so often in a small timespan. You might end up with a time out for too many requests. My two suggestions for you here:

  1. Just skip any update that failed. A retry will simply take too long
  2. Use a bigger interval (e.g. 2 seconds) for updating the messages to give the Telegram Servers enough time to realize that the message has been updated.
Jonas Fowl
  • 117
  • 5
  • increasing the timings doesn't help, but error handling - does. Thank you. One more question - maybe you know the answer. While there is a timer - other users can't do anything. How to make a real multiuser bot? – Ilya Apr 21 '17 at 17:17
  • You must handle the countdown asynchronously. I created a full [countdownbot](https://t.me/countdownmebot) that uses two scripts. One handling the normal requests and putting the countdowns into a database and another just updating the messages in a loop. – Jonas Fowl Apr 21 '17 at 19:14