- π€ 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
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
1. Clone the repo
git clone https://github.com/algoanhaf/telegram-bot-template.git
cd telegram-bot-template2. Install dependencies
pip install -r requirements.txt3. Setup environment
cp .env.example .env
# Edit .env with your values4. Create MySQL database
CREATE DATABASE telegram_bot;5. Run the bot
python main.py| 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 |
| 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 |
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.
Built something cool with this template? Need a fully custom bot for your business?