In this repo you can find the examples that were explained in the talk "How to make a Telegram bot with Python", from the PyConAr 2021. Link to the video.
You can talk to this bot on telegram! t.me/sofi_talk_bot
- Talk to BotFather on Telegram, to create a new bot and get your bot token. You can some related documentation here
- create a
local_settings.py
file in your repo's root with the following content:
BOT_TOKEN = "10201543:A..." # place here your bot's token.
To be able to connect to a Google Drive Spreadsheet (for feedback's commands for example) you will need some credentials:
- Create Google Drive credentials by following these steps
- Save the json created with your credentials in a file named
sheet_client_key.json
in the root of your repo. - Create a Spreadsheet and share it with the user of your recently created credentials
(
...@...iam.gserviceaccount.com
) - Update the variables
FEEDBACK_SPREADSHEET_NAME
andFEEDBACK_WORKSHEET_INDEX
in the filesettings.py
with the name of your spreadsheet and the index of its sheet where you want to add the feedback (0 is the first sheet)
Before running the bot, you need to install some dependencies. I recommend to create them inside a virtualenv:
$ python3 -m venv myvenv
$ . myvenv/bin/activate
$ pip install -r requirements.txt
Now you can run any of the bots! (remember to run these commands inside your virtualenv)
$ python first_bot.py
or:
$ python real_bot.py
- Create account in Heroku
- Install Heroku CLI
- Create an app on Heroku.
- Add a remote to your local repository
$ heroku git:remote -a example-app
Replace example-app
for your Heroku app name.
- Deploy by simply pushing your changes
$ git push heroku master
- from a browser (or from a terminal with curl or httpie, etc) make a request to
<your_heroku_app_domain>/webhook
to initialize the webhook for your bot.
Note: you need to have a Procfile
file pointing to a web app, like the one you can
find in the root of this repo.