3

I know this is a duplicate of Telegram sends duplicate POST JSON requests to webhook and Telegram sends duplicate POST JSON requests to webhook. However, there wasn't any adequate answer to this question, so:

I have a PHP app handling webhook requests from Telegram. However, Telegram fails to read that webhook worked successfully (although hurl.it shows clearly it sends 200 back on such a request).

Therefore, I have my bot reply a message loads of times because Telegram just won't get that the message is handled yet.

The problem is also described here (the lib I'm using):

https://github.com/irazasyed/telegram-bot-sdk/issues/23

However, no definite answer there either...

How can I fix it?

1) My bot is using a webhook 2) It definitely returns 200 OK response 3) User receives replies from the bot UPDATE 4) It's not a timeout.

My getWebhookInfo response:

[decodedBody:protected] => Array
    (
        [ok] => 1
        [result] => Array
            (
                [url] => https://bots.chatforge.me/t/test
                [has_custom_certificate] => 
                [pending_update_count] => 3
                [last_error_date] => 1514900657
                [last_error_message] => Unsupported Media Type: unsupported content-encoding
                [max_connections] => 40
            )

    )

1 Answers1

5

If Telegram received HTTP 200 in a timely manner it won't repeat the request. My guess is your request/response is timing out. Use getwebhookinfo to see what was your last request error and update question if it's not a time out.


Seems problem is something about Content-encoding header. I suggest posting some fake data to you bot and see what Content-encoding header you receive. Use the curl I found in https://core.telegram.org/bots/webhooks or use Postman like programs.

curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache"  -d '{
"update_id":10000,
"message":{
  "date":1441645532,
  "chat":{
     "last_name":"Test Lastname",
     "id":1111111,
     "type": "private",
     "first_name":"Test Firstname",
     "username":"Testusername"
  },
  "message_id":1365,
  "from":{
     "last_name":"Test Lastname",
     "id":1111111,
     "first_name":"Test Firstname",
     "username":"Testusername"
  },
  "text":"/start"
}
}' "https://YOUR.BOT.URL:YOURPORT/"
Arman Ordookhani
  • 6,031
  • 28
  • 41
  • I had no idea the API has this debugging option because the lib does not include it)) Thanks. Unfortunately, it turns out it's not a timeout. It's even more confusing now: `'Unsupported Media Type: unsupported content-encoding'`. I attached full output to the question. – Арсен Гоян Jan 02 '18 at 13:48
  • 1
    Indeed, I just found out my server is sending `Content-Encoding: none` header. Which is obviously wrong. No idea where does it come from. Normal (non-webhook) requests return `Content-encoding: gzip`. Hmmm, let's see – Арсен Гоян Jan 02 '18 at 14:06
  • 1
    Yeah, removing that header deep inside the application totally fixed it. No idea why it was there for ages. No problems with it until now) Who knew an API could fail because of this) Thanks for the hints! – Арсен Гоян Jan 02 '18 at 14:12