Python-Telegram bot 运行 在本地,但不在 Heroku 上

Python-Telegram bot running locally, but not on 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。谢谢!

AFAIK Heroku 不支持长轮询,所以你应该使用 webhook。 python-telegram-bot 带有一个内置的 webhook。参见 here and also this skeleton-repo