Simple, but extensible template for telegram bot, using pyTelegramBotAPI and adaptix
git clone https://github.com/Cub11k/async_tgBotTemplate.git # via HTTPS
# or
git clone git@github.com:Cub11k/async_tgBotTemplate.git # via SSH
cd async_tgBotTemplate
- Change package name, description, version, author, homepage, etc. in
pyproject.toml
- Create virtual environment or use the existing one
- Activate virtual environment
- Install the package in editable mode
pip install -e .
Please note, that if you're launching the bot on Linux, you should consider using uvloop
,
as it drastically increases asyncio
performance
pip install -e .[uvloop]
Before running the bot you'll have to configure the environment using the environment variables
Environment variable | Description | Allowed values |
---|---|---|
USE_UVLOOP | Use uvloop to speed up asyncio |
True , 1 Default None |
CONFIG_PATH | Path to the config file to use | Default config.toml |
CONFIG_USE_ENV_VARS | Override config file with environment variables | True , 1 Default False |
CONFIG_ENV_MAPPING_PATH | Path to the file with mapping of config values and env vars | Default config_env_mapping.toml |
The simplest way to run the bot using long polling is to use the `launch-polling` script
```bash
launch-polling <path-to-the-config-file>
To get more details about the script, run it with the --help
flag
launch-polling --help
To run the bot using webhook, you'll have to adjust the module mypackage:webhook
according to the web-framework used
After that, you can launch the app using the web-server of your choice, e.g. gunicorn
gunicorn 'mypackage:webhook_app()' --bind=$HOST:$PORT --workers-class=$WORKERS_CLASS
pip uninstall <your-package-name>
Beware that mypackage
is not the package name, but the name of the module,
the package name is defined in pyproject.toml
Feel free to contribute to the project by creating issues and pull requests