Pages

Saturday, 2 July 2022

telegram-forward-bot

Simple Telegram Bot for forwarding messages easily between various related channels and groups.

Simple Telegram Bot for forwarding messages easily between various related channels and groups.

This bot allows you to automatically forward messages between different channels. We use it on our Student Comitee because we have like 15 different Telegram groups for each commission we are working on. Then, if we want some commission receives some important information, we can automatically forward to them using hashtags at the beggining of the message (or the caption of a media file).

Made with latest version of telepot at the time (12.0) and for Python 3.5.2. And shared with a MIT license.

How to install

We will assume you and your friends have Telegram accounts and several telegram chats.

First, you need to create a Telegram bot. Talk with the BotFather and ask it for a bot (and its respective token)

Then, you need to rename the file config-sample.json to config.json. Add in token property your bot's token.

Also, its very encouraged to set a password for registering to use the bot. If you don't set a password. Any person could use it and forward messages between your channels.

The next part is to install in your server the requirements of the bot using pip3 install -r requirements.txt.

finally, configure the bot, adding it on all the groups you want to connect

How to use

  1. You need to add yourself to the authorized list of the bot typing /addme {password}, where the password is the string set on bot configuration (see previous section for more details).
  2. If you want to delete your permissions from the bot, you can type /rmme. Then you won't be able to send commands to te bot (except for /addme)
  3. You can use /taglist for a list of tags registered to the bot, and the group/channel/private chat's names
  4. You cand add a tag to a group using /add #{tag}. You can remove the tag using /rm #{tag}.
  5. If you want to send a message/file/image/other to another group, you should add the tags at the start of the message or caption. you can add more than one tag if you want to.
  6. You can forward a message by replying to it with the desired tags. Both messages will be forwarded.

Some considerations

Some details about the implementation:

  1. you can't forward a message to the same chat you wrote it. The bot will warn you and reject to do that if you try to do it.
  2. Each chat can have more than 1 tag. That's very useful if you have various names for your chats, but if you write several times the same tag, or tags that point to the same group, you will have several forwardings to that chat. I plan to correct this some day. (It's not hard but I'm very busy right now).
  3. Any person registered as authorized with the bot can add tags for the chat or another chats. The use of this bot assumes you have authorized users in your chats that you trust. Also, any person registered to the bot can forward messages to any group using the tags.

from  https://github.com/SignoreOscuro/telegram-forward-bot

------

Autoforwards a channel/group messages to another channel/group.

AutoForwarder

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

Currently, being used in our updates channel to automatically forward messages to all our groups. Originally,Can be found on Telegram as Kustom Updates Bot. My Bot is deployed as Saksham's Bot

Starting The Bot

Once your configuration (see below) is complete, simply run:

python3 -m auto_forwarder

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

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

Configuration

There are two possible ways of configuring your bot: a config.py file, or ENV variables.

The prefered version is to use a config.py file, as it makes it easier to see all your settings grouped together. This file should be placed in your auto_forwarder folder, alongside the __main__.py file . This is where your bot token will be loaded from, and most of your other settings.

It is recommended to import sample_config and extend the Config class, as this will ensure your config contains all defaults set in the sample_config, hence making it easier to upgrade.

An example config.py file could be:

from auto_forwarder.sample_config import Config


class Development(Config):
    API_KEY = "1234567890:Abcdef1234567890GHIJ"  # My bot API key
    OWNER_ID = 1234567890  # My user id

    # Make sure to include the '-' sign in group and channel ids.
    FROM_CHATS = [-1001234567890]  # List of chat id's to forward messages from.
    TO_CHATS = [-1001234567890 , 1234567890]  # List of chat id's to forward messages to.
    
    WORKERS = 4

If you can't have a config.py file (EG on Heroku), it is also possible to use environment variables. The following environment variables are supported:

  • ENV: Setting this to ANYTHING will enable environment variables.

  • API_KEY: Your bot API key, as a string.

  • OWNER_ID: An integer of consisting of your owner ID.

  • FROM_CHATS: Space separated list of chat ID's to forward messages from. Do not forget to include the minus (-) sign in the chat ID's of groups and channels. You can add ID's of users too, to forward their messages with the bot.

  • TO_CHATS: Space separated list of chat ID's to forward messages to. Do not forget to include the minus (-) sign in the chat ID's of groups and channels. You can add ID's of users too, to forward messages to them.

  • WEBHOOK: Setting this to ANYTHING will enable webhooks when in env mode messages.

  • URL: The URL your webhook should connect to (only needed for webhook mode).

  • CERT_PATH: Path to your webhook certificate.

  • PORT: Port to use for your webhooks.

  • WORKERS: Number of threads to use. 4 is the recommended (and default) amount, but your experience may vary.

NOTE: You may need to use more workers if the number of messages to be forwarded are more.

Python dependencies

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

pip3 install -r requirements.txt.

This will install all necessary python packages.

from https://github.com/saksham2410/AutoForwarder-TelegramBot 

-------

TGForwarder

既然你找到了这个项目,我觉得你应该知道他是干什么的.

它能够通知你的消息被转发的情况.

首先我不建议你分裂生态,开源仅仅是为了安全(虽然我也有可能在服务端使用别的源代码,不过你不信任我也很 不知所措.jpg

而且,代码写的很差,也没有做 Python 版本判断与依赖判断(毕竟最开始的时候是给环境量身打造的

于是这些代码开源的意义仅供参考了

食用方法:
pip install telethon
python main.py
TGForwarder 使用了以下开源项目,感谢它们的贡献:

Telethon

from https://github.com/U2FsdGVkX1/TGForwarder 


 

 

No comments:

Post a Comment