【问题标题】:Python-Telegram bot running locally, but not on HerokuPython-Telegram 机器人在本地运行,但不在 Heroku 上
【发布时间】:2021-03-23 17:17:48
【问题描述】:

我希望在 Heroku 上部署我的 python-telegram 机器人,但该机器人似乎没有响应。 .py 在本地工作得很好,但是当我部署它时,应用程序可以完美构建并启动,但在提示时不会在电报上产生任何响应。代码非常基本,但我想我可能缺少 webhook 的一些东西?我是网络新手,因为我的背景更多是数据科学。下面是我的代码和procfile。

"""import telegram
from telegram.ext import Updater
from telegram.ext import CommandHandler
import ftx
client = ftx.FtxClient()

telegram_bot_token = "token"

updater = Updater(token=telegram_bot_token, use_context=True)
dispatcher = updater.dispatcher


def start(update, context):
    chat_id = update.effective_chat.id
    context.bot.send_message(chat_id=chat_id, text= "1 ***=" + "$" + str(client.get_market('***/USD')['last']) + "\n" + "24 Change =" + str(round(client.get_market('***/USD')['change24h'],2)*100) + "%" + "\n" + "24 Hour Volume =" + str(client.get_market('***/USD')['volumeUsd24h']) + "USD"
                             + "\n"*2 + "The information presented by the price tracker is not meant to be taken as financial advice.")

#I think over here I need something else 
dispatcher.add_handler(CommandHandler("***", start))
updater.start_polling()"""

#Proc
"""worker: python bot.py"""

我很高兴编写 if dunder main,但我仍然不确定是否需要 webhook。谢谢!

【问题讨论】:

    标签: heroku python-telegram-bot


    【解决方案1】:

    AFAIK Heroku 不支持长轮询,因此您应该使用 webhook。 python-telegram-bot 带有一个内置的 webhook。请参阅here 和此skeleton-repo

    【讨论】:

    • 以下代码需要修改:dispatcher.add_handler(CommandHandler("***", start)) updater.start_polling() to updater.start_webhook(listen="0.0.0.0", port=int(PORT), webhook_url='https://app-name.herokuapp.com/') updater.idle()
    猜你喜欢
    • 2020-02-02
    • 2020-09-21
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 2014-04-07
    • 2018-02-05
    • 2016-06-19
    相关资源
    最近更新 更多