电报webhook与heroku

时间:2018-05-07 13:52:26

标签: python heroku telegram telegram-bot

我正在尝试使用python发送电报echobot。我在heroku上托管我的python。

刚开始我只使用带有python请求的电报原生API方法,然后我使用了一个库python-telegram-bot

我能够获得常规的getUpdate方法(使用长轮询 - 即heroku定期向您的电报机器人发出请求以获取更新),但是webhook is not

我认为问题是heroku不会访问端口< 1024和电报webhook only pushes notifs to ports 80,88,443 and 8443.

有谁知道如何才能使这项工作

这是我的代码:

MacBook-Pro-4:proj aiden$ curl https://mysterious-sands-89012.herokuapp.com/dwh
webhook deleted ok

=====

1。删除我的WEBHOOK

2018-05-07T15:24:46.592749+00:00 heroku[router]: at=info method=GET path="/dwh" host=mysterious-sands-89012.herokuapp.com request_id=4aef8faf-555e-4697-8a3d-3eea2861eba2 fwd="23.31.215.245" dyno=web.1 connect=3ms service=404ms status=200 bytes=178 protocol=https
2018-05-07T15:24:46.586755+00:00 app[web.1]: DEBUG:telegram.vendor.ptb_urllib3.urllib3.connectionpool:https://api.telegram.org:443 "POST /bot562713672:AAE8Pt1-UDWyKrtIEJ7_igD2t5Zw1z0LRRo/deleteWebhook HTTP/1.1" 200 61
2018-05-07T15:24:46.587925+00:00 app[web.1]: DEBUG:telegram.bot:True
2018-05-07T15:24:46.588080+00:00 app[web.1]: DEBUG:telegram.bot:Exiting: delete_webhook
2018-05-07T15:24:46.589420+00:00 app[web.1]: 10.101.133.97 - - [07/May/2018:15:24:46 +0000] "GET /dwh HTTP/1.1" 200 18 "-" "curl/7.54.0"

HEROKU LOG

MacBook-Pro-4:proj aiden$ curl https://mysterious-sands-89012.herokuapp.com/swh
webhook setup ok

=============

2。重新设置(指定端口8443)

2018-05-07T15:24:52.194779+00:00 app[web.1]: DEBUG:telegram.bot:Entering: set_webhook
2018-05-07T15:24:52.195462+00:00 app[web.1]: DEBUG:telegram.vendor.ptb_urllib3.urllib3.connectionpool:Starting new HTTPS connection (1): api.telegram.org
2018-05-07T15:24:52.596829+00:00 heroku[router]: at=info method=GET path="/swh" host=mysterious-sands-89012.herokuapp.com request_id=c2cfa1d8-48c2-4abf-a198-cfa8499e9676 fwd="23.31.215.245" dyno=web.1 connect=0ms service=404ms status=200 bytes=176 protocol=https
2018-05-07T15:24:52.593031+00:00 app[web.1]: DEBUG:telegram.vendor.ptb_urllib3.urllib3.connectionpool:https://api.telegram.org:443 "POST /bot562713672:AAE8Pt1-UDWyKrtIEJ7_igD2t5Zw1z0LRRo/setWebhook HTTP/1.1" 200 57
2018-05-07T15:24:52.594936+00:00 app[web.1]: DEBUG:telegram.bot:True
2018-05-07T15:24:52.595055+00:00 app[web.1]: DEBUG:telegram.bot:Exiting: set_webhook
2018-05-07T15:24:52.596418+00:00 app[web.1]: 10.141.252.172 - - [07/May/2018:15:24:52 +0000] "GET /swh HTTP/1.1" 200 16 "-" "curl/7.54.0"

HEROKU LOG

MacBook-Pro-4:p-d "param1=value1&param2=value2" -X POST https://mysterious-sands-89012.herokuapp.com/562713672:AAE8Pt1-UDWyKrtIEJ7_igD2t5Zw1z0LRRo
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)</p>

=============

3。现在尝试并发布到该URL(不指定端口)

2018-05-07T15:25:05.454666+00:00 app[web.1]: INFO:my_application:post from teleg
2018-05-07T15:25:05.519859+00:00 app[web.1]: 10.101.219.132 - - [07/May/2018:15:25:05 +0000] "POST /562713672:AAE8Pt1-UDWyKrtIEJ7_igD2t5Zw1z0LRRo HTTP/1.1" 400 187 "-" "curl/7.54.0"
2018-05-07T15:25:05.524749+00:00 heroku[router]: at=info method=POST path="/562713672:AAE8Pt1-UDWyKrtIEJ7_igD2t5Zw1z0LRRo" host=mysterious-sands-89012.herokuapp.com request_id=3b9713a3-b3db-4db2-8915-29f995560ec2 fwd="23.31.215.245" dyno=web.1 connect=1ms service=68ms status=400 bytes=342 protocol=https

HEROKU LOG

MacBook-Pro-4:proj aiden$ curl -d "param1=value1&param2=value2" -X POST https://mysterious-sands-89012.herokuapp.com/562713672:AAE8Pt1-UDWyKrtIEJ7_igD2t5Zw1z0LRRo:8443
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

===============

4。现在尝试并发布到URL(指定端口)

2018-05-07T15:25:14.809828+00:00 heroku[router]: at=info method=POST path="/562713672:AAE8Pt1-UDWyKrtIEJ7_igD2t5Zw1z0LRRo:8443" host=mysterious-sands-89012.herokuapp.com request_id=458c911e-62ae-4eee-9cfd-b5a1345e5064 fwd="23.31.215.245" dyno=web.1 connect=0ms service=3ms status=404 bytes=386 protocol=https
2018-05-07T15:25:14.804975+00:00 app[web.1]: 10.180.49.12 - - [07/May/2018:15:25:14 +0000] "POST /562713672:AAE8Pt1-UDWyKrtIEJ7_igD2t5Zw1z0LRRo:8443 HTTP/1.1" 404 233 "-" "curl/7.54.0"

HEROKU LOG

documentsSize

=================

5。如果我向我的TELEGRAM BOT发送消息,没什么在我的HEROKU LOGS上显示

1 个答案:

答案 0 :(得分:1)

您必须使用aidentmchugh.pythonanywhere.com作为网址,而不是www

您的HTTPS证书未签署www域名。

Firefox