【问题标题】:how to use setwebhook in telegram?如何在电报中使用 setwebhook?
【发布时间】:2023-03-29 00:37:01
【问题描述】:

您好,我正在电报中创建一个机器人。我发送一个http请求:
https://api.telegram.org/bot(mytoken)/setWebhook?url=https://mywebpagetorespondtobot

我收到了这个:

{"ok":true,"result":true,"description":"Webhook was set"}

但它不起作用。我的意思是电报不会向服务器发送更新。 这是因为我没有上传我的证书吗?那我应该怎么做呢?

【问题讨论】:

  • 如何接收更新?
  • 当我删除 webhook 时,getUpdates() 工作正常
  • 你使用自签名证书吗?

标签: certificate telegram telegram-bot


【解决方案1】:

在此处查看您的更新状态:

https://api.telegram.org/botYOUR_TOKEN/getWebhookInfo

它会告诉你任何错误。如果您没有在这里看到任何问题,那么问题就在您的脚本中的某处。确保正确处理传入的更新。

这可能是自签名证书的问题。它需要首先通过 setWebhook 方法上传,如here 所述。或者尝试更广泛的指南here

【讨论】:

  • 我删除了 webhook 并且 getUpdates() 工作正常。可能问题出在证书上。我阅读了链接,但我不知道如何生成和发送 pem 文件
【解决方案2】:

我将 setwebhook url 更改为 a 并且它有效。它似乎不适用于 wabepage url。 https://api.telegram.org/bot(mytoken)/setWebhook?url=https://mywebpagetorespondtobot/mymethod ' (WebMethod)

【讨论】:

    【解决方案3】:

    这意味着您的公钥不正确。

    您可以通过 url https://api.telegram.org/bot{token}/getWebhookInfo 查看 设置后

    当我发送不正确的公钥时 - 我收到了

    {"ok":true,"result":{"url":"","has_custom_certificate":false,"pending_update_count":6}}
    

    但如果我发送了正确的公钥,我会收到:

    {"ok":true,"result":{"url":"mycorrecturl.com","has_custom_certificate":true,"pending_update_count":6,"last_error_date":1506772578,"last_error_message":"SSL error {337047686, error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed}","max_connections":40}}
    

    【讨论】:

      【解决方案4】:
      1. BotFather -> Bot 列表 -> API 令牌 -> 撤销当前令牌
      2. https://api.telegram.org/bot(新令牌)/setWebhook?url=https://myweb... 完成)

      【讨论】:

        猜你喜欢
        • 2016-01-30
        • 2017-02-23
        • 1970-01-01
        • 2016-07-23
        • 2015-12-08
        • 2020-03-02
        • 2023-03-13
        • 1970-01-01
        • 2021-04-17
        相关资源
        最近更新 更多