2

I'm trying to push a telegram bot into Heroku. These are files within my folder.

/new_bot
---/requirements.txt
---/Procfile   #worker: python new_bot.py 
---/init.py    #empty
---/new_bot.py
---/.env

My procfile does NOT have any .txt extension. Inside the procfile is worker: python new_bot.py I am using atom text editor.

In my requirements .txt folder, these are the following requirements

requests
telegram
tornado>=5.1

The new_bot.py script is here

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackQueryHandler, CallbackContext
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
import requests

PORT = int(os.environ.get('PORT', 443))

TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")

def hello(update, context):
    update.message.reply_text('Hello! \U0001F600')

def main():  
    updater = Updater(TOKEN, use_context=True)
    dp = updater.dispatcher
    dp.add_handler(CommandHandler("hello", hello))
    updater.start_webhook(listen="0.0.0.0",
                          port=int(PORT),
                          url_path=TOKEN,
                          webhook_url='https://abc.herokuapp.com/' + TOKEN)

    updater.start_polling()

    updater.idle()
if __name__ == '__main__':
    main()

So it managed to build successfully, and I ran and did heroku ps:scale worker=1 in my heroku CLI, managed to deploy it successfully which showed this:

2021-07-15T11:56:11.022397+00:00 heroku[worker.1]: State changed from crashed to starting
2021-07-15T11:56:15.944190+00:00 heroku[worker.1]: Starting process with command `python new_bot.py`
2021-07-15T11:56:17.093075+00:00 heroku[worker.1]: State changed from starting to up
2021-07-15T11:56:21.000000+00:00 app[api]: Build succeeded
2021-07-15T11:56:22.155897+00:00 app[worker.1]: 2.26.0

On my Heroku UI, I am seeing this

worker
python new_bot.py
ON

However, I still keep getting this error at=error code=H14 desc="No web processes running" method=GET. I have seen many places in Stackoverflow that I have to use heroku ps:scale web=1, which is different from the command I used earlier which was heroku ps:scale worker=1. Can I just check what am I doing wrong here and how do I remedy it? Any help will be appreciated.

Edit: Hi guys I've actually found the problem already. It has to do with

updater.start_webhook(listen="0.0.0.0",
                          port=int(PORT),
                          url_path=TOKEN,
                          webhook_url='https://abc.herokuapp.com/' + TOKEN)

Thanks for helping anyway!

Jonathan
  • 424
  • 4
  • 14
  • 1
    Given the definition on your Procfile, the name of your dyno is `worker` so doing the `heroku ps:scale worker=1` should scale this dyno, in other words should be up. Check if your dyno is up with `heroku ps`, this command will display all your dynos. – Gealber Jul 16 '21 at 11:57
  • 1
    One question, this error, `I still keep getting this error at=error code=H14 desc="No web processes running" method=GET`, you are getting this error when you try to access the `web` application, right? I mean, through the browser? If that's the case, you shouldn't, given that you haven't deployed a `web` dyno. A telegram bot, as you had deployed it, is in the background, and will respond to any message that you send through Telegram. – Gealber Jul 16 '21 at 12:03
  • hi @Gealber, I have actually tried ```heroku ps```, it shows this ```worker.1: starting 2021/07/17 10:11:09 +0800 (~ 8s ago)```, but when I try to get a message, it doesn't return me anything. – Jonathan Jul 17 '21 at 02:13

1 Answers1

1

For a web process in heroku you need to add something like this to your Proc file:

Below is a rails equivalent, you need specific to your app.

web: bundle exec rails server -p $PORT

And then run:

heroku ps:scale web=1
kup
  • 731
  • 5
  • 18