Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Multi-User Telegram Auto-Forward Bot

A powerful Telegram bot that automatically forwards messages between channels and groups with advanced filters, caption cleaning, watermarking, and multi-account support.

Deploy on Railway Python 3.10+ License: MIT


✨ Features

πŸš€ Core Features

  • βœ… 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

🎨 Advanced Features

  • βœ‚οΈ 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

πŸ“Š Monitoring & Health

  • πŸ₯ Health check server - HTTP endpoints for monitoring
  • πŸ“ˆ Prometheus metrics - Track forwards, sessions, uptime
  • 🎯 Beautiful dashboard - Visual status page
  • 🚨 Error tracking - Monitor and debug issues

πŸ—οΈ Tech Stack

  • 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

πŸš€ Quick Start

Option 1: Deploy to Railway (Recommended) ⚑

Deploy on Railway

  1. Click the button above
  2. Connect your GitHub account
  3. Fork this repository
  4. Set environment variables in Railway dashboard
  5. Done! Your bot is live πŸŽ‰

πŸ“– Full Railway Deployment Guide β†’

Option 2: Local Development πŸ’»

# 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

Option 3: Docker 🐳

# 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-bot

βš™οΈ Configuration

Required Environment Variables

Get 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...

Optional Configuration

# 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


πŸ“– How to Use

1️⃣ Start the Bot

Open Telegram and search for your bot, then send:

/start

2️⃣ Connect Your Account

  1. Click "πŸ”— Connect Account"
  2. Send your phone number: +1234567890
  3. Enter the verification code from Telegram
  4. Enter 2FA password (if enabled)
  5. βœ… Account connected!

3️⃣ Create Forwarding Rule

  1. Click "βž• Add Rule"

  2. Select your connected account

  3. Enter sources (where messages come FROM):

    -1001234567890, @channel1, @channel2
    
  4. Enter destinations (where messages go TO):

    @mychannel, -1009876543210
    
  5. Choose mode:

    • πŸ“€ Forward - Keep "Forwarded from" header
    • πŸ“‹ Copy - Send as new message (no header)
  6. Configure filters (optional):

    • Ignore specific message types
    • Remove hashtags, links, mentions
    • Add watermarks, buttons, custom captions
  7. βœ… Done! Messages will forward automatically 24/7

4️⃣ Manage Rules

  • πŸ“‹ View Rules - See all your active rules
  • ⏯️ Toggle - Enable/disable rules
  • πŸ”§ Edit - Change sources, destinations, filters
  • πŸ—‘οΈ Delete - Remove rules

🎯 Use Cases

πŸ“’ Content Aggregation

Forward from multiple news channels β†’ your single news channel

πŸ”„ Content Redistribution

Copy competitor content β†’ your channel (with watermark & cleaned captions)

🎨 Brand Protection

Add watermark to all forwarded media automatically

πŸ“Š Multi-Channel Management

Manage multiple Telegram accounts from one bot

🚫 Content Filtering

Forward only specific message types (photos only, videos only, etc.)

πŸ”— Cross-Promotion

Add custom buttons to all forwarded messages


πŸ“Š Health Monitoring

The bot includes a built-in health check server for monitoring:

Endpoints

# 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

Metrics Tracked

  • ⏱️ 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

Dashboard Preview

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
πŸ€– Telegram Bot Status
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Status: HEALTHY βœ…

Uptime: 2d 14h 32m
Active Sessions: 3
Total Forwards: 15,234

Database: βœ…
Telegram: βœ…
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

πŸ—‚οΈ Project Structure

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)

πŸ”’ Security

Best Practices

βœ… 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

What Gets Stored

  • βœ… 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

πŸ› Troubleshooting

Bot Not Starting

# Check logs
python main.py

# Verify environment variables
cat .env

# Test health endpoint
curl http://localhost:8080/health

Sessions Lost on Deploy

Use persistent storage (Railway Volumes):

# Railway Dashboard β†’ Settings β†’ Volumes
Mount Path: /app/user_sessions

Database Resets

Enable persistent storage:

# Railway Dashboard β†’ Settings β†’ Volumes
Mount Path: /app/data

# Update environment
DATABASE_FILE=data/autoforward.db

FFmpeg Not Found

Install FFmpeg for watermarking:

# Ubuntu/Debian
apt-get install ffmpeg

# macOS
brew install ffmpeg

# Docker (already included in Dockerfile)

πŸ“š Documentation


🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

# 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

Contribution Guidelines

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

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


πŸ™ Acknowledgments


πŸ’¬ Support

  • πŸ› Bug reports - Open an issue
  • πŸ’‘ Feature requests - Open an issue
  • πŸ“§ Questions - Open a discussion
  • ⭐ Star this repo - If you find it useful!

⚑ Quick Links


🎯 Roadmap

  • 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!

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages