Skip to content

serdukow/easy-aiogram-bot-template

Repository files navigation

Easy Aiogram Bot Template

Python Aiogram FastAPI

🤖 Simple, but powerful template for scalable Aiogram bots.

Features

  • Poetry: As main dependency and package manager.

  • Webhook Support: Easily configure and deploy bots with webhooks.

  • Nginx Integration: Serving your bot over HTTPS and manage webhooks.

  • Logging & Monitoring: Logging, debugging and monitoring.

  • Dockerized: Fully Dockerized.

  • Postgres: As main database storage.

  • Redis: As main cache storage

  • Localization: Translatable support for different languages with.


Get started

Clone repository

git clone https://github.com/serdukow/easy-aiogram-bot-template.git
cd easy-aiogram-bot-template

Webhook

If you want to use webhook, ensure you have your own domain.
Then proceed to How to Set Webhook

Polling

To start bot without webhook, just fill .env with your keys, then verify it by run this command in terminal:

poetry run pytest tests/test_polling.py

then remove services nginx, certbot from docker-compose.yml and finally:

docker compose up --build

How to set Webhook

To set up the webhook, follow these steps:

  1. Set your domain in the .env file under the NGINX_HOST variable.
NGINX_HOST=your-domain.com
  1. Build and start the Docker containers using the .env file:
docker compose --env-file .env build
docker compose run --rm -d -p 80:80 nginx
  1. Verify it by using curl:
curl http://your-domain.com

If you receive an HTTP 301 redirect, everything is working fine.

  1. Simulate certificate issuance:
docker compose run --rm certbot certonly --webroot --webroot-path /var/www/certbot/ --dry-run -d your-domain.com

If the dry run is successful, you should see a appropriate message

  1. Issue the SSL certificate:
docker compose run --rm certbot certonly --webroot --webroot-path /var/www/certbot/ -d your-domain.com
  1. Stop the containers:
docker compose kill && docker compose down
  1. Update docker-compose.yml for production:
volumes:
# - ./nginx/initial:/etc/nginx/templates/:ro
- ./nginx/templates:/etc/nginx/templates/:ro
  1. Finally verify and restart with the final setup, do not forget to set this vars in .env:
USE_WEBHOOK=True
WEBHOOK_URL='https://your-domain.com'

then run test:

poetry run pytest tests/test_webhook.py

finally compose

docker compose up --build

Renewing SSL Certificate: After 3 months, you’ll need to renew the SSL certificate. To do so, run:

docker compose up
dockercompose run --rm certbot renew

Roadmap

  • Tests
    • Basic
    • Versions
  • React Webapp integration
  • Database
    • Alembic

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

Special thanks

@ssharkexe

About

Template for scalable Aiogram bots.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages