/heroku-telegram-bot

Starter pack to host your Python Telegram Bot on Heroku for free.

Primary LanguagePythonMIT LicenseMIT

Hosting telegram bot on Heroku for free.

Easy way to host your python telegram bot on Heroku

Deploying via Heroku Toolbelt (CLI)

Install Heroku Toolbelt, then:

Clone repository

git clone https://github.com/Kylmakalle/heroku-telegram-bot.git

Edit files

  1. Edit bot.py file with your code

    1. ATTENTION! Do not collapse/delete/comment some_token = os.environ[SOME_TOKEN] style stings (you can delete redis setup line if you do not need it), do not change them with your REAL tokens, all tokens will be setted up below in this guide!

    2. More About Config Vars

    3. Also, don't do like this, it's insecure, realy.

  2. Edit requirments.txt with your code's dependencies

  3. Specify your python runtime, avaliable versions listed here

Go to command line

cd heroku-telegram-bot
heroku login
heroku create --region eu appname # create app in eu region, common regions: eu, us
heroku addons:create heroku-redis:hobby-dev -a appname # (Optionaly) installing redis
heroku buildpacks:set heroku/python # set python buildpack
git push heroku master # deploy app to heroku
heroku config:set TELEGRAM_TOKEN=123456789:AAABBBCCCDDDEEEFFFGGGHHHIIIJJJKKKLL # set config vars, insert your own
heroku config:set SOME_API_TOKEN=qwertyuiop1234567890
                ...
heroku ps:scale bot=1 # start bot dyno
heroku logs --tail # If for some reason it’s not working, check the logs
heroku ps:stop bot #stop bot dyno

Deploying via Heroku Dashboard (GUI)

  1. Fork this repo to your account.

  2. Edit files

  3. Go to Dashboard, login, Press New and choose Create new app.

  4. Fill in an App Name and choose Runtime Region.

  5. Connect your GitHub repo at Deploy page.

  6. Setup Automatics deploys (Optionaly).

  7. Deploy a GitHub branch.

  8. Then go to a Settings page, click Reveal Config Vars and then add your own, for example: Config Vars

  9. Finally, go to the Resources page.

    1. Install Heroku Redis add-on (Optionaly)
    2. Press on a small pen button, move slider and then click Confirm, that will start bot dyno.
    3. Simply move slider back if you need to stop bot dyno, remember to click Confirm.
    4. If for some reason it’s not working, check the logs here

    Logs

More about

Thanks to Roman Zaynetdinov for awesome and easy CLI guide.