Skip to content

Chanael Admin Bot — is a simple Telegram bot designed for managing content and users in a Telegram channel.

License

Notifications You must be signed in to change notification settings

dev-lymar/channel-admin-bot

Repository files navigation

channel-admin-bot

Python PostgreSQL SQLAlchemy aiogram Ruff Ruff Flake8

Admin Bot — is a simple and user-friendly Telegram bot designed for efficient management of content and users within a Telegram channel. The project is built using Python 3.12.2, leveraging aiogram for seamless interaction with the Telegram API, asyncpg for efficient asynchronous database operations, Babel for easy localization, and SQLAlchemy for robust database modeling with PostgreSQL. This combination ensures high performance, scalability, and ease of use for administrators and content managers.

Admin Bot

Table of Contents

Key Features:

  • Post Management: View, create, edit, and delete posts.
    • Administrators can maintain full control over content, ensuring that all posts meet the desired standards before publication
  • Publish to Channel: Publish posts directly to a Telegram channel.
    • Content managers can quickly share updates or announcements with their audience, streamlining communication.
  • User Roles: Assign and manage roles like administrator or content manager.
    • Manage permissions directly through the bot, ensuring that access to functions is given only to authorized users.
  • Localization: Supports English and Russian (en/ru).
    • Ready to expand to additional languages, offering flexibility for different user bases and international audiences.

Installation and Setup

Requirements:

  • Python 3.12.2
  • PostgreSQL 16.3

Install dependencies from requirements.txt

Installation Steps

Clone the repository:

git clone https://github.com/dev-lymar/channel-admin-bot.git

Create and activate a virtual environment:

python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

Install dependencies:

pip install -r requirements.txt

Create a .env file: Copy .env.example file:

cp .env.example .env

Edit the .env file with your API token and PostgreSQL database details:

API_TOKEN=your_bot_token
ADMIN_ID=administrator_ID (For initial setup)
DB_URL=postgresql+asyncpg://user:password@localhost:5432/database_name
CHAT_ID=channel_ID_for_publications

Run the bot with automatic translation compilation and migrations:

make run

Project Structure

.
├── main.py                 # Entry point of the application
├── config/                 # Configuration files
│   ├── .env.example        # Example environment variables file
│   └── bot_config.py       # Bot configuration and settings
├── db/                     # Database management
│   ├── db_handler/         # Handlers for posts and user roles
│   └── models/             # Database models
├── handlers/               # Command and function handlers for the bot
│   ├── admin_panel/        # Logic for the admin panel
│   └── start/              # Start command
├── locales/                # Localization files
│   ├── en/                 # English translations
│   └── ru/                 # Russian translations
├── keyboards/              # Telegram keyboards for user interaction
├── states/                 # User state management
├── requirements.txt        # Project dependencies
├── README.md               # Project documentation
└── LICENSE                 # License for project usage

Makefile Commands

  • make run: Runs the bot and compiles translation files .po into .mo.
  • make lint: Checks the code for style compliance using ruff and flake8.

Adding New Languages

  1. If there are changes in the text, update the message template (if not, proceed to step 3):
pybabel extract -k _:1,1t -k _:1,2 -k __ --input-dirs=. -o locales/messages.pot
  1. Update existing locales:
pybabel update -d locales -D messages -i locales/messages.pot
  1. Create a new locale (e.g., uk for Ukrainian):
pybabel init -i locales/messages.pot -d locales -D messages -l uk
  1. Compile translations automatically using make run or manually:
pybabel compile -d locales -D messages

Future Plans

  • Docker Integration: Implement a Docker file for easier project deployment.
  • Documentation: Provide detailed documentation for all modules, including usage examples and possible scenarios.
  • Role Expansion: Add more roles and access management capabilities.

Contributing

We welcome contributions from the community! If you want to add new features or fix bugs, please follow these steps:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/feature-name
  3. Make your changes and commit them: git commit -m 'Added a new feature'
  4. Push your changes: git push origin feature/feature-name
  5. Create a pull request.

Before creating a pull request, make sure your code passes all ruff and flake8 checks.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Author

This project was developed by dev-lymar. If you enjoyed the project, please give a star ⭐️ on the repository.

If you have any questions or suggestions, feel free to reach out: