This is a Telegram bot that automatically forwards messages from a source channel/group to a designated destination channel/group.
- Forwards Messages: Sends messages from a source to a destination.
- Handles Media Groups: Keeps media groups together and forwards them as a single message.
-
Clone the Repository:
git clone https://github.com/khduy/forward-bot.git cd forward-bot
-
Install Dependencies:
pip install -r requirements.txt
-
Environment Variables:
-
Create a
.env
file in the root directory. -
Add the following:
BOT_TOKEN=<your_bot_token> OWNER_ID=<your_telegram_user_id>
- Replace
<your_bot_token>
with the token from BotFather. - Replace
<your_telegram_user_id>
with your Telegram user ID (use a bot like@userinfobot
to find it).
- Replace
-
-
Configuration:
config.json
is created automatically when you set source and destination IDs.- Source ID: ID of where to forward messages from (use negative IDs for channels/groups, e.g.,
-1001234567890
). - Destination ID: ID of where messages will be forwarded to.
-
Running the Bot:
python src/main.py
- Start the bot: Send
/start
to the bot in Telegram. - Set the source:
/setsource <source_channel_id>
(bot must be in the source channel/group).
- Set the destination:
/setdestination <destination_channel_id>
(bot must be an admin in the destination channel).
- View config:
/config
- Help:
/help
- The bot forwards messages that arrive after setup.
- Ensure the bot has needed permissions.
- Constants like
MEDIA_GROUP_TIMEOUT
,MAX_RETRIES
can be adjusted inmessage_forwarder.py
.
- "Bot token not found..." error: Check your
.env
file andBOT_TOKEN
. - "You're not authorized..." error: Make sure
OWNER_ID
in.env
is your Telegram ID. - Messages not being forwarded:
- Check source/destination IDs.
- Ensure the bot has correct permissions.
- Look for errors in the console log.
- "Failed to forward media group..." error: Usually a network or Telegram API issue. Try again later.
- Other errors: The console log will have more details.
This bot is provided as-is. Use it responsibly and follow Telegram's terms of service. The developers are not responsible for any misuse.