XDPlatypus
XDPlatypus

Reputation: 23

Issues with Telegram Bot deployment to Heroku

I deployed a Python Telegram bot to Heroku, but the bot isn't responding.

In terminal, typing "heroku logs -t" shows that the build succeeded, but there is nothing else shown when I send a command like /start to the Telegram bot.

I'm not sure if it's something with my webhooks or just my implementation of the functions in the bot? For the webhooks part, I basically copy-pasted the getMessage, webhook and if name == main parts from https://github.com/eternnoir/pyTelegramBotAPI/blob/888c7a6b0d97c376947ee7b525d4b70583acc3fc/examples/webhook_examples/webhook_flask_heroku_echo.py

Or is the issue something wrong with my handlers for the commands? This is what my code looks like, minus the functions that are being called in main. (the part heroku url is removed so that my heroku url isn't being put out here, but it's correct in the original code)

def main() -> None:
    updater = Updater(TOKEN)

    updater.dispatcher.add_handler(CommandHandler('start', start))
    updater.dispatcher.add_handler(CallbackQueryHandler(button))
    updater.dispatcher.add_handler(CommandHandler('help', help_command))
    updater.dispatcher.add_handler(CommandHandler('test', test_command))

@server.route('/' + TOKEN, methods=['POST'])
def getMessage():
    json_string = request.get_data().decode('utf-8')
    update = telebot.types.Update.de_json(json_string)
    bot.process_new_updates([update])
    return "!", 200

@server.route("/")
def webhook():
    bot.remove_webhook()
    bot.set_webhook(url="heroku url" + TOKEN)
    return "!", 200

if __name__ == '__main__':
    server.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))
    main()

Upvotes: 0

Views: 1044

Answers (1)

At onece, you can try to start bot with command heroku run python main.py

Upvotes: 1

Related Questions