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:
- Receive an update from the webhook
- Save the
update_id
- Reply to the user
/sendMessage
- disable the webHook
/setWebhook?url=
- Set the offset
/getUpdates?offset={update_id+1}
- Reinstate the webHook
/setWebhook?url=https://mywebhook.domain.com
There must be a better way right? Anyone?
4
Answers
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.What HTTP status code are you returning on the page handling your webhook? It is possible that Telegram is attempting to retry your webhook endpoint because it’s not receiving a status 200 (OK) from you.
use This on webHook to get data from telegram servers:
You must say to telegram that you get updates successfully with this: