A powerful Telegram bot that automatically forwards messages between channels and groups with advanced filters, caption cleaning, watermarking, and multi-account support.
- β Multiple source β destination rules - Forward from many to many
- β Telethon (MTProto) - Forward files up to 2GB+
- β Copy mode & Forward mode - Choose how to send messages
- β Album handling - Keep grouped media together
- β Duplicate prevention - Skip already forwarded files
- β Multi-account support - Connect multiple Telegram accounts
- β Per-user rules - Each user has isolated rules
- βοΈ Caption cleaning - Remove hashtags, links, emojis, mentions, phones, emails
- π« Message filters - Ignore specific message types (video, photo, sticker, etc.)
- π Text watermark - Add custom text to images and videos
- πΌοΈ Logo watermark - Add logo/image watermark with transparency
- π¬ Custom captions - Replace captions with formatted text
- π Word replacement - Replace words/phrases in captions
- π Header/Footer - Add custom text at beginning/end
- π Link buttons - Add custom inline buttons
- β±οΈ Delay forwarding - Schedule message forwarding
- π History forwarding - Forward past messages when creating rule
- π Spoiler effect - Apply blur effect to photos/videos
- ποΈ Block/Whitelist words - Filter messages by content
- π₯ Health check server - HTTP endpoints for monitoring
- π Prometheus metrics - Track forwards, sessions, uptime
- π― Beautiful dashboard - Visual status page
- π¨ Error tracking - Monitor and debug issues
- Python 3.10+
- python-telegram-bot - Bot UI and commands
- Telethon - MTProto for large file forwarding
- SQLite - Local database
- FFmpeg - Media processing (watermarks)
- Pillow - Image manipulation
- Click the button above
- Connect your GitHub account
- Fork this repository
- Set environment variables in Railway dashboard
- Done! Your bot is live π
π Full Railway Deployment Guide β
# 1. Clone repository
git clone https://github.com/YOUR-USERNAME/telegram-autoforward-bot.git
cd telegram-autoforward-bot
# 2. Install dependencies
pip install -r requirements.txt
# 3. Copy environment template
cp .env.example .env
# 4. Edit .env with your credentials
nano .env
# 5. Run the bot
python main.py# 1. Build image
docker build -t telegram-bot .
# 2. Run container
docker run -d \
--name telegram-bot \
-e TELEGRAM_API_ID=your_api_id \
-e TELEGRAM_API_HASH=your_api_hash \
-e TELEGRAM_BOT_TOKEN=your_bot_token \
-v $(pwd)/data:/app/data \
-p 8080:8080 \
telegram-botGet these credentials before starting:
# Get from https://my.telegram.org/apps
TELEGRAM_API_ID=12345678
TELEGRAM_API_HASH=abc123def456...
# Get from @BotFather on Telegram
TELEGRAM_BOT_TOKEN=1234567890:ABC-DEF...# Admin user ID (optional)
ADMIN_USER_ID=123456789
# Storage paths
SESSION_DIR=user_sessions
DATABASE_FILE=autoforward.db
# Limits
MAX_RULES_PER_USER=50
MAX_ACCOUNTS_PER_USER=10
# Health check server port
HEALTH_PORT=8080π See .env.example for full configuration
Open Telegram and search for your bot, then send:
/start
- Click "π Connect Account"
- Send your phone number:
+1234567890 - Enter the verification code from Telegram
- Enter 2FA password (if enabled)
- β Account connected!
-
Click "β Add Rule"
-
Select your connected account
-
Enter sources (where messages come FROM):
-1001234567890, @channel1, @channel2 -
Enter destinations (where messages go TO):
@mychannel, -1009876543210 -
Choose mode:
- π€ Forward - Keep "Forwarded from" header
- π Copy - Send as new message (no header)
-
Configure filters (optional):
- Ignore specific message types
- Remove hashtags, links, mentions
- Add watermarks, buttons, custom captions
-
β Done! Messages will forward automatically 24/7
- π View Rules - See all your active rules
- β―οΈ Toggle - Enable/disable rules
- π§ Edit - Change sources, destinations, filters
- ποΈ Delete - Remove rules
Forward from multiple news channels β your single news channel
Copy competitor content β your channel (with watermark & cleaned captions)
Add watermark to all forwarded media automatically
Manage multiple Telegram accounts from one bot
Forward only specific message types (photos only, videos only, etc.)
Add custom buttons to all forwarded messages
The bot includes a built-in health check server for monitoring:
# Dashboard (HTML)
http://localhost:8080/
# Liveness check (always returns 200 if running)
http://localhost:8080/health
# Readiness check (200 if ready, 503 if not)
http://localhost:8080/ready
# Prometheus metrics
http://localhost:8080/metrics- β±οΈ Uptime - How long bot has been running
- π± Active Sessions - Number of connected accounts
- π¨ Total Forwards - Cumulative message count
- πΎ Database Health - SQLite connection status
- π‘ Telegram Health - API connection status
- π Last Error - Most recent error with timestamp
ββββββββββββββββββββββββββββββββ
π€ Telegram Bot Status
ββββββββββββββββββββββββββββββββ
Status: HEALTHY β
Uptime: 2d 14h 32m
Active Sessions: 3
Total Forwards: 15,234
Database: β
Telegram: β
ββββββββββββββββββββββββββββββββ
telegram-autoforward-bot/
βββ main.py # Main bot application
βββ health_server.py # HTTP health check server
βββ requirements.txt # Python dependencies
βββ Dockerfile # Container configuration
βββ railway.toml # Railway platform config
βββ .env.example # Environment template
βββ .gitignore # Git ignore rules
βββ README.md # This file
βββ RAILWAY_DEPLOYMENT.md # Deployment guide
βββ LICENSE # MIT License
βββ user_sessions/ # Telegram session files (gitignored)
β
Never commit .env - Always in .gitignore
β
Use environment variables - For all secrets
β
Rotate credentials - Change tokens every 3-6 months
β
Monitor access - Check logs regularly
β
Enable 2FA - On your Telegram account
β
Use Railway's secrets - Encrypted at rest
- β Session files - Encrypted Telegram sessions
- β Database - Forward rules and user data
- β Temporary files - Downloaded media (auto-cleaned)
- β Passwords - Never stored
- β Bot token - Only in environment variables
# Check logs
python main.py
# Verify environment variables
cat .env
# Test health endpoint
curl http://localhost:8080/healthUse persistent storage (Railway Volumes):
# Railway Dashboard β Settings β Volumes
Mount Path: /app/user_sessionsEnable persistent storage:
# Railway Dashboard β Settings β Volumes
Mount Path: /app/data
# Update environment
DATABASE_FILE=data/autoforward.dbInstall FFmpeg for watermarking:
# Ubuntu/Debian
apt-get install ffmpeg
# macOS
brew install ffmpeg
# Docker (already included in Dockerfile)- π Railway Deployment Guide
- π€ Telegram Bot API
- π‘ Telethon Docs
- π python-telegram-bot
Contributions are welcome! Please feel free to submit a Pull Request.
# 1. Fork and clone
git clone https://github.com/YOUR-USERNAME/telegram-autoforward-bot.git
# 2. Create virtual environment
python -m venv venv
source venv/bin/activate # or `venv\Scripts\activate` on Windows
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure environment
cp .env.example .env
nano .env
# 5. Run locally
python main.py- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Telegram - Messaging platform
- Telethon - Telegram MTProto library
- python-telegram-bot - Bot framework
- Railway - Deployment platform
- π Bug reports - Open an issue
- π‘ Feature requests - Open an issue
- π§ Questions - Open a discussion
- β Star this repo - If you find it useful!
- π Deploy to Railway
- π Deployment Guide
- π§ Configuration
- π Health Dashboard
- π€ Create Bot
- π Get API Credentials
- Web dashboard for rule management
- Multi-language support
- Advanced scheduling (cron-like)
- Media conversion (video β GIF, etc.)
- Statistics and analytics
- Webhook support
- Message templates
- Auto-reply functionality
Made with β€οΈ for the Telegram community
Star β this repo if you find it useful!