DEV Community

Cover image for Best way to deploy python telegram bot to Heroku! (Save money 💸 using webhooks)
Aahnik Daw
Aahnik Daw

Posted on Edited on Originally published at github.com

Best way to deploy python telegram bot to Heroku! (Save money 💸 using webhooks)

webhook-aiogram-heroku

A simple telegram echo bot is first made with aiogram, that fetches updates using web-hook connection.

Deploy

This bot can be easily deployed to Heroku cloud platform.

The following steps assume that you have Heroku CLI installed in your system.

  1. Clone the repo and move into the project directory.
git clone https://github.com/aahnik/webhook-aiogram-heroku.git
cd webhook-aiogram-heroku
🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini 🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini
  1. Create a new Heroku app.
heroku create
🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini 🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini
  1. Set the Config Vars.
Config Var Description
HEROKU_APP_NAME name of your Heroku app. You may set it manually or turn on Dyno Metadata feature which is currently in Heroku Labs.
BOT_TOKEN the token for your bot given by @BotFather after bot creation.
heroku labs:enable runtime-dyno-metadata
heroku config:set BOT_TOKEN=<your token>
🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini 🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini
  1. Push the code to Heroku.
git push heroku main
🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini 🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini

Cheers

To confirm your bot is working:

  • Run heroku ps which will show you details of your dyno.
=== web (Free): python start.py (1)
web.1: up
🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini 🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini
  • Send a message to your bot, and your bot will echo it back to you.

The bot will go to sleep after 30 minutes of inactivity. So you save dyno hours in Heroku.

Generic badge
 MIT license
telegram-chat

Top comments (1)

🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini
 
gariq11 profile image
🏆 Live Soccer TV: aahnik/best way to deploy python telegram bot to heroku save money using webhooks i - Pertandingan Hari Ini Comment hidden by post author - thread only accessible via permalink
gariq11 •

it is NOT
heroku config:set API_TOKEN=
it is
heroku config:set BOT_TOKEN=

Some comments have been hidden by the post's author - find out more