如何在电报中使用setwebhook?

ami*_*ola 9 certificate telegram telegram-bot

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

我收到了这个:

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

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

ami*_*ola 6

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


小智 6

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

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

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

{"ok":true,"result":{"url":"","has_custom_certificate":false,"pending_update_count":6}}
Run Code Online (Sandbox Code Playgroud)

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

{"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}}
Run Code Online (Sandbox Code Playgroud)


new*_*sha 5

检查是否正在发送更新,首先删除您的网络挂钩

https://api.telegram.org/bot(yourToken)/setWebhook
Run Code Online (Sandbox Code Playgroud)

然后启动您的机器人,输入信息并检查

https://api.telegram.org/bot(yourtoken)/getUpdates
Run Code Online (Sandbox Code Playgroud)


如果收到更新,一切正常。确保您的脚本正确处理传入的更新。

如果您没有收到更新,则证书可能存在问题。
自签名证书需要被描述为通过setWebhook方法首先上传这里