Skip to content

Aiogram 3.x bot template using PostgreSQL (asyncpg) with SQLAlchemy + alembic.

License

Notifications You must be signed in to change notification settings

wakaree/aiogram_bot_template

Repository files navigation

aiogram_bot_template

System dependencies

  • Python 3.11+
  • Docker
  • docker-compose
  • make
  • poetry

Deployment

Via Docker

  • Rename .env.dist to .env and configure it
  • Rename docker-compose.example.yml to docker-compose.yml
  • Run make app-build command then make app-run to start the bot

Via Systemd service

  • Configure and start PostgreSQL
  • Configure and start Redis (» Read more)
  • Rename .env.example to .env and configure it
  • Run database migrations with make migrate command
  • Fill User and WorkingDirectory fields in systemd/telegram-bot.example.service (» Read more
  • Copy systemd/telegram-bot.example.service to /etc/systemd/system/telegram-bot.service
  • Run systemctl start telegram-bot to start the bot
  • If you want to start the bot on system boot, run systemctl enable telegram-bot

Development

Setup environment

poetry install

Update database tables structure

Make migration script:

make migration message=MESSAGE_WHAT_THE_MIGRATION_DOES

Run migrations:

make migrate

Used technologies:

  • Aiogram 3.x (Telegram bot framework)
  • PostgreSQL (persistent relational database)
  • SQLAlchemy (working with database from Python)
  • Alembic (lightweight database migration tool)
  • Redis (in-memory data storage for FSM and caching)
  • Project Fluent (modern localization system)
  • FTL-Extract (tool for extracting localizable strings from source code files in Fluent format)