Git Product home page Git Product logo

forwarder-app's Introduction

Telegram Forwarder App

Description

forwarder-app is a Python client that forwards messages automatically from a chat to another by using your Telegram account.

Every rule allows you to forward from one source to n destinations (one to many)

You can have as many rules as you want or until your machine can take it.

Setup

This project depends on TDLib. TDLib is the official cross-platform library for building Telegram clients written in C++. Also, it depends on pywtdlib which is a synchronous python Telegram wrapper for TDLib.

How to use it:

  1. Pull the docker repository

    docker pull alvhix/forwarder-app
    
  2. Make a separate folder and inside it:

    • Write your API_ID and API_HASH into the .env file. Go to Telegram page to get your API_ID and API_HASH, example:

      API_ID=1234567
      API_HASH=f10123h41l142jl134nngnl143543lep
      
    • Write your forwarder-app.config.yml file: To specify the source and destination of different chats, you may add new rules in the forwarder-app.config.yml file. Example:

      forward:
        - id: 'Rule 1'
          source: -1001234567890
          destination:
            - 1234567890
          options: {}
          send_copy: true
          remove_caption: false
      
        - id: 'Rule 2'
          source: -1000987654321
          destination:
            - 1234567890
            - -1001234567890
          options:
            disable_notification: true
            from_background: true
          send_copy: false
          remove_caption: true

      The structure of this file is very simple. Every rule has:

      • id: Give a unique name to your rule, make sure that is unique in this file
      • source: Source chat id, only one chat id
      • destination: Destination chat ids, can be multiple
      • options: Options for the message
        • disable_notification: Disable the push notification
        • from_background: Sent from the background
      • send_copy: Send copy or not
      • remove_caption: Remove caption

      For more information about the options: Go to TDLib documentation page

  3. Run the docker container inside the folder you have created:

    docker run \
    -v "$(pwd)/forwarder-app.config.yml:/forwarder-app/forwarder-app.config.yml" \
    --env-file .env \
    --name forwarder-app \
    -it alvhix/forwarder-app
    
  • -v Bind your forwarder-app.config.yml with the one on the docker container
  • --env-file Send your environment variables with your API_ID and API_HASH to the docker container
  • it Execute the container in interactive mode so you can put your credentials

Optional: You can pass the parameter --restart=always to make sure that the container starts on boot. For more info, go to this page.

This will execute the docker container and it will ask you for your Telegram account phone number and a code that you will receive. To stop the session in your Telegram account, just go to Telegram app > Settings > Privacy and security > Devices > Active sessions (just delete here the pywtdlib app)

  1. Next time you want to run the container, just use this command:

    docker start forwarder-app
    
  2. (Recommended): If you want to run the app for long periods of time in your server, I recommend you to create a cron job in your Linux machine to avoid an OOM. TDLib caches all data to be that fast, if you have a lot of chats and let the app run for long periods of time it can take all your server memory. To fix this possible problem, follow this steps:

    • Create a cron job

      crontab -e
      
    • Put this at the bottom of the file and save it

      0 0 * * 0 /usr/bin/docker restart forwarder-app
      

    This will make your docker container restart at 00:00 on every Sunday. For more info, you can check this page.

  3. To interrupt your docker container, just type

    docker stop forwarder-app
    

Configuration:

Configure the forwarder to fit your needs. The config.py contains the instructions to control the behaviour of the forwarder and the client.

FORWARDER = {
    "api_id": environ["API_ID"], # don't touch this
    "api_hash": environ["API_HASH"], # don't touch this
    "rules_path": path.join(_dirname, "forwarder-app.config.yml"), # you can specify other path to your rules file
    "group_messages": False,  # True to group media messages before forwarding, (it may take $(periodicity_fwd) second/s to forward)
    "periodicity_fwd": 1,  # second/s (not used if $(group_messages) is false)
    "verbosity": 1,
}

Hosting

The best way to host this application is in a dedicated server as AWS, Google Cloud, Azure...

Warning: The TDLib library stores data in memory throughout the life cycle of the application. It is recommended to restart the application from time to time for prolonged uses.

Logs

  • To see your logs execute this with your docker container id: docker exec forwarder-app tail log/app.log
  • Errors are registered by TDLib in console, to see the printed errors to console: docker logs forwarder-app

Issues

If you detect a bug or you have a suggestion, open a ticket with the corresponding template.

forwarder-app's People

Contributors

alvhix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

forwarder-app's Issues

Help to go

Hello, i am a little bit newbie on Linux.
i did:
sudo docker pull alvhix/forwarder-app
and then, i don't know where i Make a separate folder, and where i can find the .env file and proceed...
Can you help me ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.