How to create a simple Telegram bot in Python and then hosting it on Heroku (https://heroku.com).
PTB (python-telegram-bot) is the BotApi-wrapper I used here. As of recording this video, the current version was 13.7. Be aware that the shown implementation may not work with future versions of PTB.
I'll be using GitHub in between to have a space where our code is saved online and so that deploying to Heroku is more convenient after setting it up.
Heroku's free tier is pretty sweet for smaller projects. Please note that you only have 550 free dyno hours (in which your code is active) available per month. If your project reaches this limit, the bot won't work until the next month starts. according to my experience with a more frequently used bot, it usually lasts approx. until the 28th of each month. To save you some dyno hours, Heroku automatically shuts down the project if it's not in use for 30 minutes. After that it takes a few seconds for the bot to respond.
There's alternative platforms like PythonAnywhere (https://www.pythonanywhere.com) out there, but I think that Heroku should be fairly sufficient and quite handy. More about hosting your bot here:
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Where-to-host-Telegram-Bots
Useful links:
• Read this to get a glance at what PTB even is:
https://github.com/python-telegram-bot/python-telegram-bot#getting-started
• A written tutorial can be found here:
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot
• Find more information about what PTB can do here:
https://python-telegram-bot.readthedocs.io/en/stable/
• Find a more detailed starter project here:
https://github.com/PXNX/ptb-starter-project
• More example projects are available here:
https://github.com/python-telegram-bot/python-telegram-bot/tree/master/examples
• Contact BotFather to create a Bot account:
https://t.me/BotFather
• PyCharm - the IDE I'm using:
https://www.jetbrains.com/pycharm/download
• If you have any questions regarding PTB, feel free to ask here:
https://t.me/pythontelegrambotgroup
I hope it was helpful and you enjoyed it :)