App that aggregates posts from multiple Telegram channels into a single target channel. Built with Telethon library and managed through Saved Messages. The main idea is to implement a news feed like in other social networks.
If you find this project helpful, please consider giving it a star ⭐ It helps others discover the project and motivates further development.
- Combines posts from multiple channels into one
- Preserves media album structure
- Management through Saved Messages
- Concurrent post processing
- Persistent settings between restarts
- Independent session management
- Python 3.7+
- Telegram account
- Telegram API keys (get at https://my.telegram.org/apps)
- Clone and install dependencies:
git clone https://github.com/AlestackOverglow/telegram-aggregator.git
cd telegram-aggregator
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
pip install -r requirements.txt
- Create
.env
file:
API_ID=your_api_id
API_HASH=your_api_hash
PHONE_NUMBER=+1234567890
- Run the bot:
python main.py
- First launch:
- Enter Telegram verification code
- Enter 2FA password (if enabled)
⚠️ IMPORTANT: Send/start
to Saved Messages to begin aggregation, you only need to use this command every time you restart the bot, the rest of the settings are saved- Set target channel using
/set_target
command - Add at least one source channel
/add_channel <channel>
or all/add_all_channels
- The bot will not aggregate any messages until these steps are completed.
Linux/Mac:
source venv/bin/activate && nohup python main.py > output.log 2>&1 &
Windows:
- Create
run_bot.bat
:
@echo off
call venv\Scripts\activate
python main.py
pause
- Run the batch file
Linux Autostart with systemd:
[Unit]
Description=Telegram Channel Aggregator Bot
After=network.target
[Service]
Type=simple
User=YOUR_USERNAME
WorkingDirectory=/path/to/bot
Environment=PYTHONUNBUFFERED=1
ExecStart=/path/to/bot/venv/bin/python main.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
All commands are sent to Saved Messages:
/start
- Start the bot (required after each launch)/stop
- Stop the bot/set_target <channel>
- Set target channel/add_channel <channel>
- Add source channel/add_all_channels
- Add all subscribed channels/remove_channel <channel>
- Remove channel/list
- List all channels/status
- Show bot status
-
Target Channel:
- Create or use existing channel
- Make bot an admin
- Set with
/set_target @channel
-
Source Channels:
- One by one:
/add_channel @channel
- All at once:
/add_all_channels
- Formats:
@username
,https://t.me/channel
,username
- One by one:
.env
- API keys and phonesessions/
- Session fileschannels.json
- Channel settingsbot.log
- Logs (1MB rotation)
-
Import/Init Errors:
- Update code
- Restart bot
-
2FA Issues:
- Enter password when prompted
- Restart if error occurs
-
Channel Access Issues:
- Check channel membership
- Verify access rights
- Test with regular client
-
Session Problems:
- Delete
sessions
folder - Reauthorize
- Delete
Detailed logs in bot.log