【问题标题】:Telegram setwebhook not receiving updates电报 setwebhook 未收到更新
【发布时间】:2017-06-26 04:30:19
【问题描述】:

我正在使用 Google Cloudshell 平台创建一个经过 ssl 认证的 url 来托管 webhook。所以我最初开始使用 getupdates 来查找 chat_id 并发送机器人消息。以下代码旨在获取用户的聊天 ID,然后给他发短信 "text" ,工作正常。

<?php 
$botToken = "insert bot token" ;
$website = "https://api.telegram.org/bot".$botToken ;

$update = file_get_contents($website."\getupdates");
$updateArray = json_decode($update, TRUE) ;

$chatId = $updateArray["result"][0]["message"]["chat"]["id"] ;
file_get_contents($website."/sendmessage?chat_id=".$chatId."&text=test") ;
?>

然后我使用 setwebhook 设置了一个 webhook 并修改了上面的代码。

<?php 
$botToken = "insert bot token" ;
$website = "https://api.telegram.org/bot".$botToken ;

$update = file_get_contents("php://input");
$updateArray = json_decode($update, TRUE) ;

$chatId = $updateArray["result"][0]["message"]["chat"]["id"] ;
file_get_contents($website."/sendmessage?chat_id=".$chatId."&text=test") ;
?>

换句话说,我将 \getupdates 更改为 "php://input" 。它没有没有工作。

我想谷歌应用程序引擎可能不会自动签署其 ssl 证书,这可能就是 webhook 不起作用的原因。

任何帮助将不胜感激。

编辑:为了回应下面的答案/评论,我尝试了 getWebhookinfo 方法并得到了

"url:"https://my_url.com","has_custom_certificate":false, "pending_update_count":0, "max_connections":40

【问题讨论】:

  • 您可以使用/webhookinfo方法获取更多信息。请发布此结果。
  • @creyD 所以这给出了一个 "url:"https.url" ,"has_custom_certificate":false, "pending_update_count":0, "max_connections":40
  • 是的,网址不正确。您必须使用 /setwebhook 方法对此进行调整。示例:/setwebhook?url=https://www.google.de 记录在 here
  • @creyD 不,我故意用愚蠢的“https:url”替换了我的实际网址;但是, "has_custom_certificate":false 声明似乎暗示它还没有 ssl 证书。我试图找到如何从谷歌应用引擎获取 ssl 证书但失败了。
  • 不,has_custom_certificate = false 没问题,与 SSL 无关。但是,是的,您需要一个 https 地址,否则它无法正常工作。我猜你已经尝试过this..

标签: php google-app-engine ssl-certificate telegram-bot php-telegram-bot


【解决方案1】:

您可以通过以下方法发现问题:

检查getWebhookInfo方法,确保你的webhook URL是正确的,并且没有last_error_message字段。

POST 类似的数据到你的服务器,here 是一些你可以在curl -d JSON 中使用的数据,只需复制它并在你自己的服务器上运行即可。

最后,检查您的 CDN 配置(如果您已在该服务器上应用),暂时禁用泛洪或任何检查。

【讨论】:

  • 感谢您的回答。 getWebhookInfo 产生 "url:"https.url" ,"has_custom_certificate":false, "pending_update_count":0, "max_connections":40
  • 我认为问题在于,我需要在应用引擎的 app.yaml 文件中添加一个安全参数。
猜你喜欢
  • 2016-01-30
  • 2017-02-23
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 2022-07-12
  • 1970-01-01
  • 1970-01-01
  • 2016-07-23
相关资源
最近更新 更多