skip to Main Content

I am making a telegram bot using the telegram bot web API as described here

I am using long polling to collect updates for my bot via the method getUpdates. In order to avoid processing the same message twice I am using the method’s offset parameter.

import requests

url = "https://api.telegram.org/botTOKEN/getUpdates"
offsetParam = {'offset' : 999}
response = requests.get(url,params=offsetParam)

When running this code, one would expect that every update would have an offset greater than 999. However I still get message_id’s which are less than 999 as part of the last variable in the code (all of them, as a matter of fact).

Can anyone help me figure out why is the response offset not increasing after this call?

P.S: I’m glad to provide extra info.

Thanks

3

Answers


  1. Chosen as BEST ANSWER

    The answer was simple. The offset refers to the update_id value.

    Other answers claim that message_id is the offset, this is not the case at the time of writing.


  2. Offset is message ID, you should obtain that in result.message_id, not start from 0.

    Login or Signup to reply.
  3. Worked through this using cURL. It’s not the message_id; it’s the update_id. If offset is greater than update_id, cURL returns only when a new update is available or when timeout elapses. In other words, it long polls.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search