电报发送大量重复

Telegram sends lots of duplicates

我知道这是 Telegram sends duplicate POST JSON requests to webhook and Telegram sends duplicate POST JSON requests to webhook 的副本。 然而,这个问题没有任何充分的答案,所以:

我有一个 PHP 应用程序处理来自 Telegram 的 webhook 请求。然而,Telegram 无法读取 webhook 成功运行(尽管 hurl.it 清楚地表明它在这样的请求上发回了 200)。

因此,我让我的机器人多次回复一条消息,因为 Telegram 还不知道消息已被处理。

问题也在这里描述(我正在使用的库):

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

然而,那里也没有明确的答案...

我该如何解决?

1) 我的机器人正在使用 webhook 2) 肯定是 returns 200 OK 响应 3)用户收到机器人的回复 更新 4) 不是超时。

我的 getWebhookInfo 回复:

[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
            )

    )

如果 Telegram 及时收到 HTTP 200,它就不会重复请求。我猜你的 request/response 超时了。使用 getwebhookinfo 查看您的上次请求错误是什么,如果没有超时则更新问题。


似乎问题出在 Content-encoding header 上。我建议向你的机器人发布一些虚假数据,看看你收到了什么 Content-encoding header。使用我在 https://core.telegram.org/bots/webhooks 中找到的 curl 或使用类似 Postman 的程序。

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/"