A Python-based tool that automatically forwards messages between Telegram chats and topics using your personal account credentials.
- User Account Authentication: Operates under your Telegram user credentials (not a bot)
- Flexible Forwarding Rules: Configure forwarding by chat or specific topics
- Topic Support: Full support for Telegram topics in both source and destination chats
- User Filtering: Forward messages only from specific users
- Reply Content Forwarding: Includes the original message content when forwarding replies
- Message Link Processing: Automatically includes content from any Telegram message links in the text
- Media Handling: Properly forwards media attachments from both original messages and linked content
- MTProto Proxy Support: Connect through MTProto proxy for enhanced privacy/accessibility
- Source Attribution: Automatically includes source chat/topic information in forwarded messages
- Performance Optimized: Caches chat entities and topic information for faster operation
- Detailed Logging: Comprehensive logging for monitoring and troubleshooting
- Docker Support: Easy deployment with Docker and Docker Compose
- Auto-restart Capability: Both Docker and WSL scripts ensure the forwarder stays running
- Python 3.11
- Telegram account
- Telegram API credentials (API ID and API Hash)
-
Clone this repository:
git clone git@github.com:DimaPhil/telegram_forwarder.git cd telegram-forwarder -
Install the required dependencies:
pip install -r requirements.txt
-
Configure
config.jsonandforwarding_rules.jsonwith your implied data (more about that below) -
Run the setup wizard:
python main.py
-
Clone this repository:
git clone git@github.com:DimaPhil/telegram_forwarder.git cd telegram-forwarder -
Create your configuration files (
config.jsonandforwarding_rules.json) or run the setup wizard first:python main.py --setup
-
Build and start with Docker Compose:
docker compose up -d
-
Clone this repository:
git clone git@github.com:DimaPhil/telegram_forwarder.git cd telegram-forwarder -
Install the required dependencies:
pip install -r requirements.txt
-
Run the setup wizard and then configure
config.jsonandforwarding_rules.json:python main.py --setup
-
Make the WSL script executable:
chmod +x run_wsl.sh
-
Run the WSL script:
./run_wsl.sh
The forwarder requires two configuration files:
Contains your Telegram API credentials and proxy settings:
{
"api_id": 123456,
"api_hash": "your_api_hash_here",
"proxy": {
"type": "",
"server": "",
"port": 0
}
}"proxy" can be left unconfigured if not needed.
Defines which messages should be forwarded and where:
{
"-100123456789": {
"*": [
{
"chat_id": "-100987654321",
"topic_id": null
}
]
},
"-100111222333": {
"1": [
{
"chat_id": "-100444555666",
"topic_id": 123,
"user_ids": [12345678, 87654321]
}
],
"2": [
{
"chat_id": "-100777888999",
"topic_id": null
}
],
"3": [
{
"chat_id": "@username",
"topic_id": null
}
]
}
}In this example:
- All messages from chat
-100123456789will be forwarded to chat-100987654321 - Messages from topic
1in chat-100111222333will be forwarded to topic123in chat-100444555666, but only if sent by users with IDs12345678or87654321 - Messages from topic
2in chat-100111222333will be forwarded to chat-100777888999(no specific topic) - Messages from topic
3in chat-100111222333will be forwarded to@username(no specific topic)
python main.pyCommand-line options:
--setup: Run the interactive setup wizard--config PATH: Specify a custom config file path (default:config.json)--rules PATH: Specify a custom rules file path (default:forwarding_rules.json)--session PATH: Specify a custom session file path (default:telegram_session)--log-level LEVEL: Set logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Start the forwarder:
docker compose up -dStop the forwarder:
docker compose downView logs:
docker compose logs -fStart the forwarder with auto-restart capability:
./run_wsl.shStop the forwarder:
./stop_wsl.shLogs are stored in the logs directory:
telegram_forwarder.log: Main application logswsl_runner.log: WSL runner logs (when using the WSL script)
When using Docker, logs are also stored in the logs directory on your host system, thanks to the volume mapping in the Docker Compose file.
- Visit https://my.telegram.org and log in
- Go to "API development tools"
- Create a new application
- Note down your API ID and API Hash
Edit the forwarding_rules.json file to specify your forwarding rules:
- Use
"*"to forward all messages from a chat - Specify topic IDs to forward only specific topics
- Add
user_idsarray to filter by specific users
Finding Chat IDs:
- Forward a message from the chat to @userinfobot
- For supergroups and channels, the ID format is
-100xxxxxxxxxx
Finding Topic IDs:
- Open the topic in a web browser
- The topic ID is the number at the end of the URL (after "/topic/")
Finding User IDs:
- Forward a message from the user to @userinfobot
- The user ID will be displayed
Choose one of the running methods described above. When run for the first time, you'll be prompted to enter your phone number and verification code to authenticate with Telegram.
The forwarder provides several debug commands when you message the bot privately:
/debugtopic- Show topic information for your message/debugchat -100xxxx- Show information about a specific chat/debuglinks- Test message link extraction from your message/help- Show all available commands
- The script uses your Telegram user account credentials
- Keep your
config.jsonfile secure as it contains sensitive information - Consider restricting file permissions:
chmod 600 config.json
This tool is for personal use only. It uses your user account, not a bot account. Please ensure your usage complies with Telegram's Terms of Service.