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
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.
Offset is message ID, you should obtain that in
result.message_id
, not start from0
.Worked through this using
cURL
. It’s not themessage_id
; it’s theupdate_id
. Ifoffset
is greater thanupdate_id
,cURL
returns only when a new update is available or whentimeout
elapses. In other words, it long polls.