Telegram 如何在ngrok工作的情况下获得电报webhook?
我正在开发一个电报机器人,想用它来接收来自网络的消息 设置webhook很有效。当我将可公开访问的域设置为URL时,我实际上得到了预期的消息。现在,当我知道代码正在工作时,我想通过隧道将消息从ngrok服务器传输到本地VMTelegram 如何在ngrok工作的情况下获得电报webhook?,telegram,telegram-bot,ngrok,php-telegram-bot,telegram-webhook,Telegram,Telegram Bot,Ngrok,Php Telegram Bot,Telegram Webhook,我正在开发一个电报机器人,想用它来接收来自网络的消息 设置webhook很有效。当我将可公开访问的域设置为URL时,我实际上得到了预期的消息。现在,当我知道代码正在工作时,我想通过隧道将消息从ngrok服务器传输到本地VM $ ngrok http telegrambot.sandbox.loc:80 ngrok by @inconshreveable
$ ngrok http telegrambot.sandbox.loc:80
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Session Expires 7 hours, 59 minutes
Version 2.2.8
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://0955b8f3.ngrok.io -> telegrambot.sandbox.loc:80
Forwarding https://0955b8f3.ngrok.io -> telegrambot.sandbox.loc:80
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
嗯。现在我设置webhook并得到如下响应
{
"ok":true,
"result":{
"url":"https://a200f5f7.ngrok.io",
"has_custom_certificate":false,
"pending_update_count":0,
"max_connections":40
}
}
ngrok的CLI输出:
HTTP Requests
-------------
POST / 502 Bad Gateway
POST / 502 Bad Gateway
POST / 502 Bad Gateway
POST / 502 Bad Gateway
我没有收到任何消息。然后我将主机名添加到/etc/hosts
:
127.0.0.1 telegrambot.sandbox.loc
现在我开始
HTTP Requests
-------------
POST / 405 Not Allowed
POST / 405 Not Allowed
POST / 405 Not Allowed
POST / 405 Not Allowed
POST / 405 Not Allowed
POST / 405 Not Allowed
GET /favicon.ico 404 Not Found
GET / 200 OK
如何正确设置和使用ngrok并从电报机器人获取转发至本地系统的消息?
其他信息: 我还试图让ngrok在我的可公开访问的服务器上工作。该域受SSL保护,我不需要为生产系统进行此转发。我只是想看看它会怎样/是否起作用
ngrok http mybot.myserver.com:80
输出:
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Session Expires 7 hours, 56 minutes
Version 2.2.8
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://22cf6597.ngrok.io -> mybot.myserver.com:80
Forwarding https://22cf6597.ngrok.io -> mybot.myserver.com:80
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
结果(无论有无/etc/hosts
条目)似乎都正常:
HTTP Requests
-------------
POST / 200 OK
POST / 200 OK
POST / 200 OK
POST / 200 OK
但是定义的URI似乎仍然没有被触发。您可以尝试以下方法:
ngrok http telegrambot.sandbox.loc:80 -host-header=telegrambot.sandbox.loc