A modern Telegram bot built with aiogram 3.x for a clothes shop, featuring admin messaging, spam protection, and comprehensive logging.
- 🎯 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
- Python 3.14+
- Poetry (for dependency management)
- Telegram Bot Token from @BotFather
-
Clone the repository:
git clone <your-repo-url> cd TgBot
-
Install dependencies:
poetry install
-
Configure environment:
cp .env.example .env # Edit .env with your values -
Run the bot:
poetry run python main.py
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- Bot Token: Get from @BotFather
- Group ID: Add @userinfobot to your group and get the ID
/start- Welcome message with menuMenu- Browse brands (links to external sites)Contacts- Get contact informationinfo- Unlock messaging to admins (30-minute session)- Send messages/photos after clicking "info"
- Reply to forwarded messages in the admin group
- Messages are automatically forwarded back to users
- Original messages are deleted after successful reply
├── 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)
- Token Protection: Sensitive data in
.envfile - Spam Protection: Session-based messaging approval
- Input Validation: User ID and message validation
- Error Handling: Comprehensive exception handling
- Logging: All actions logged with rotation
- Add handlers in
handlers.py - Update keyboards in
keyboards.pyif needed - Test thoroughly before deployment
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
# Build image
docker build -t tgbot .
# Run container
docker run -d --env-file .env tgbotCreate /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.targetThen:
sudo systemctl enable tgbot
sudo systemctl start tgbotCheck logs in logs/bot.log for:
- User interactions
- Error messages
- Admin actions
- Spam attempts
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, contact the development team or create an issue in the repository.