小编Shi*_*los的帖子

如何在Heroku上设置python-telegram-bot webhook?

我正在使用python-telegram-bot包装器,我一直在尝试在Heroku上托管一个简单的回声电报机器人,以适应用于Google App Engine 的预先存在的示例以及维基上的webhook指南,但无济于事.

我似乎无法使webhook工作,并且机器人能够正确地回显消息.

我似乎无法弄清楚什么是错的,所以任何帮助指出我正确的方向将非常感谢!

我的尝试详述如下.

import telegram
from os import environ
from telegram.ext import Updater
from flask import Flask, request
from credentials import TOKEN, APP_URL

app = Flask(__name__)

global bot
bot = telegram.Bot(token=TOKEN)


@app.route('/' + TOKEN, methods=['POST'])
def webhook_handler():
    if request.method == "POST":
        # retrieve the message in JSON and then transform it to Telegram object
        update = telegram.Update.de_json(request.get_json(force=True))

        chat_id = update.message.chat.id

        # Telegram understands UTF-8, so encode text for unicode compatibility
        text …
Run Code Online (Sandbox Code Playgroud)

python-telegram-bot telegram-bot

6
推荐指数
1
解决办法
6082
查看次数

标签 统计

python-telegram-bot ×1

telegram-bot ×1