Skip to content

ALGOANHAF/telegram-bot-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Python aiogram MySQL License

A production-ready Telegram bot template with MySQL, Admin Panel & Command Handlers


✨ Features

  • πŸ€– aiogram 3.x β€” Modern async Telegram bot framework
  • πŸ—„οΈ MySQL Database β€” Async connection pool via aiomysql
  • πŸ‘‘ Admin Panel β€” Ban/unban, broadcast, user info
  • πŸ” Auth Middleware β€” Auto-registers users, blocks banned users
  • πŸ“‹ Command Handlers β€” /start, /help, /me out of the box
  • πŸ—οΈ Clean Architecture β€” Modular handlers, middlewares, config

πŸ“ Project Structure

telegram-bot-template/
β”œβ”€β”€ main.py                  # Entry point
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env.example
β”œβ”€β”€ config/
β”‚   └── settings.py          # All config from .env
β”œβ”€β”€ database/
β”‚   └── db.py                # MySQL pool + all queries
└── bot/
    β”œβ”€β”€ handlers/
    β”‚   β”œβ”€β”€ start.py          # /start, /help
    β”‚   β”œβ”€β”€ user.py           # /me
    β”‚   └── admin.py          # /admin, /ban, /unban, /broadcast
    └── middlewares/
        └── auth.py           # Auto-register + ban check

⚑ Quick Start

1. Clone the repo

git clone https://github.com/algoanhaf/telegram-bot-template.git
cd telegram-bot-template

2. Install dependencies

pip install -r requirements.txt

3. Setup environment

cp .env.example .env
# Edit .env with your values

4. Create MySQL database

CREATE DATABASE telegram_bot;

5. Run the bot

python main.py

βš™οΈ Configuration (.env)

Variable Description
BOT_TOKEN Your bot token from @BotFather
ADMIN_IDS Comma-separated admin Telegram IDs
DB_HOST MySQL host (default: localhost)
DB_NAME Database name
DB_USER MySQL username
DB_PASSWORD MySQL password

πŸ“‹ Admin Commands

Command Description
/admin Show admin panel & stats
/ban <user_id> Ban a user
/unban <user_id> Unban a user
/userinfo <user_id> Get user details
/broadcast <message> Send message to all users

πŸ—„οΈ Database Schema

users (id, username, first_name, last_name, is_banned, is_admin, joined_at, last_seen)
messages_log (id, user_id, command, text, created_at)

Tables are auto-created on first run.


πŸ’Ό Need a Custom Bot?

Built something cool with this template? Need a fully custom bot for your business?

Fiverr GitHub


Made with ❀️ by ALGOANHAF

⭐ Star this repo if it helped you!

About

πŸ€– Production-ready Telegram bot template with MySQL, Admin Panel & Command Handlers | Built with aiogram 3.x

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages