/aiogram-template

Template of aiogram telegram bot

Primary LanguagePython

โšก Aiogram bot template

It is a template you can use for creating telegram bot with aiogram 3. It supports internationalization

Tools:

  • ๐Ÿ’ช Aiogram (v3)
  • ๐Ÿ˜„ i18n
  • ๐Ÿคน๐Ÿฝ Loguru

๐Ÿ”ฅ Getting started

Requirements:

  • Python
  • Make

Installing

For linux
git clone git@github.com:lleballex/aiogram-template.git
cd aiogram-template
python3 -m venv env
. env/bin/activate
pip install -r requirements.txt
For windows
git clone git@github.com:lleballex/aiogram-template.git
cd aiogram-template
python -m venv env
env\scripts\activate
pip install -r requirements.txt

Starting

python src/bot.py

โœ Adding handlers

Just create new file in src/handlers folder or its subfolder

Initialize router and use it to handle events:

from aiogram import Router
my_router = Router()

Add created router to router list in src/handlers/__init__.py:

from .my_file import my_router
routers = [my_router]

๐Ÿ“– Internationalization

This template uses i18n. So wrap your messages in aiogram.utils.i18n.gettext to make it translatable
More information you can find here

Extracting messages (creating .pot):

make i18n-extract

Initializing a new language:

mkdir locales
pybabel init -i locales/messages.pot -d locales -D messages -l en

Compiling translations (.po -> .mo):

make i18n-compile

Updating translated messages (.po) with new extracted messages (.pot):

make i18n-update

๐Ÿ™‹๐Ÿฝโ€โ™‚๏ธ Contact me