Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tzagim/tzbot

Repository files navigation

tzbot

Sending messages from group to group in Telegram using a bot, the main difference between a user and a bot is the ability to edit messages.

If you want to send messages as a USER, use: fuserbot

please note:

version 4.x works with Telegram Python bot ver 22+

version 3.x works with Telegram Python bot ver 21+

version 2.x works with Telegram Python bot ver 20-21

version 1.X works with Telegram Python bot ver 13.15 and below!!

Features

Deleting join and leave messages and commands

The bot must be granted deletion privileges in order to delete messages user leave or join the group, and also commands by users other than the bot owner.

Auto Forwarder

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

Auto Delete messages after X time

Automatic deletion of messages after a specified period of time, please note that you cannot delete messages of another bot, Because of Telegram limitations.

Translation

Languages ​​can be added in strings.py, the default language is the user's language, if the user's language cannot be found or in channels the default is English.

Setting Up The Bot (Read Before Trying To Use!):

Please make sure to use the latest Python version. (Recommended)

Configuration

Configuring your bot: a config.env and chat_list.json files.

This file should be placed in tzbot folder, alongside the __main__.py file . This is where your bot token will be loaded from, and most of your other settings.

config.env

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

Value Type Default Description Options
BOT_TOKEN str none Telegram bot token. You can get it from @BotFather string
OWNER_ID int none An integer or a comma-separated list of consisting of your owner ID. integer
REMOVE_TAG str False set to True if you want to remove the tag ("Forwarded from xxxxx") from the forwarded message. False True
DEFAULT_LANG str en Default language when the user language cannot be retrieved and in channels, if blank defaults to English. en / he
APSCHEDULER_LOG_LEVEL str INFO Syslog log levels are defined in RFC 5424 string
APSCHEDULER_SCHEDULER_INFO int 0 An integer that determines whether schedule additions or removals will be displayed: 0 = hidden, 1 = visible 0 / 1

An example config.env file could be:

BOT_TOKEN = 1234567890:Abcdef1234567890GHIJ
OWNER_ID = 1234567890, 0987654321
REMOVE_TAG = True
DEFAULT_LANG = en
APSCHEDULER_LOG_LEVEL = INFO
APSCHEDULER_SCHEDULER_INFO = 0

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 - The chat ID of the chat to forward messages from. It can be a group or a channel.

    If the source chat is a Topic groups, you MUST explicitly specify the topic ID. The bot will ignore incoming message from topic group if the topic ID is not specified.

  • destination (Optional) - An array of chat IDs to forward messages to. It can be a group or a channel.

    Destenation supports Topics chat. You can use #topicID string to forward to specific topic. Example: [-10011111111, "-10022222222#123456"]. With this config it will forward to chat -10022222222 with topic 123456 and to chat -10011111111 .

  • filters (Optional) - An array of strings to filter words. If the message containes any of the strings in the array, it WILL BE forwarded.

  • blacklist (Optional) - An array of strings to blacklist words. If the message containes any of the string in the array, it will NOT BE forwarded.

  • delete_after (Optional) - A numeric integral. Defines the time in seconds period after which the message will be deleted.

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.

It is also possible to enter several different filters on the same source.

[
  {
    "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"],
    "delete_after": 60
    // message must contain word5 and must not contain word6 to be forwarded and deleted after 60 seconds
  },
  {
    "source": -10087654321,
    "delete_after": 2700
    // message from this group will be deleted after 2700 seconds
  }
]

Installing

Python dependencies

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

$ git clone https://github.com/tzagim/tzbot
$ cd tzbot

If you are using pip:

$ pip install -r requirements.txt

If you are using advanced versions of linux that pip cannot be used:

$ sudo apt install python3-anyio python3-certifi python3-h11 python3-httpcore python3-httpx python3-idna python3-dotenv python3-python-telegram-bot python3-rfc3986 python3-sniffio python3-apscheduler

This will install all necessary python packages.

Launch in Docker container

Requrements

  • Docker
  • docker compose

Before launch make sure all configuration are completed (config.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

Starting The Bot

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

$ python3 -m tzbot

Can be run in a screen with the following command:

$ screen -dmS tzbot python3 -m tzbot

Credits

Based on: MrMissx - Telegram_Forwarder

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •