aiogram-starlette-template icon indicating copy to clipboard operation
aiogram-starlette-template copied to clipboard

Template for telegram bots using aiogram, starlette-admin, telegram login widget, and FastAPI.

🤖 Aiogram Starlette Template

Telegram Bot Python Versions License

Starlette FastAPI Telegram PHPMyAdmin MySQL Redis Certbot Nginx Docker

Features

Project Components:

  • MySQL - Database management system.
  • Nginx - Proxy server for routing and handling web requests.
  • Certbot - SSL certificate management and issuance.
  • phpMyAdmin - Web-based database administration tool.
  • Admin Panel - Custom web interface for administrative tasks.
  • Telegram Bot - Bot implementation for interacting on Telegram.
  • Redis - In-memory data structure store, commonly used as a cache.

Launch and deployment:

  • Clone this repo:

    git clone https://github.com/nessshon/aiogram-starlette-template.git
    
  • Go to the project folder:

    cd aiogram-starlette-template
    
  • Clone environment variables file:

    cp .env.example .env
    
  • Configure environment variables variables file:

    nano .env
    
Continuation for local launch
  • Install dependencies

    pip install -r requirements.txt
    
  • Launch project:

    python -m project
    
Continuation for server deployment

The deployment script handles the creation of containers for MySQL and Redis.
Configures MySQL and Redis databases.
Configures Nginx as a proxy server for web requests.
Uses Certbot to generate and renew SSL certificates for secure communications.
Launches the admin panel, Telegram Bot and phpMyAdmin.

  • Change server_name on phpmyadmin.conf:

    server_name pma.example.com www.pma.example.com;
    
  • Change server_name on project.conf :

    server_name app.example.com www.app.example.com;
    
  • Install Docker and docker-compose:

    sudo apt install docker.io docker-compose -y
    
  • Deploy the project:

    docker-compose up --build
    

Environment Variables Reference

Click to expand Here is a reference guide for the environment variables used in the project:
Variable Type Description Example Local Example Prod
BOT_TOKEN str Bot token, obtained from @BotFather 123456:qweRTY 123456:qweRTY
BOT_USERNAME str The username of the bot same_bot same_bot
BOT_DEV_ID int User ID of the bot developer 123456789 123456789
BOT_ADMIN_ID int User ID of the bot administrator 123456789 123456789
APP_URL str The domain of the webhook https://...ngrok.free.app https://example.com
APP_HOST str The host address where the app is running localhost 0.0.0.0
APP_PORT int The port number on which the app is listening 8000 8000
WEBHOOK_SECRET str Secret key for securing the webhook qwerty12345 qwerty12345
WEBHOOK_PATH str The path of the webhook /bot /bot
REDIS_HOST str The hostname or IP address of the Redis server localhost redis
REDIS_PORT int The port number on which the Redis server is running 6379 6379
REDIS_DB int The Redis database number 1 1
MYSQL_ROOT_PASSWORD str Root password for MySQL --skip-- root-password
MYSQL_HOST str The hostname or IP address of the database server localhost localhost
MYSQL_PORT int The port number on which the database server is running 3306 3306
MYSQL_USER str The username for accessing the database user user
MYSQL_PASSWORD str The password for accessing the database password password
MYSQL_DATABASE str The name of the database dbname dbname
CERTBOT_EMAIL str Email address for Certbot notifications --skip-- [email protected]

Contribution

We welcome your contributions! If you have ideas for improvement or have identified a bug, please create an issue or submit a pull request.

Donations

TON - EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess

USDT (TRC-20) - TJjADKFT2i7jqNJAxkgeRm5o9uarcoLUeR

License

This repository is distributed under the MIT License. Feel free to use, modify, and distribute the code in accordance with the terms of the license.