Search code examples
herokupython-telegram-bot

Python-Telegram bot running locally, but not on Heroku


I'm looking to deploy my python-telegram bot on Heroku but the bot seems to be unresponsive. The .py works just fine locally, but when I deploy it the app builds perfectly and is on, but produces no response on telegram when prompted. The code is very basic but I think I am missing something with the webhook maybe? I'm new to web stuff as my background is more in data science. Below is my code and 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"""

I'm happy to write a if dunder main, but I'm unsure still if I even need a webhook. Thanks!


Solution

  • AFAIK Heroku doesn't support long polling, so you should use a webhook. python-telegram-bot comes with a built-in webhook. See here and also this skeleton-repo.