如何让 Telegram webhook 与 ngrok 一起工作?
How to get Telegram webhook with ngrok working?
我正在开发 Telegram 机器人并想使用 ngrok to receive messages from the webhook。
设置 webhook 有效。当我将可公开访问的域设置为 URL 时,我实际上收到了预期的消息。现在,当我知道代码正在运行时,我想将消息从 ngrok 服务器传送到我的本地 VM。
$ 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 并将来自 Telegram 机器人的消息转发到本地系统?
附加信息:
我还尝试让 ngrok 在我的可公开访问的服务器上工作。该域受 SSL 保护,生产系统不需要此转发。我只是想看看,how/whether 它会起作用。
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
我正在开发 Telegram 机器人并想使用 ngrok to receive messages from the webhook。
设置 webhook 有效。当我将可公开访问的域设置为 URL 时,我实际上收到了预期的消息。现在,当我知道代码正在运行时,我想将消息从 ngrok 服务器传送到我的本地 VM。
$ 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 并将来自 Telegram 机器人的消息转发到本地系统?
附加信息:
我还尝试让 ngrok 在我的可公开访问的服务器上工作。该域受 SSL 保护,生产系统不需要此转发。我只是想看看,how/whether 它会起作用。
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