A comprehensive Telegram bot system that automatically forwards and organizes media content from multiple groups/channels to a centralized backup supergroup. The bot creates organized topics for each source and provides a web-based dashboard for monitoring and configuration.
- Monitors multiple Telegram groups and channels
- Forwards all media types (photos, videos, documents, audio, voice notes, stickers, animations)
- Removes "forwarded from" attribution for cleaner organization
- Adds source identification to each forwarded media
- Automatically creates topics in the backup supergroup for each source
- Groups media by source channel/group name
- Advanced duplicate detection prevents duplicate topics
- Unicode normalization handles emojis and special characters
- Real-time monitoring and statistics
- Bot control (start/stop/restart)
- Configuration management
- Activity logs and analytics
- System performance monitoring
- One-click setup with
start.py - Automatic dependency installation
- Persistent configuration storage
- User-friendly web interface for settings
- Python 3.11 or higher
- A Telegram account
- Basic computer knowledge
Simply run the start.py file and everything will be configured automatically:
python start.pyThat's it! The script will:
- β Check and install all required dependencies
- β Guide you through bot token configuration
- β Help you set up the backup group
- β Start the bot automatically
- β Open the web dashboard
If you prefer manual setup:
# Install dependencies
pip install pyTelegramBotAPI python-dotenv streamlit plotly pandas psutil
# Set environment variables
export BOT_TOKEN="your_bot_token_here"
export BACKUP_GROUP_ID="your_group_id_here"
# Run the bot
python bot/telegram_bot.py
# In another terminal, run the dashboard
streamlit run app.py --server.port 5000- Open Telegram and search for
@BotFather - Start a conversation with BotFather by sending
/start - Create a new bot by sending
/newbot - Choose a name for your bot (e.g., "My Media Backup Bot")
- Choose a username for your bot (must end with 'bot', e.g., "my_media_backup_bot")
- Copy the bot token - it looks like:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz - Save this token - you'll need it during setup
- Create a new group in Telegram
- Add at least one other member (you can remove them later)
- Convert to supergroup:
- Go to group settings
- Tap "Group Type"
- Select "Public Group" then change back to "Private Group"
- Enable Topics:
- Go to group settings
- Tap "Topics"
- Enable "Topics"
- Add your bot to the group:
- Add the bot using its username (e.g., @my_media_backup_bot)
- Make the bot an Administrator
- Give it "Manage Topics" permission
Method 1: Using @userinfobot (Recommended)
- Add @userinfobot to your backup supergroup
- The bot will automatically send the group ID (looks like
-1001234567890) - Copy this ID - you'll need it during setup
- Remove @userinfobot from the group
Method 2: Using Bot API
- Add your bot to the group first
- Send a message in the group
- Visit:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Look for the chat object with "type": "supergroup"
- Copy the negative ID from the "id" field
Execute the start.py script:
python start.pyThe script will ask for:
- Bot Token: Paste the token from BotFather
- Group ID: Paste the negative ID from your supergroup
The web dashboard is accessible at http://localhost:5000 and provides:
- Total messages processed
- Active topics count
- Today's activity
- Source groups statistics
- Daily activity charts (last 7 days)
- Hourly activity patterns (last 24 hours)
- Media type distribution
- Source group performance
- List of all created topics
- Thread IDs and media counts
- Topic management interface
- Real-time activity feed
- Recent media forwards
- Success/failure status
- Source and media type details
- Bot token management
- Backup group ID settings
- Bot control (start/stop/restart)
- System status monitoring
Create a .env file or set these environment variables:
BOT_TOKEN=your_bot_token_here
BACKUP_GROUP_ID=your_group_id_hereTo ignore specific groups/channels, edit bot/telegram_bot.py:
# Add chat IDs to ignore
IGNORED_CHAT_IDS = [-1001234567890, -1009876543210]π Your Project/
βββ π start.py # Easy setup script
βββ π app.py # Streamlit dashboard
βββ π config.json # Bot configuration
βββ π bot/
β βββ π telegram_bot.py # Main bot script
β βββ π topics.json # Topic mappings
β βββ π stats.json # Statistics data
β βββ π activity_logs.json # Activity logs
βββ π utils/
βββ π analytics.py # Analytics engine
βββ π bot_monitor.py # Bot monitoring
βββ π config_manager.py # Configuration management
βββ π duplicate_detector.py # Duplicate detection
The bot monitors all groups and channels it's added to and automatically detects:
- πΈ Photos
- π₯ Videos
- π Documents
- π΅ Audio files
- π€ Voice messages
- π¬ Video notes
- π Stickers
- ποΈ Animations/GIFs
When media is detected from a new source:
- Normalizes the group/channel name (removes emojis, special characters)
- Checks for duplicates using advanced similarity detection
- Creates a new topic in the backup supergroup if no duplicate found
- Saves the mapping between source name and topic thread ID
For each media item:
- Downloads the original media
- Re-uploads to remove "forwarded from" label
- Adds source caption indicating the original group/channel
- Posts to appropriate topic in the backup supergroup
- Logs the activity for dashboard analytics
β "BOT_TOKEN not set" Error
- Make sure you ran
start.pyand entered a valid bot token - Check that the token was saved correctly in
config.json - Verify the token format: should be numbers:letters (e.g.,
123456789:ABCdef...)
β "Group ID not found" Error
- Ensure the group ID is negative (supergroups always have negative IDs)
- Verify your bot is an administrator in the backup group
- Check that "Topics" are enabled in the group settings
β "Permission denied" Error
- Make sure your bot has "Manage Topics" permission
- Verify your bot is an administrator, not just a member
- Try removing and re-adding the bot with proper permissions
β Bot not responding to media
- Check that the bot is running (
python start.py) - Verify the source groups aren't in the IGNORED_CHAT_IDS list
- Ensure the bot has permission to read messages in source groups
β Dashboard not loading
- Make sure port 5000 is not being used by another application
- Try accessing
http://localhost:8000for the basic monitor - Check console logs for error messages
Check Bot Status
# In Telegram, send to your bot:
/start
/statusCheck Logs
# View real-time logs while bot runs:
python bot/telegram_bot.pyTest Configuration
# Verify your configuration:
python -c "import json; print(json.load(open('config.json')))"Reset Configuration
# Delete config and start fresh:
rm config.json
python start.py- Real-time metrics on media processing
- Historical data with charts and graphs
- Source performance analytics
- Media type breakdown
- Unicode normalization for international characters
- Fuzzy matching for similar group names
- Configurable similarity threshold
- Manual override capabilities
- Automatic bot restart on crashes
- Memory and CPU monitoring
- Uptime tracking
- Health checks
- Check this README for common solutions
- Review the troubleshooting section above
- Check the dashboard logs for specific error messages
- Verify your configuration using the dashboard
- Regular backups of your
config.jsonandbot/topics.jsonfiles - Monitor disk space if processing large media files
- Keep bot token secure - never share it publicly
- Use strong permissions on your backup supergroup
- Python 3.11+ (recommended)
- 2GB RAM minimum (more for heavy usage)
- Stable internet connection
- Available ports 5000 and 8000
The start.py script automatically installs:
pyTelegramBotAPI- Telegram Bot API wrapperpython-dotenv- Environment variable managementstreamlit- Web dashboard frameworkplotly- Interactive charts and graphspandas- Data manipulation and analysispsutil- System monitoring
- Keep your bot token secret - never commit it to version control
- Use environment variables or the secure config system
- Regularly update dependencies for security patches
- Monitor bot permissions in all connected groups
- Review activity logs for unusual behavior
Once everything is configured:
- The bot runs automatically and monitors all connected groups
- Media is forwarded and organized by topic
- Dashboard shows real-time stats at
http://localhost:5000 - Configuration can be changed through the web interface
- Everything is logged for monitoring and troubleshooting
Enjoy your organized media backup system! π
Like it? Want to support the developer?
π Buy me a Coffee
Creator & Maintainer: Matheus Delagostini
Code Partner: IA Assistant β Helped debug, structure, optimize, and make everything 100% functional.
"Without him, this bot wouldn't be here today!"
π Made with β€οΈ and lots of beer. Share, contribute, and have fun!
Use, modify, and share freely! Just remember to give me the credits!
Need help? Check the troubleshooting section above or review the configuration in your web dashboard.