Modular customizable python-telegram-bot
template to speed-up development process.
configuration.yaml
prod:
- botname: My Production Bot
username: my_production_bot
token:
1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi
about:
"this is some short text about my bot"
description:
"This is a description of what my bot can do which customer will use"
configuration.yaml
dev:
- botname: Development Bot
username: my_development_bot
token:
1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi
about:
"this is some short text about development bot "
description:
"This is a description of what my development bot can do with testing"
choose the mode
mode: dev
or
mode: prod
handlers
directory: as a placeholder for all command handlersindex.py
file: to register all the function members- sample command handlers
echo.py
file:/echo
command handlerstart.py
file:/start
command handlerhello.py
file:/hello
command handlerhelp.py
file:/help
command handlerwhoami.py
file:/whoami
command handler
help.py
will generate help text usingdocstring
from all the function members- writing help as you code
def hello(update, context): """ /hello just say hello and reply """ update.message.reply_text( 'Hi {}, how are you?'.format(update.message.from_user.first_name))
- will produce help text
/hello just say hello and reply
Just run
docker-compose up --build
- prepare two bot accounts from @botfather
- one bot will be used for development
- another bot for production
git clone https://github.com/jansenicus/python-telegram-bot-template
- edit
configuration-sample.yaml
and save it asconfiguration.yaml
mode: prod
prod:
- botname: My Production Bot
username: my_production_bot
token:
1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi
about:
"this is some short text about my bot"
description:
"This is a description of what my bot can do which customer will use"
Make sure you are in the bot
directory to install all the requirements and then run the telegram bot
cd bot
pipenv install -r requirements.txt
pipenv run python main.py
docker build -t python-telegram-bot -f Dockerfile .
docker run -it --workdir /home python-telegram-bot pipenv run python main.py
You could also build and run in one go for the first time
docker-compose up -d
or you could also force build every you want to apply change into the image
docker-compose up -d --build
All command handlers are put in one directory handlers
and registered in one file index.py
. The result is a convenient way to import all command handlers in one import
call:
from handlers.index import index