A sophisticated Telegram bot built with PyroFork that allows owners to forward messages and media between chats with advanced features, comprehensive error handling, and intelligent media group preservation.
- β‘ Fast & Efficient: Built with PyroFork for optimal performance and reliability
- πΎ Persistent Storage: Thread-safe JSON database with automatic backups and corruption recovery
- π― Multiple Chat Support: Forward between any accessible chats (groups, channels, private)
- π Real-time Progress Tracking: Live updates with detailed statistics and processing rates
- π Owner-Only Access: Secure access control with comprehensive permission checks
- π± Smart Media Group Support: Preserves albums and media groups as complete units
- ποΈ Chronological Order: Messages forwarded in correct chronological sequence (oldest first)
- βοΈ Comprehensive Settings Management: View, edit, and reset configuration with chat details
- π Intelligent Batch Processing: Handles large message volumes efficiently with memory optimization
- π‘οΈ Robust Error Handling: Exponential backoff, FloodWait management, and graceful recovery
- π§Ή Automatic Cleanup: Smart cleanup of temporary data and corrupted files with backup system
- ποΈ Intuitive Command System: User-friendly commands with comprehensive validation
- π Detailed Statistics: Track processed, failed, skipped messages and media groups with rates
- π Queue Management: Active operation tracking with stop/resume capabilities
β οΈ Rate Limiting: Built-in delays to prevent API rate limits and account restrictions- π Data Safety: Automatic backups before operations with recovery mechanisms
/start- Start the bot and view welcome message/help- Show available commands and detailed feature list/set_ids(or/set) - Set source and target chat IDs with validation/forward(or/f,/fwd) - Start forwarding with progress tracking/stop- Stop ongoing forward operation gracefully
/settings(or/st) - View current settings with chat details and timestamps/stats- View detailed statistics of current/last forward operation/count(or/cnt) - Show chat history statistics with ETA for forwarding/reset(or/rs) - Reset all settings with 5-second confirmation countdown
Note: All commands are owner-only and work exclusively in private chats for security.
- Python 3.7 or higher
- Telegram API credentials (api_id and api_hash) get them from Telegram App Configuration
-
Clone the repository:
git clone https://github.com/Shadoworbs/pyrofork_forwarder_bot.git && cd pyrofork_forwarder_bot
-
Install required packages:
pip install -r requirements-l.txt
pip install -r requirements-w.txt
-
Create and configure environment variables:
- Rename
environ.envto.env - Add your Telegram API credentials:
API_ID = "your_api_id" API_HASH = "your_api_hash" OWNER_ID = "your telegram ID (not username)"
- Rename
-
First, run the login process:
python login.py
-
Then start the bot:
python forwarder.py
-
Use the provided startup script:
chmod +x start.sh # Make executable (Linux/macOS) ./start.shOn Windows:
bash start.sh
-
Build the Docker image:
docker build -t telegram-forwarder . -
Run the container:
docker run -d --name forwarder-bot -v $(pwd)/user_data:/app/user_data telegram-forwarder -
Set up your forward configuration:
- Use
/set_ids source_id target_idto configure source and target chats - Use
/settingsto verify your configuration - Use
/forwardto start forwarding
- Use
pyrofork_forwarder_bot/
βββ bot/
β βββ __init__.py
β βββ configs.py # Configuration management
β βββ database.py # Thread-safe database operations with backups
β βββ helper.py # Chat validation and utility functions
β βββ settings_manager.py # Settings management
β βββ utils.py # Utility classes (RetryHandler, ForwardStats, etc.)
βββ user_data/ # Database storage directory (auto-created)
βββ forwarder.py # Main bot application
βββ login.py # Telegram authentication script
βββ start.sh # Automated startup script
βββ Dockerfile # Docker configuration
βββ requirements-l.txt # Linux dependencies
βββ requirements-w.txt # Windows dependencies
βββ environ.env # Environment template
βββ README.md # Project documentation
The bot includes a sophisticated database system with:
- Thread-safe Operations: Async locks prevent data corruption
- Automatic Backups: Creates backups before major operations
- Corruption Recovery: Restores from backups if database corruption is detected
- Data Persistence: User settings are preserved across restarts
- Safe Reset: 5-second countdown protection for data deletion
- Chronological Ordering: Two-phase collection and reversal ensures oldest-first forwarding
- Media Group Preservation: Albums forwarded as complete units without splitting
- Batch Processing: Efficient memory usage for large message volumes
- Progress Tracking: Real-time statistics with processing rates and ETA
- Retry Handler: Exponential backoff with configurable maximum attempts
- FloodWait Management: Intelligent delays to respect Telegram rate limits
- Queue Management: Active operation tracking with graceful stop/resume
- Connection Resilience: Automatic reconnection on network interruptions
- Memory Management: Efficient batch processing to handle large chat histories
- Rate Limiting: Built-in delays prevent API restrictions
- Async Operations: Non-blocking database and network operations
- Resource Cleanup: Automatic cleanup of temporary data and handles
The bot includes comprehensive error handling with:
- FloodWait Protection: Exponential backoff for API rate limits
- Invalid Chat ID Handling: Validates and normalizes chat identifiers
- Database Operation Recovery: Automatic backup restoration on corruption
- Message Processing Errors: Graceful handling of failed message operations
- Connection Error Recovery: Automatic reconnection on network issues
- Memory Management: Efficient batch processing to prevent memory overloads
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Never share your
api_idandapi_hash - Keep your
.envfile secure - Don't commit sensitive information to git
- Use
.gitignoreto prevent accidental uploads
For support or inquiries, contact @shadoworbs on Telegram.