Since 2 days I've been exploring the Telegram bot API, which is pretty neat. But there is one thing I can't figure out.
When you don't use the webHook but the /getUpdates
call, you can tell the API via the offset
parameter which message where processed by the server.
But how do you do this with the webHook in place? I keep getting the same message as an update. Which results in the server spamming the user with the same message.
The solution I came up with is as follows:
update_id
/sendMessage
/setWebhook?url=
/getUpdates?offset={update_id+1}
/setWebhook?url=https://mywebhook.domain.com
There must be a better way right? Anyone?
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. Save this answer. Show activity on this post.
Go to bot settings, then the "Webhooks" tab. Activate the setting and insert the URL to which you want to send data. Select the events you want to send alerts for and click Save to apply the settings.
An important function of a Telegram bot is the possibility to execute commands in a Telegram chat, which then directly trigger actions or request information. For example, it is possible to send the bot the command “/help” or “/help”, which then outputs the commands possible for this bot in the chat as text feedback.
Ok, problem solved. It appeared that just a 200 (OK) wasn't enough (the body of my response was null. I've added a body to the response {}
, and know it works fine.
You must say to telegram that you get updates successfully with this:
- 200 response code
&
- empty json like this {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With