How to use offset on Telegram bot webHook API

From 2 days I have been studying the Telegram API, which is pretty neat. But there is one thing that I cannot understand.

If you are not using the webHook call but /getUpdates , you can tell the API through the offset parameter which message the server is processing.

But how do you do it with webHook? I get the same message as the update. This leads to the fact that the server sends the user the same message.

The solution I came up with is as follows:

  • Get Update From Web Hosting
  • Save update_id
  • Reply to /sendMessage
  • disable webHook /setWebhook?url=
  • Set the offset /getUpdates?offset={update_id+1}
  • Recover webHook /setWebhook?url=https://mywebhook.domain.com

Should there be a better way? Is anyone

+5
source share
4 answers

Ok, the problem is resolved. It turned out that just 200 (OK) is not enough (the body of my answer was zero). I added the body to the answer {} and I know that it works fine.

+13
source

You must tell the telegram that you are successfully receiving updates:

  - 200 response code & - empty json like this {} 
+5
source

use This is on webHook to receive 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); 
+2
source

What HTTP status code do you return on the page that processes your website? Perhaps Telegram is trying to repeat your webhook endpoint because it does not receive 200 (OK) status from you.

+1
source

All Articles