Skip to content

A small tool for automatically forwarding telegram messages from a source chat to a list of destination chats as they appear

Notifications You must be signed in to change notification settings

smaugfm/simple-telegram-forwarder

Repository files navigation

Simple Telegram forwarder

A small tool for automatically forwarding telegram messages from a source chat to a list of destination chats as they appear.

  • Monitoring multiple sources and forwarding/coying messages to all the defined destinations
  • Forwarding (with 'Forwarded to' label) or just copying (posting as new) messages to destinations
  • Filtering messages with regular expressions
  • --auth-only flag to only interactively login to Telegram and then exit
  • This app uses Client API, so there is no need to create any bots and be an admin of the group/channel from where you want to forward messages
  • You don't need to trust any third party software or service with your Telegram account as this app does not force you to forward your Telegram OTP code anywhere.

Usage

You'll need a Telegram account for the app to work. The account must be a member and have necessary permissions in the chats/groups/channels between which you want to forward messages.

Configuration

Configuration is done via a json file. File name can be specified with CONFIG_FILE environment variable, by default it is simple-telegram-forwarder.config.json.

Field JSONPath Example value Description
$.api_hash cb01sdfe7922afd2970359f6aa76d0 api_hash obtained from creating a Telegram application
$.api_id 98011131 api_id obtained from creating a Telegram application
$.forwarding_config.sources[*].username @telegram Username or channel name of the source. Use this field or $.forwarding_config.sources[*].chat_id
$.forwarding_config.sources[*].chat_id -1001005640892 Chat ID of the source. Use i.e. @userinfobot to get it. Use this field or $.forwarding_config.sources[*].username
$.forwarding_config.destinations Array of destinations. Must contain at least one
$.forwarding_config.destinations[*].username @telegram Username or channel name of the source. Use this field or $.forwarding_config.destinations[*].chat_id
$.forwarding_config.destinations[*].chat_id -1001005640892 Chat ID of the destination. Use i.e. @userinfobot to get it. Use this field or $.forwarding_config.destinations[*].username
$.forwarding_config.forward bool Forward messages instead of sending a copy. Default: false
$.forwarding_config.filter (?i)(any|regex?|(you)*want) Optional regular expression for message filtering: only matched messages are forwarded.

Example configuration file:

{
  "api_hash": "cb01sdfe7922afd2970359f6aa76d0",
  "api_id": 98011131,
  "forwarding_config": {
    "sources": [{
      "username": "@telegram"
    },{
      "chat_id": "-1001005640893"
    }],
    "destinations": [
      {
        "chat_id": -1001005640892
      }
    ],
    "forward": true,
    "filter": {
      "regex": "(?i)(any|regex?|(you)*want)"
    }
  }
}

Building and running an executable

In order to compile and run this application you'll need a TDLib library installed on your system. Please refer to TDLib building instructions. Then run:

go build .
./simple-telegram-forwarder

If it is the first run, then you will be prompted to enter your phone and OTP code. After that TDLib will create .tdlib folder in the working directory which stores session data.

If you wish to decouple logging in to Telegram and normal app usage, then run the executable with --auth-only flag.

./simple-telegram-forwarder --auth-only

Running with Docker

Build docker image (may take a while):

docker build -t simple-telegram-forwarder .

Or pull an existing one from DockerHub (for linux-amd64 only):

docker pull marchukd/simple-telegram-forwarder

When running for the first time, pass--auth-only flag to interactively authorize to Telegram and then exit:

docker container run -it -v ./.tdlib:/app/.tdlib -v ./simple-telegram-forwarder.config.json:/app/simple-telegram-forwarder.config.json:ro simple-telegram-forwarder ./simple-telegram-forwarder --auth-only

After that run as usual:

docker run -v ./.tdlib:/app/.tdlib -v ./simple-telegram-forwarder.config.json:/app/simple-telegram-forwarder.config.json:ro simple-telegram-forwarder

About

A small tool for automatically forwarding telegram messages from a source chat to a list of destination chats as they appear

Resources

Stars

Watchers

Forks

Packages

No packages published