我是电信僵尸网络开发的新手,我遇到了困难,同时将项目部署到GAE并创建了webhooks
我有一个简单的机器人,我从这里https://github.com/sooyhwang/Simple-Echo-Telegram-Bot:
from flask import Flask, request
import telegram
import config
import logging
bot = telegram.Bot(config.token)
app = Flask(__name__)
URL = 'my-service-dot-kristik-160312.appspot.com/'
#def sendPhotoToServer() -> Bool:
# sending photo to server
# return
@app.route('/HOOK', methods=['POST'])
def webhook_handler():
if request.method == "POST":
update = telegram.Update.de_json(request.get_json(force=True))
chat_id = update.message.chat.id
text = update.message.text.encode('utf-8')
bot.sendMessage(chat_id=chat_id, text=text)
logging.getLogger().setLevel(logging.INFO)
logging.info('===============TEXT=================')
return 'ok'
@app.route('/set_webhook', methods=['GET', 'POST'])
def set_webhook():
s = bot.setWebhook('https://my-service-dot-kristik-160312.appspot.com/HOOK')
if s:
return "webhook setup ok"
else:
return "webhook setup failed"
@app.route('/')
def index():
return 'App is ready'
当我转到https://my-service-dot-kristik-160312.appspot.com/set_webhook
时,我收到500错误。
我做错了什么?
服务器日志:
5.254.65.88 - - [04/Mar/2017:00:53:54 +0300] "GET /set_webhook HTTP/1.1" 500 264 - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" "my-service-dot-kristik-160312.appspot.com" ms=12 cpu_ms=18 cpm_usd=2.9504e-8 loading_request=0 instance=00c61b117c22a1c62e3fac7b35862e68e42b61f0284c2de4c4f50e319bcfa0d57efafc3b4e58 app_engine_release=1.9.48 trace_id=28ae78361cb2dde6bf4f6388ba535198
00:53:54.036
Entering: setWebhook
00:53:54.040
[2017-03-03 21:53:54,039] ERROR in app: Exception on /set_webhook [GET]
00:53:54.040
Traceback (most recent call last):
00:53:54.040
File "/base/data/home/apps/e~kristik-160312/my-service:20170303t195857.399582377782761728/lib/flask/app.py", line 1982, in wsgi_app
00:53:54.040
response = self.full_dispatch_request()
00:53:54.040
File "/base/data/home/apps/e~kristik-160312/my-service:20170303t195857.399582377782761728/lib/flask/app.py", line 1614, in full_dispatch_request
00:53:54.040
rv = self.handle_user_exception(e)
00:53:54.040
File "/base/data/home/apps/e~kristik-160312/my-service:20170303t195857.399582377782761728/lib/flask/app.py", line 1517, in handle_user_exception
00:53:54.040
reraise(exc_type, exc_value, tb)
00:53:54.040
File "/base/data/home/apps/e~kristik-160312/my-service:20170303t195857.399582377782761728/lib/flask/app.py", line 1612, in full_dispatch_request
答案 0 :(得分:0)
Telegram Bot API Webhooks不支持重定向。
当您将Webhook URL设置为GAE时,没有任何作用。检查getWebhooInfo后,您将获得last_error_message作为webhook的错误响应:302暂时移动
是的,Google Script Content Service documentation说,内容服务返回的内容不是从script.google.com提供的,而是重定向到script.googleusercontent.com上的一次性网址。这意味着如果您使用Content服务将数据返回到另一个应用程序,则必须确保HTTP客户端配置为遵循重定向
因此,您无法将Google Script URL用作webhook