A cookiecutter template for Python Telegram Bot based on python-template and virus/total-telegram-bot, repos of my college clarriu97.
- Scripted operations: with GNU make
- Testing: with pytest
- Multiple Python versions support: Setup tox to easily test for Python 3.8, 3.9, etc.
- Package documentation: ready for generation with mkdocs
- Version handling: Pre-configured version bumping with a single command: bump2version
Install cookiecutter (1.4.0 or higher):
python3 -m pip install --user cookiecutter
Create the project:
cookiecutter https://github.com/i97orbegozo/telegram-bot-template
Fill all the details and your project should be ready in a matter of seconds!
If you want to upload your project to Github, please make sure the URL is the same as the one you configured during project creation to ensure everything works properly (links, etc.).
The template provides sensible defaults for all the configuration options, however you can customize your project using the following parameters:
author
: The name of the person or team behind this project.author_email
: The email of the author. In the case of a team or group, you can use a mailing list address.project_name
: The name of the project. Prefer short names (ideally one word) using kebab-case (hyphen-separated lowercase letters)project_slug
: The name of the project in snake case (underscore-separated lowercase letters). Will be autogenerated if left empty.project_short_description
: A short description of the projectproject_url
: The Github URL of the project. It's recommended that you create the project first on Github and paste the generated URL here.version
: The initial version (Semantic Versioning). It's recommended you use the default value (0.1.0
).python_versions
: The supported python versions. If possible, prefer supporting only the latest version available.
Once you have created the project from the template, let's see how we can launch it to start developing. First let's create a virtual environment using tox:
$ make env-compile
$ make env-create
This will create a virtual environment with all the needed dependencies (using tox). You can activate this environment with:
$ source ./.tox/{{cookiecutter.project_slug}}/bin/activate
Then, you can run make help
to learn more about the different tasks you can perform on this project using make.
But back to what we are interested in, to run the bot, you must follow the following steps:
- Create a bot using father bot and getting its apikey. Here you will find more information.
- Add the Telegram bot API key to your
.bashrc
/.zshrc
...export BOT_APIKEY='your-API-key-here'
- Run the bot
make run
And that's it! Your bot is running an ready to start a conversation. Try to send /start
or /help
commands in your telegram bot and you should get a response message!
You can freely contribute to this template by submitting a merge request with the intended changes. Before you do, please take a look at the CONTRIBUTING guidelines.