Skip to content

Sam1sh-code/TG-ManagerBot

Repository files navigation

Telegram Bot for Clothes Shop

A modern Telegram bot built with aiogram 3.x for a clothes shop, featuring admin messaging, spam protection, and comprehensive logging.

Features

  • 🎯 User-friendly interface with inline keyboards
  • 📨 Admin messaging system with reply functionality
  • 🛡️ Spam protection - users must click "info" button to unlock messaging
  • 📊 Comprehensive logging with automatic rotation and cleanup
  • 🔒 Secure configuration via environment variables
  • 🚀 Production-ready with error handling and validation

Quick Start

Prerequisites

  • Python 3.14+
  • Poetry (for dependency management)
  • Telegram Bot Token from @BotFather

Installation

  1. Clone the repository:

    git clone <your-repo-url>
    cd TgBot
  2. Install dependencies:

    poetry install
  3. Configure environment:

    cp .env.example .env
    # Edit .env with your values
  4. Run the bot:

    poetry run python main.py

Configuration

Create a .env file in the root directory:

TOKEN=your_telegram_bot_token_here
ADMIN_GROUP_ID=-your_admin_group_chat_id
ADMIN_GROUP_ID_to_message=-your_admin_group_chat_id

Getting Chat IDs

  1. Bot Token: Get from @BotFather
  2. Group ID: Add @userinfobot to your group and get the ID

Usage

For Users:

  • /start - Welcome message with menu
  • Menu - Browse brands (links to external sites)
  • Contacts - Get contact information
  • info - Unlock messaging to admins (30-minute session)
  • Send messages/photos after clicking "info"

For Admins:

  • Reply to forwarded messages in the admin group
  • Messages are automatically forwarded back to users
  • Original messages are deleted after successful reply

Architecture

├── main.py              # Entry point
├── handlers.py          # Message handlers and logic
├── keyboards.py         # Telegram keyboards
├── config.py            # Configuration and logging
├── pyproject.toml       # Poetry dependencies
├── .env                 # Environment variables
└── logs/                # Log files (auto-rotated)

Security Features

  • Token Protection: Sensitive data in .env file
  • Spam Protection: Session-based messaging approval
  • Input Validation: User ID and message validation
  • Error Handling: Comprehensive exception handling
  • Logging: All actions logged with rotation

Development

Adding New Features

  1. Add handlers in handlers.py
  2. Update keyboards in keyboards.py if needed
  3. Test thoroughly before deployment

Logging

Logs are stored in logs/bot.log with automatic rotation:

  • Max 10MB per file
  • 5 backup files (50MB total)
  • Auto-cleanup of files older than 30 days

Deployment

Docker (Recommended)

# Build image
docker build -t tgbot .

# Run container
docker run -d --env-file .env tgbot

Systemd Service

Create /etc/systemd/system/tgbot.service:

[Unit]
Description=Telegram Bot Service
After=network.target

[Service]
Type=simple
User=your-user
WorkingDirectory=/path/to/TgBot
ExecStart=/path/to/poetry run python main.py
Restart=always

[Install]
WantedBy=multi-user.target

Then:

sudo systemctl enable tgbot
sudo systemctl start tgbot

Monitoring

Check logs in logs/bot.log for:

  • User interactions
  • Error messages
  • Admin actions
  • Spam attempts

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support, contact the development team or create an issue in the repository.

About

A modern Telegram bot built with aiogram 3.x for a clothes shop, featuring admin messaging, spam protection, and comprehensive logging.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors