Giter Site home page Giter Site logo

alehacksp / python-telegram-bot-heroku Goto Github PK

View Code? Open in Web Editor NEW

This project forked from liuhh02/python-telegram-bot-heroku

0.0 0.0 0.0 8 KB

A guide to hosting a telegram bot created using the python-telegram-bot library with heroku

License: MIT License

Python 100.00%

python-telegram-bot-heroku's Introduction

python-telegram-bot-heroku

A guide to hosting a telegram bot created using the python-telegram-bot library with heroku. Deploy your Ember project to Heroku from Github - Philip Mutua ... See the full article explaining the steps here.

Getting Started

Before you begin, you will need a Telegram bot API token from BotFather.

  1. Download the three files in this repo: bot.py (containing your python code for the Telegram bot), requirements.txt (containing the python libraries to be installed), and Procfile (containing the command to execute the python file).
  2. Login / create a Heroku account.
  3. Install Git.
  4. Install the Heroku CLI.
  5. Once installed, you can use the heroku command in your terminal / command prompt. Go to the same directory as the files in this repository, and type:

heroku login

A new window will be opened in your browser prompting you to login, so just click on the button.

  1. Once you are logged in, go back to the command line. Type in

heroku create

to create your new webapp. Heroku will assign your webapp a name as well as the link to your webapp, which should be of the format https://{yourherokuappname}.herokuapp.com/.

  1. To the bot.py file, change the TOKEN variable to the API token of your telegram bot, and change the yourherokuappname to the name of your heroku app in the line

updater.bot.setWebhook('https://yourherokuappname.herokuapp.com/' + TOKEN)

  1. Next, in your command line, type the following commands in the following order:

git init
git add .
git commit -m "first commit"

heroku git:remote -a YourAppName

git push heroku master

(Make sure to replace YourAppName with the name of your Heroku webapp)

You should then see the following messages:

In particular, it will say that a Python app is detected and it will install the required libraries in the requirements.txt file using pip. Then, it will read the Procfile which specifies that the bot.py file is to be executed.

  1. Go to your conversation with your Telegram bot on Telegram and type /start. The bot should be working now!

Since you are using the free plan on heroku, the bot will sleep after 30 minutes of inactivity. So do expect the bot to take a few seconds to respond to your /start if you are using it more than 30 minutes after it was previously used. Other than that, the bot will respond almost instantaneously~

What to do if your Bot stops responding

I’ve noticed the bot stops responding after about 24 hours of inactivity (because we are using the free version of Heroku), so if you want to “jolt” the bot awake, one way is to make a change to one of the files (eg. changing the python3 in the procfile to python and vice versa) and then committing the changes with the lines below:

git add .
git commit -m "changing python3 to python in Procfile"
git push heroku master

You should see again see the messages about a Python app being detected and once it finishes executing, your bot should revive now!

python-telegram-bot-heroku's People

Contributors

liuhh02 avatar lucamalagutti avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.