- Purpose: Automatically forward news messages from one Telegram group to another.
- Key Features:
- Fetches new messages from a source Telegram group.
- Forwards messages to a target Telegram group.
- Prevents duplicate forwarding using SQLite for message tracking.
- Handles network interruptions by periodically checking for missed messages.
- Language: Python
- Libraries: Telethon, SQLite3, asyncio
- Database: SQLite
- Deployment: Docker, Docker Compose
- API: Telegram API
git clone https://github.com/live4code/telegram-post-stealer.git
cd telegram-news-forwarder
Replace the placeholders with your Telegram API credentials and group details:
services:
telegram-bot:
build: .
container_name: telegram-bot
network_mode: host
volumes:
- ./data:/app/data
environment:
- API_ID=YOUR_API_ID
- API_HASH=YOUR_API_HASH
- PHONE_NUMBER=YOUR_PHONE_NUMBER
- SOURCE_GROUP=SOURCE_GROUP_USERNAME_OR_ID
- TARGET_GROUP=TARGET_GROUP_USERNAME_OR_ID
restart: unless-stopped
If you're not using Docker, update the following variables in the script (main.py
):
api_id = 'YOUR_API_ID'
api_hash = 'YOUR_API_HASH'
phone_number = 'YOUR_PHONE_NUMBER'
source_group = 'SOURCE_GROUP_USERNAME_OR_ID'
target_group = 'TARGET_GROUP_USERNAME_OR_ID'
-
Build and start the container:
docker-compose up --build
-
Stop the container:
docker-compose down
-
Install dependencies:
pip install -r requirements.txt
-
Run the script:
python main.py
-
Fetching Messages:
- The script listens for new messages in the source Telegram group using the
Telethon
library. - If a new message is detected, it checks whether the message has already been forwarded using an SQLite database.
- The script listens for new messages in the source Telegram group using the
-
Forwarding Messages:
- If the message is new, it forwards the message to the target group.
- The message ID is stored in the SQLite database to prevent duplicates.
-
Handling Network Issues:
- If the connection is lost, the script periodically checks the last 10 messages in the source group and forwards any missed messages.
-
Persistent Storage:
- The SQLite database (
news.db
) is stored in thedata
folder, ensuring that message IDs are preserved even after the container is restarted.
- The SQLite database (
- Telegram: @live4code
- Email: steven.marelly@gmail.com
Good luck with your Telegram news forwarding! 🚀