A powerful, feature-rich Telegram forwarding bot with real-time synchronization to Bale Messenger and Eitaa, featuring automatic translation and intelligent media handling.
- Instant forwarding from Telegram channels/groups to Bale Messenger and Eitaa
- Support for multiple source channels and destination chats
- Configurable polling intervals for optimal performance
- Dual platform support: Forward to both Bale and Eitaa simultaneously
- Automatic translation using Google Translate
- Per-chat language configuration
- Preserves original formatting and structure
- Photos: Single images and photo albums
- Videos: All video formats with streaming support
- Documents: Files, PDFs, and other document types
- Audio: Music files and voice messages
- Media Groups: Intelligent album handling with proper grouping
- Edit Detection: Automatically updates forwarded messages when originals are edited
- Delete Synchronization: Removes forwarded messages when originals are deleted
- Duplicate Prevention: Smart filtering to avoid message duplication
- Album Processing: Handles media groups as cohesive units
- Retry Mechanism: Exponential backoff with configurable limits
- Error Recovery: Graceful handling of network issues and API limits
- Database Persistence: SQLite-based message mapping for reliability
- Memory Management: Automatic cleanup of old media files
- Concurrent Processing: Async/await for optimal performance
- Docker containerization with multi-stage builds
- Docker Compose for easy orchestration
- Environment-based configuration
- Timezone support
- Python 3.9 or higher
- Telegram API credentials (Get them here)
- Bale Bot token (Create a bot) - Optional
- Eitaa Bot token (Get from eitaayar.ir) - Optional
Note: You need at least one messaging platform (Bale or Eitaa) configured.
-
Clone the repository
git clone https://github.com/tje3d/Telesync.git cd Telesync -
Install dependencies
pip install -r requirements.txt
-
Configure environment
cp .env.example .env # Edit .env with your credentials -
Run the application
python main.py
# Using Docker Compose (Recommended)
docker-compose up -d
# Or using Docker directly
docker build -t Telesync .
docker run -d --name telegram-forwarder TelesyncCreate a .env file based on .env.example:
# Telegram API Configuration
API_ID=your_api_id_here
API_HASH=your_api_hash_here
SESSION_STRING=your_session_string_here
SOURCES=@channel1,@channel2,@group1
# Bale Messenger Configuration (Optional)
BALE_TOKEN=your_bale_bot_token
BALE_CHAT_IDS=chat_id1,chat_id2:en,chat_id3:fa
# Eitaa Messenger Configuration (Optional)
EITAA_TOKEN=your_eitaa_bot_token
EITAA_CHAT_IDS=chat_id1,chat_id2:en,chat_id3:fa
# Performance Tuning
POLL_INTERVAL=5 # Polling frequency (seconds)
EDIT_DELETE_CHECK_INTERVAL=30 # Edit/delete check frequency (seconds)Both BALE_CHAT_IDS and EITAA_CHAT_IDS support per-chat language settings:
chat_id1- No translation (original language)chat_id2:en- Translate to Englishchat_id3:fa- Translate to Persian/Farsi
Supported Languages: Any language code supported by Google Translate (en, fa, ar, fr, de, es, etc.)
| Feature | Bale | Eitaa |
|---|---|---|
| Message Editing | β Supported | β Not supported |
| Message Deletion | β Supported | β Not supported |
| Media Groups | β Supported | β Sends individually |
| File Types | All types | All types |
| Translation | β Supported | β Supported |
Specify Telegram sources in SOURCES:
@channel_username- Public channels@group_username- Public groups-1001234567890- Private channels/groups (use chat ID)
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Telegram βββββΆβ Telesync βββββΆβ Bale β
β Channels β β β β Messenger β
β Groups β β βββββββββββββββ β β Chats β
βββββββββββββββββββ β β Message β β βββββββββββββββββββ
β β Processor β β
β βββββββββββββββ β
β βββββββββββββββ β
β β Media β β
β β Handler β β
β βββββββββββββββ β
β βββββββββββββββ β
β β Translation β β
β β Engine β β
β βββββββββββββββ β
β βββββββββββββββ β
β β Database β β
β β Manager β β
β βββββββββββββββ β
ββββββββββββββββββββ
SQLite database stores message mappings for edit/delete synchronization:
CREATE TABLE messages (
telegram_id INTEGER,
bale_chat_id TEXT,
bale_ids TEXT, -- JSON array of Bale message IDs
is_album BOOLEAN, -- Whether message is part of media group
first_message BOOLEAN, -- First message in album (has caption)
content_hash TEXT, -- Hash for edit detection
last_check TIMESTAMP, -- Last edit/delete check
chat_id INTEGER, -- Source Telegram chat ID
PRIMARY KEY (telegram_id, bale_chat_id)
);- Exponential Backoff: Intelligent retry with increasing delays
- Maximum Retry Time: 5 minutes total retry duration
- Jitter: Random delay variation to prevent thundering herd
- Server Error Handling: Automatic retry on 5xx HTTP errors
- Automatic Cleanup: Removes media files older than 12 hours
- Progress Tracking: Real-time download progress indicators
- Type Detection: Intelligent media type classification
- Album Preservation: Maintains media group integrity
- Async Processing: Non-blocking I/O operations
- Connection Pooling: Efficient HTTP session management
- Memory Management: Automatic cleanup of processed messages
- Batch Operations: Efficient database transactions
The application provides comprehensive logging with color-coded output:
- π΅ Info: General operation status
- π’ Success: Successful operations
- π‘ Warning: Non-critical issues
- π΄ Error: Critical errors requiring attention
2024-01-15 10:30:45 - INFO - π Starting monitoring...
2024-01-15 10:30:46 - INFO - π© New message [ID: 12345] in Channel Name (123456789)
2024-01-15 10:30:47 - INFO - β
Text forwarded to Bale chat 987654321
2024-01-15 10:30:48 - INFO - βοΈ Detected edit in message 12345
2024-01-15 10:30:49 - INFO - ποΈ Detected deletion of message 12346
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- 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.
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed information
- Include logs and configuration (remove sensitive data)
- Telethon - Telegram client library
- aiohttp - Async HTTP client/server
- Google Translate - Translation service
- Bale Messenger - Iranian messaging platform
- Eitaa Messenger - Iranian messaging platform
The Eitaa integration is based on the official Eitaayar API. Key features:
- Base URL:
https://eitaayar.ir/api/{TOKEN}/{METHOD} - Supported Methods:
getMe,sendMessage,sendFile - File Support: All media types via
sendFilemethod - Limitations: No message editing, deletion, or media groups
For complete API documentation, see doc/eitaa.md.