Intially I was not able to push a simple bot to heroku, but yeah googling a lot made it work!
- Install Telegram :)
- Create a telegram bot by talking to Bot Father
- Install python in your computer, if you are on windows follow this
- Install git, follow this
- Install Heroku account here
- Install Heroku CLI from here
- Install editor of your choice, I preffer Atom
- Just git clone this repository and start working by editing the code
git clone https://github.com/AnshumanFauzdar/telegram-bot-heroku-deploy.git cd telegram-bot-heroku-deploy
- Or follow steps below!
- Create your bot like we have bot.py and write any python code that is intially working on your local machine!
- Make a folder like telegram-bot and put bot.py in the folder
- Make a blank python file named
__init__.py
- Make a Procfile this should be without any extension like .txt, you can go to view -> tick file name extensions and remove any extension
worker: python bot.py
- Write this in Procfile by using notepad or any editor of your choice! Here bot.py is your python code!
- Now we have to make a requirements.txt through which heroku will install the dependencies to make our bot work!
- What to add in requirements.txt
- Mine looks like this:
future>=0.16.0 certifi tornado>=5.1 cryptography python-telegram-bot
Add anything which you have included in the python code!
- Change directory to where you have made these files
- now in git bash CLI, intialize a git
git init
- Now install heroku CLI
- Next
heroku login heroku create app_name
- If you have already created app then select it:
heroku git:remote -a app_name
- Or else continue:
git add -f bot.py Procfile requirements.txt __init__.py
-
git commit -m "Added Files"
- Push files to heroku:
git push heroku master
- If it is not working then try this one:
git push heroku master --force
-
heroku ps
If it is not running then we have to reset dynos:
-
heroku ps:scale worker=0
-
heroku ps:scale worker=1
Now it should be running fine! Enjoy :)
Choose App name and deploy! Follow from Step 7 and edit bot.py with your token! And finally deploy!
- Check It Here!