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:
git clone https://github.com/Kylmakalle/heroku-telegram-bot.git
-
Edit bot.py file with your code
-
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! -
Also, don't do like this, it's insecure, realy.
-
-
Edit requirments.txt with your code's dependencies
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)
-
Fork this repo to your account.
-
Go to Dashboard, login, Press New and choose Create new app.
-
Fill in an App Name and choose Runtime Region.
-
Connect your GitHub repo at Deploy page.
-
Setup Automatics deploys (Optionaly).
-
Deploy a GitHub branch.
-
Then go to a Settings page, click Reveal Config Vars and then add your own, for example:
-
Finally, go to the Resources page.
- Install Heroku Redis add-on (Optionaly)
- Press on a small pen button, move slider and then click Confirm, that will start bot dyno.
- Simply move slider back if you need to stop bot dyno, remember to click Confirm.
- If for some reason it’s not working, check the logs here
- https://devcenter.heroku.com/articles/dynos
- https://devcenter.heroku.com/articles/config-vars
- https://devcenter.heroku.com/articles/heroku-redis
- https://devcenter.heroku.com/articles/error-codes
Thanks to Roman Zaynetdinov for awesome and easy CLI guide.