This repository provides a comprehensive template for creating Telegram bots using the Aiogram framework. It includes a powerful admin panel accessible via the /admin
command, making it ideal for managing bot functionalities and user interactions.
- About the Project
- Project Features
- Technologies Used
- Project Structure
- Installation and Usage
- Contributing
- Reporting Issues
- License
- Contact
This template is designed for developers looking to create Telegram bots using the Aiogram framework. It comes with an integrated admin panel that allows bot administrators to manage users, send advertisements, add new admins, and more, directly from the bot interface.
- Admin Management: Add, remove, and manage admins.
- Advertisement Sending: Send ads with a speed of approximately 100 messages per minute.
- User Management: Block, check, and manage users.
- Mandatory Channels: Add and manage mandatory channels for users.
- Statistics: View bot usage statistics.
- Language Support: The bot operates in the user's Telegram device language.
- Permission Control: Admins have different levels of control over the bot and other admins.
The admin panel is accessible by sending the /admin
command in the bot. It allows the following functionalities:
- Admin Control: Full rights for the main admin to manage other admins.
- Channel Management: Control only the channels added by the respective admin.
- Role-Based Access: Admins can only perform actions based on their permissions.
- Send advertisement: Send advertisement message for all user.
- Control bot: Admin can control bot and bot user.
- View Statistika: Vaev real Statistika.
- Programming Language: Python (3+), Cython (3+)
- Framework: Aiogram (3.5) absolute.
- Database: Mysql (8+)
- Dependencies:
aiogram==3.5.0
- Aiogram Documentationdeep-translator==1.11.4
- Deep Translator Documentationenvirons==11.0.0
- Environs Documentationmysql-connector-python==9.0.0
- MySQL Connector/Python Documentationopenpyxl==3.1.5
- OpenPyXL Documentationpandas==2.2.2
- Pandas DocumentationCython==3.0.11
- Cython Documentationrequests==2.32.3
- Requests Documentationurllib3==2.2.2
- urllib3 Documentation
Aiogram-Bot-Template/
├── README.md # Project documentation
├── main.py # Entry point for the bot
├── loader.py # Bot loader
├── setup.py # Setup script for the project
├── requirements.txt # Project dependencies
├── LICENSE # License file
│
├── cython_code/ # Cython optimized code
│ ├── file_db.pyx # Class for working with data in files
│ ├── my_translator.pyx # Translator class
│ ├── send_ads.pyx # Advertisement sender for all users
│ ├── throttling_middleware.pyx # Middleware class to manage throttling of requests to prevent overloading
│ └── user_check.pyx # Check if user has joined the required channels
│
├── data/ # Data-related modules
│ └── config.py # A collection of necessary variables
│
├── filters/ # Custom filters for the bot
│ ├── admin.py # Filters for admin
│ └── ban.py # Filters for banned users
│
├── function/ # Core bot functionalities
│ ├── function.py # A collection of various functions
│ ├── send_ads.py # Moved to cython_code/send_ads.pyx
│ └── translator.py # Translator function
│
├── handlers/ # Request handlers
│ ├── __init__.py # Initialize the handlers module
│ ├── admins/ # Admin-specific handlers
│ │ ├── super_admin.py # Super admin functionalities
│ │ ├── main_panel.py # Main admin panel operations
│ │ ├── admin_settings/ # Admin settings submodule
│ │ │ ├── attach_admins.py # Attach admin functionalities
│ │ │ └── add_admin_first_step.py # Steps to add a new admin
│ │ ├── statistika/ # Statistical data management for admins
│ │ │ ├── statistika.py # Main statistics functionalities
│ │ │ └── download_statistics.py # Download statistics data
│ │ ├── check_usr/ # Admin user check functionalities│
│ │ │ ├── block_users.py # Block users functionalities
│ │ │ ├── attach_usr.py # Attach users to specific operations
│ │ │ ├── send_message.py # Sending messages to users
│ │ │ └── send_ads_message.py # Sending advertisement messages
│ │ └── send_ads/ # Admin advertisement functionalities
│ │ ├── send_ads.py # Send ads functionalities
│ │ ├── stop_ads.py # Stop advertisements functionalities
│ │ └── get_message.py # Get messages for advertisements
│ ├── users/ # User-specific handlers
│ │ ├── check_ban.py # Check if a user is banned
│ │ ├── check_join.py # Check if a user has joined required channels
│ │ ├── check_usr.py # General user check functionalities
│ │ ├── close.py # Close user sessions
│ │ ├── help.py # Help command for users
│ │ └── start.py # Start command for users
│ └── errors/ # Error handling module
│ └── error_handler.py # General error handler functionalities
│
├── keyboards/ # Bot keyboards
│ └── inline/ # Inline keyboards
│ ├── admin_btn.py # Inline keyboards for admins
│ ├── button.py # Base inline keyboards
│ ├── close_btn.py # Close button functionality
│ └── user.py # User-specific inline keyboards
│
├── middlewares/ # Middlewares for processing requests
│ ├── __init__.py # Initialize middlewares
│ ├── check_user.py # Not used, moved to cython_code/user_check.pyx
│ └── throttling.py # Not used, moved to cython_code/throttling_middleware.pyx
│
├── states/ # State management
│ └── admin_state.py # Class state for admin
│
└── utils/ # Utility scripts
├── notify_admins.py # Notify admins when the bot is started
├── set_bot_commands.py # Set up the necessary commands (/) for the bot
└── db_api/
├── bot_db.py # Not used, moved to cython_code/file_db.pyx
└── mysql_db.py # Class for working with MySQL database
- Clone the Repository:
git clone https://github.com/UznetDev/Aiogram-Bot-Template.git
- Navigate to the Project Directory:
cd Aiogram-Bot-Template
- Create a virtual environment:
python -m venv env
- Activate the virtual environment:
- On Windows:
env\Scripts\activate
- On macOS and Linux:
source env/bin/activate
- On Windows:
- Install Dependencies:
pip install -r requirements.txt
- Create a .env file:
- On Windows:
wsl nano .env
- On macOS and Linux:
nano .env
- On Windows:
- Write in the .env file:
BOT_TOKEN=<Your Bot token from @BotFather>
ADMIN=<Admin Id>
HOST=<host default localhost>
MYSQL_USER=<your MySQL user>
MYSQL_PASSWORD=<your MySQL password>
MYSQL_DATABASE=<your MySQL database>
- Run the setup.py:
python setup.py build_ext --inplace
- Run the Bot:
python main.py
To run the bot as a Windows Service, you can use tools like NSSM (Non-Sucking Service Manager):
- Download and install NSSM.
- Create a service using NSSM and point it to
python main.py
in the project directory.
To run the bot as a systemd service on Linux:
-
Create a service file:
nano /etc/systemd/system/Aiogram-Bot-Template.service
[Unit] Description=Aiogram-Bot-Template Service After=network.target [Service] User=yourusername WorkingDirectory=/path/to/Aiogram-Bot-Template ExecStart=/usr/bin/python3 /path/to/Aiogram-Bot-Template/main.py Restart=always [Install] WantedBy=multi-user.target
sudo systemctl start Aiogram-Bot-Template sudo systemctl enable Aiogram-Bot-Template
We welcome contributions! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
If you find any issues with the bot or have suggestions, please open an issue in this repository.
This project is licensed under the MIT License. See the LICENSE file for details.
If you have any questions or suggestions, please contact:
- Email: uznetdev@gmail.com
- GitHub Issues: Issues section
- GitHub Profile: UznetDev
- Telegram: UZNet_Dev
- Linkedin: Abdurakhmon Niyozaliev