MrMissx / Telegram_Forwarder

Simple telegram bot to forward message from channel/group
GNU General Public License v3.0
479 stars 458 forks source link
bot forwarder telegram telegram-bot telegram-forwarder

Telegram Forwarder

A simple Telegram Python bot running on Python3 to automatically forward messages from one chat to another.

Migration from V1

v2 uses a different configuration file format. Please refer to the Configuration section for more information. The bot will not start if the configuration file is not in the correct format.

Starting The Bot

Once you've setup your your configuration (see below) is complete, simply run:

python -m forwarder

or with poetry (recommended)

poetry run forwarder

Setting Up The Bot (Read the instruction bellow before starting the bot!):

Telegram Forwarder only supports Python 3.9 and higher.

Configuration

There are two files mandatory for the bot to work .env and chat_list.json.

.env

Template env may be found in sample.env. Rename it to .env and fill in the values:

chat_list.json

Template chat_list may be found in chat_list.sample.json. Rename it to chat_list.json.

This file contains the list of chats to forward messages from and to. The bot expect it to be an Array of objects with the following structure:

[
  {
    "source": -10012345678,
    "destination": [-10011111111, "-10022222222#123456"]
  },
  {
    "source": "-10087654321#000000", // Topic/Forum group
    "destination": ["-10033333333#654321"],
    "filters": ["word1", "word2"] // message that contain this word will be forwarded
  },
  {
    "source": -10087654321,
    "destination": [-10033333333],
    "blacklist": ["word3", "word4"] // message that contain this word will not be forwarded
  },
  {
    "source": -10087654321,
    "destination": [-10033333333],
    "filters": ["word5"],
    "blacklist": ["word6"]
    // message must contain word5 and must not contain word6 to be forwarded
  }
]

You may add as many objects as you want. The bot will forward messages from all the chats in the source field to all the chats in the destination field. Duplicates are allowed as it already handled by the bot.

Python dependencies

Install the necessary python dependencies by moving to the project directory and running:

poetry install --only main

or with pip

pip3 install -r requirements.txt

This will install all necessary python packages.

Launch in Docker container

Requrements

Before launch make sure all configuration are completed (.env and chat_list.json)!

Then, simply run the command:

docker compose up -d

You can view the logs by the command:

docker compose logs -f

Credits