首页 > 解决方案 > Python-Telegram 机器人在本地运行,但不在 Heroku 上

问题描述

我希望在 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。谢谢!

标签: herokupython-telegram-bot

解决方案


AFAIK Heroku 不支持长轮询,因此您应该使用 webhook。python-telegram-bot带有一个内置的 webhook。请参见此处以及此骨架存储库


推荐阅读