A Python-based Telegram bot that listens to messages from a source channel and forwards them (including media and formatted hyperlinks) to a destination group.
- Listens for new messages in a specified Telegram channel
- Supports forwarding both text and media messages
- Preserves hyperlinks in messages using HTML formatting
- Automatically cleans up downloaded media files after sending
- Python 3.7+
- Telegram API credentials
- A bot token
- Environment variables set in a
.env
file
-
Clone the repository:
git clone [email protected]:bunsalcoder/telegram-message-scrapper.git cd telegram-message-scrapper
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file in the project directory and add your credentials:API_ID=your_api_id API_HASH=your_api_hash BOT_TOKEN=your_bot_token DESTINATION_GROUP_ID=-100xxxxxxxxxx # Your target group ID SOURCE_CHANNEL_ID=-100xxxxxxxxxx # Your source channel ID PHONE_NUMBER=+855xxxxxxx # Phone number with country code
Run the bot:
python3 index.py
- Connects to Telegram using Telethon.
- Monitors the specified
SOURCE_CHANNEL_ID
for new messages. - If the message contains media, it downloads and forwards it.
- If the message has hyperlinks, it formats them properly using HTML.
- Sends the message to
DESTINATION_GROUP_ID
.
- If
.env
variables are not loading, try running:export $(grep -v '^#' .env | xargs)
- Ensure your bot is an admin in both the source channel and destination group.
- Check that your API credentials are correct.
This project is open-source and available under the APACHE-2.0 License.