A comprehensive Telegram bot administration system with MongoDB support, featuring a GUI admin panel for managing users and sending bulk/personalized messages.
- ๐ค Telegram Bot Integration: Automatic user registration and welcome messages
- ๐พ MongoDB Database: Flexible NoSQL database with connection string support
- ๐ฅ๏ธ Admin GUI: Modern CustomTkinter-based interface for managing users
- ๐ค Bulk Messaging: Send messages to multiple users at once
- ๐ Template Messages: Use placeholders like
{name}and{chat_id}in messages - ๐ Excel Import/Export: Import personalized messages from Excel, export user lists
- ๐ Search & Filter: Easily find users by name or chat ID
- ๐ Environment Variables: Secure configuration using .env files
telebot/
โโโ main.py # Application entry point
โโโ config.py # Configuration and environment variables
โโโ database.py # MongoDB database operations
โโโ bot_handler.py # Telegram bot handlers and messaging
โโโ gui.py # Admin GUI interface
โโโ requirements.txt # Python dependencies
โโโ .env.example # Example environment configuration
โโโ .env # Your actual configuration (create this)
โโโ README.md # This file
- Python 3.8 or higher
- MongoDB (local installation or MongoDB Atlas account)
- Telegram Bot Token (from @BotFather)
cd c:\Users\ahmed\Desktop\telebot\telebotpip install -r requirements.txtCopy the example environment file:
copy .env.example .envEdit .env file with your settings:
# Your Telegram Bot Token
TELEGRAM_TOKEN=your_bot_token_here
# MongoDB Connection String
# For local MongoDB:
MONGODB_URI=mongodb://localhost:27017/
# For MongoDB Atlas (cloud):
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/?retryWrites=true&w=majority
# Database Name
DATABASE_NAME=telegram_bot
# Application Settings
SEND_DELAY=0.5
WELCOME_MESSAGE=ุงููุง ุจูู ูู ูุธุงู
ุงูู
ุชุงุจุนุฉ ูู
ุณุชุฑ ุดุงุฏู ุงูุดุฑูุงูู ุดูุฑุง ุนูู ุซูุชู ุจูุชู
ูู ูููู ุนูุฏ ุญุณู ุธูู- Install MongoDB Community Edition from mongodb.com
- Start MongoDB service
- Use connection string:
mongodb://localhost:27017/
- Create free account at mongodb.com/cloud/atlas
- Create a cluster
- Get your connection string from "Connect" โ "Connect your application"
- Replace
<password>with your database user password - Use the connection string in your
.envfile
Example Atlas connection string:
mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority
python main.pyThis will:
- Connect to MongoDB
- Start the Telegram bot in the background
- Launch the admin GUI
- Search: Type in the search box to filter users by name or chat ID
- Refresh: Update the user list from the database
- Select All/Deselect All: Quickly select or deselect all users
- Delete: Remove users from the database
-
Template Messages to Selected Users:
- Select users using checkboxes
- Enter a message template (use
{name}or{chat_id}as placeholders) - Click "Send to Selected"
-
Personalized Messages from Excel:
- Prepare an Excel file with:
- Column A: Target (chat_id or name)
- Column B: Message text
- Click "Load Excel (A=target, B=message)"
- Click "Send Imported Rows"
- Prepare an Excel file with:
- Click "Export users"
- Choose CSV or Excel format
- Save the file
Create an Excel file with this structure:
| A (target) | B (message) |
|---|---|
| 123456789 | Hello User 1! |
| John | Hi John, this is your message |
| 987654321 | Custom message for this user |
- Column A: Can be either chat_id (numeric) or user name (text)
- Column B: The message to send to that user
Users can interact with your bot using:
/start- Register and receive welcome message- Any message - Will trigger registration and welcome message
All configuration is in config.py and can be overridden with environment variables:
| Variable | Description | Default |
|---|---|---|
TELEGRAM_TOKEN |
Your bot token from BotFather | Required |
MONGODB_URI |
MongoDB connection string | mongodb://localhost:27017/ |
DATABASE_NAME |
Database name | telegram_bot |
SEND_DELAY |
Delay between messages (seconds) | 0.5 |
WELCOME_MESSAGE |
Message sent to new users | Arabic welcome message |
LOG_FILE |
Log file path | app.log |
LOG_LEVEL |
Logging level | INFO |
All application activity is logged to app.log including:
- User registrations
- Message sending (success/failure)
- Database operations
- Errors and exceptions
If you're migrating from the old bot.py with SQLite:
- The old
users.dbSQLite file is no longer used - Users will need to re-register with the bot (send
/start) - Alternatively, you can write a migration script to transfer data from SQLite to MongoDB
- Check your
TELEGRAM_TOKENin.env - Verify internet connection
- Check
app.logfor errors
- Verify MongoDB is running (for local setup)
- Check
MONGODB_URIconnection string - For Atlas: Verify IP whitelist and credentials
- Ensure all dependencies are installed:
pip install -r requirements.txt - Check if CustomTkinter is properly installed
- Check
app.logfor specific errors - Verify users have started the bot (sent
/start) - Ensure
SEND_DELAYis not too low (minimum 0.5 recommended)
- Never commit
.envfile to version control - Keep your bot token secret - regenerate if exposed
- Use strong passwords for MongoDB Atlas
- Whitelist specific IPs in MongoDB Atlas (not 0.0.0.0/0)
- Regularly backup your MongoDB database
This project is provided as-is for educational and personal use.
For issues or questions:
- Check the logs in
app.log - Review this README
- Verify your configuration in
.env
Made with โค๏ธ for Mr. Shady's Telegram Administration System