Reputation: 201
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?
Upvotes: 6
Views: 11902
Reputation: 414
You must say to telegram that you get updates successfully with this:
- 200 response code
&
- empty json like this {}
Upvotes: 5
Reputation: 1238
use This on webHook to get data from telegram servers:
// get the raw POST data
$rawData = file_get_contents("php://input");
// this returns null if not valid json
$jsonData = json_decode($rawData);
Upvotes: 2
Reputation: 201
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.
Upvotes: 13
Reputation: 1990
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.
Upvotes: 1