https://github.com/blazzed21/py-aiogram-template-bot
Template for quickly starting an async Telegram bot using redis, sqlite, docker, python asyncio
https://github.com/blazzed21/py-aiogram-template-bot
aiogram asyncio bot docker redis telegram telegram-bot-api
Last synced: about 1 year ago
JSON representation
Template for quickly starting an async Telegram bot using redis, sqlite, docker, python asyncio
- Host: GitHub
- URL: https://github.com/blazzed21/py-aiogram-template-bot
- Owner: BLazzeD21
- License: mit
- Created: 2023-10-10T14:25:09.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-05T01:50:35.000Z (over 2 years ago)
- Last Synced: 2025-03-28T20:46:43.683Z (about 1 year ago)
- Topics: aiogram, asyncio, bot, docker, redis, telegram, telegram-bot-api
- Language: Python
- Homepage: https://aiogram.dev/
- Size: 90.8 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README






> ❗️ This version of the bot is not final, new functionality is being added
# Template for creating a telegram bot using the aiogram framework
This bot was created for educational purposes and is a template with examples of using various functionality of the aiogram 3 framework for creating telegram bots. In this example, a bot with a registration form is implemented. You can register, view your profile and view the profiles of other users. Try, study, change existing functionality and add new ones!
**This template has:**
- virtual environment,
- custom filters,
- environment variables,
- bot configuration,
- strict modularity,
- routers,
- replyKeyboards,
- inlineKeyboards,
- setMyCommands,
- callback Factory,
- SQLite databases,
- FSM based on redis,
- Custom pagination.
# Bot structure 📁
Folder | Description
------------- | -------------
config | Configuration files, database
filters | Admin filter
handlers | Handlers of commands and callbacks
keyboards | Dynamically generated keyboards
lexicon | Dictionary with all text
logs | Storage of all logs
middlewares | Middlewares for antispam and etc.
models | Modules for interacting with the database
states | Modules that describe classes that reflect the possible states of
users during interaction with the bot, for the implementation of FSM
utils | Functions that run multiple times
# Development 🛠
### 1. To create a virtual environment:
- For windows - ```python -m venv venv```
- For macOS & Linux - `python3 -m venv venv`
### 2. The virtual environment is activated with the command:
- For windows - `venv\Scripts\activate.bat`
- For Power Shell - `venv\Scripts\activate.ps1`
- For macOS & Linux - `source venv/bin/activate`
### 3. To install all dependencies in a virtual environment:
```bash
pip install -r requirements.txt
```
### 4. To add new dependencies:
```bash
pip freeze > requirements.txt
```
### 5. How to leave the virtual environment:
```bash
deactivate
```
### 6. How to launch a bot:
- For windows - `py start.py`
- For macOS & Linux - `python3 start.py`
If you want the bot to automatically restart every time you save files, you can use the [nodemon](https://www.npmjs.com/package/nodemon) tool:
```bash
npm i -g nodemon
```
You can launch the bot via:
```bash
nodemon --exec py/python3 start.py
```
# Deploying a bot 💾
### 1. Docker installation
**❗️ Important**
Before starting installation, check the system requirements:
- 64-bit architecture
- kernel no lower than version 3.10 (suitable for Ubuntu version 16.04 and higher)
Update the existing package list:
```bash
sudo apt update
```
Install a few necessary packages that allow `apt` to use packages over HTTPS:
```bash
sudo apt install apt-transport-https ca-certificates curl software-properties-common
```
Add the GPG key for the official Docker repository to your system:
```bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
```
Add the Docker repository to the APT sources:
```bash
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
```
Update the package database and add the Docker packages from the newly added repository:
```bash
sudo apt update
```
Install Docker:
```bash
sudo apt install docker-ce
```
Docker must be installed. Check that it is running:
```bash
sudo systemctl status docker
```
### 2. Installation make
You need to update packages and install make on the server:
```bash
sudo apt-get update && sudo apt-get -y install make
```
Check the installed version:
```bash
make -v
```
### 3. Docker container
Go to the bot repository:
```bash
cd name
```
To create a container image you need:
```bash
make build
```
To start a container:
```bash
make run
```