{"id":13610628,"url":"https://github.com/khoben/telemirror","last_synced_at":"2025-04-13T00:32:29.605Z","repository":{"id":37710775,"uuid":"168496924","full_name":"khoben/telemirror","owner":"khoben","description":"Telegram message forwarder (client API)","archived":false,"fork":false,"pushed_at":"2025-01-21T08:53:03.000Z","size":262,"stargazers_count":236,"open_issues_count":5,"forks_count":105,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-01-21T09:31:16.753Z","etag":null,"topics":["forwarder","heroku","mirroring","python","telegram","telegram-bot","telegram-forward-bot","telegram-forwarder","telethon"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khoben.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-31T09:17:52.000Z","updated_at":"2025-01-21T08:53:07.000Z","dependencies_parsed_at":"2024-03-20T06:24:10.698Z","dependency_job_id":"61153a7d-1388-47f4-93d7-1af9015e81ed","html_url":"https://github.com/khoben/telemirror","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khoben%2Ftelemirror","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khoben%2Ftelemirror/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khoben%2Ftelemirror/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khoben%2Ftelemirror/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khoben","download_url":"https://codeload.github.com/khoben/telemirror/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650556,"owners_count":21139670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["forwarder","heroku","mirroring","python","telegram","telegram-bot","telegram-forward-bot","telegram-forwarder","telethon"],"created_at":"2024-08-01T19:01:46.461Z","updated_at":"2025-04-13T00:32:29.591Z","avatar_url":"https://github.com/khoben.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Telegram message forwarder (client API)\n\n### Functionality\n- Live forwarding and updating messages\n- Source and target channels/chats/topics (one-to-one, many-to-one, many-to-many) mapping\n- Incoming message filters: word replacing, forward formating, skipping by keyword and more\n\n## Prepare\n\n1. [Create Telegram App](https://my.telegram.org/apps)\n\n2. Obtain **API_ID** and **API_HASH**\n\n    ![Telegram API Credentials](/README.md-images/telegramapp.png)\n\n3. Get **SESSION_STRING**\n\n    **SESSION_STRING** can be obtained by running [login.py](login.py) with provided **API_ID** and **API_HASH** environment variables. ❗ **DON'T USE** your own account.\n\n4. Setup Postgres database or use `InMemoryDatabase` with `USE_MEMORY_DB=true` parameter in `.env` file\n\n5. Fill `.env` with your data\n\n    [.env-example](.env-example) contains the minimum environment configuration to run with an in-memory database.\n\n    \u003cdetails\u003e\n    \u003csummary\u003e\u003cb\u003e.env\u003c/b\u003e overview\u003c/b\u003e\u003c/summary\u003e\n\n    ```bash\n    ###########################\n    #    App configuration    #\n    ###########################\n    \n    # Telegram app ID\n    API_ID=test\n    # Telegram app hash\n    API_HASH=test\n    # Telegram session string (telethon session, see login.py in root directory)\n    SESSION_STRING=test\n    # Use an in-memory database instead of Postgres DB (true or false). Defaults to false\n    USE_MEMORY_DB=false\n    # Postgres credentials\n    DATABASE_URL=postgres://user:pass@host/dbname\n    # or\n    DB_NAME=test\n    DB_USER=test\n    DB_HOST=test\n    DB_PASS=test\n    # Logging level (debug, info, warning, error or critical). Defaults to info\n    LOG_LEVEL=info\n    ```\n    \u003c/details\u003e\n\n6. Setup mirror forwarding config:\n\n    [mirror.config.yml-example](./.configs/mirror.config.yml-example) contains an example config: to set up a filter, specify the name of the filter (should be accessable from `./telemirror/messagefilters`) and pass named parameters with the same types but in yaml syntax. Example:\n\n    ```yaml\n    - ForwardFormatFilter:  # Filter name under telemirror/messagefilters\n        # Filter string argument\n        format: \"{message_text}\\n\\nForwarded from [{channel_name}]({message_link})\"\n\n    - SkipUrlFilter:\n        skip_mention: false # Filter bool argument\n\n    - UrlMessageFilter:\n        blacklist: !!set    # Filter set argument\n            ? t.me\n            ? google.com\n    ```\n\n    `./.configs/mirror.config.yml` or `.env` (limited) can be used to configure mirroring:\n\n    \u003cdetails\u003e\n    \u003csummary\u003e\u003cb\u003e./.configs/mirror.config.yml\u003c/b\u003e mirroring config overview\u003c/summary\u003e\n\n    ```yaml\n    # (Optional) Global filters, will be applied in order\n    filters:\n      - ForwardFormatFilter: # Filter name under ./telemirror/messagefilters\n          format: \"\"           # Filters arguments\n      - EmptyMessageFilter\n      - UrlMessageFilter:\n          blacklist: !!set\n            ? t.me\n      - SkipUrlFilter:\n          skip_mention: false\n\n    # (Optional) Global settings\n    disable_edit: true\n    disable_delete: true\n    mode: copy # or forward\n\n    # (Required) Mirror directions\n    directions:\n      - from: [-1001, -1002, -1003]\n        to: [-100203]\n\n      - from: [-1000#3] # forwards from topic to topic\n        to: [-1001#4]\n\n      - from: [-100226]\n        to: [-1006, -1008]\n        # Overwrite global settings\n        disable_edit: false\n        disable_delete: false\n        mode: forward\n        # Overwrite global filters\n        filters:\n          - UrlMessageFilter:\n              blacklist: !!set\n                ? t.me\n          - KeywordReplaceFilter:\n              keywords:\n                \"google.com\": \"bing.com\"    # treat keyword as word\n                \"r'google\\.com.*'\": \"bing.com\" # treat keyword as regex expr\n          - SkipWithKeywordsFilter:\n              keywords: !!set\n                ? \"stopword\"     # treat keyword as word\n                ? \"r'badword.*'\" # treat keyword as regex expr\n    ```\n    \u003c/details\u003e\n\n    \u003cdetails\u003e\n    \u003csummary\u003e\u003cb\u003e.env\u003c/b\u003e mirroring config overview\u003c/summary\u003e\n\n    ```bash\n    ###############################################\n    #    Setup directions and filters from env    #\n    ###############################################\n\n    # Mapping between source and target channels/chats\n    # Channel/chat id can be fetched by using @messageinformationsbot telegram bot\n    # Channel id should be prefixed with -100\n    # [id1, id2, id3:id4] means send messages from id1, id2, id3 to id4\n    # id5:id6 means send messages from id5 to id6\n    # [id1, id2, id3:id4];[id5:id6] semicolon means AND\n    CHAT_MAPPING=[-100999999,-100999999,-100999999:-1009999999];\n    \n    # (Optional) YAML filter configuration thru single-lined env string (new lines (\\n) should be replaced to \\\\n), other filter settings from env will be ignored\n    YAML_CONFIG_ENV=\n    \n    # Remove URLs from incoming messages (true or false). Defaults to false\n    REMOVE_URLS=false\n    # Comma-separated list of URLs to remove (reddit.com,youtube.com)\n    REMOVE_URLS_LIST=google.com,twitter.com\n    # Comma-separated list of URLs to exclude from removal (google.com,twitter.com).\n    # Will be applied after the REMOVE_URLS_LIST\n    REMOVE_URLS_WL=youtube.com,youtu.be,vk.com,twitch.tv,instagram.com\n    # Disable mirror message deleting (true or false). Defaults to false\n    DISABLE_DELETE=false\n    # Disable mirror message editing (true or false). Defaults to false\n    DISABLE_EDIT=false\n    ```\n    \u003c/details\u003e\n\n    **Channel mirroring config priority**:\n\n    - `YAML_CONFIG_ENV` from `.env`\n\n    - from `./.configs/mirror.config.yml` file\n\n    - `CHAT_MAPPING, REMOVE_URLS, REMOVE_URLS_LIST, REMOVE_URLS_WL, DISABLE_DELETE, DISABLE_EDIT` from `.env` file\n\n    ❓ Channels ID can be fetched by using [Telegram bot](https://t.me/messageinformationsbot).\n\n    ❗ Note: never push your `.env`/`.yml` files with real crendential to a public repo. Use a separate branch (eg, `heroku-branch`) with `.env`/`.yml` files to push to git-based deployment system like Heroku.\n\n7. Make sure the account has joined source and target channels\n\n8. **Be careful** with forwards from channels with [`RESTRICTED SAVING CONTENT`](https://telegram.org/blog/protected-content-delete-by-date-and-more). It may lead to an account ban\n\n## Deploy\n\u003cdetails\u003e\n    \u003csummary\u003e\u003cb\u003eHeroku\u003c/b\u003e\u003c/summary\u003e\n\u003cbr\u003e\n\n[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/khoben/telemirror)\n\n### or via CLI:\n\n1. Clone project\n\n    ```bash\n    git clone https://github.com/khoben/telemirror.git\n    ```\n2. Create new heroku app within Heroku CLI\n\n    ```bash\n    heroku create {your app name}\n    ```\n3. Add heroku remote\n\n    ```bash\n    heroku git:remote -a {your app name}\n    ```\n4. Set environment variables to your heroku app from .env by running bash script\n\n    ```bash\n    ./set_heroku_env.bash\n    ```\n\n5. Upload on heroku host\n\n    ```bash\n    git push heroku master\n    ```\n\n6. Start heroku app\n\n    ```bash\n    heroku ps:scale web=1\n    ```\n\n#### Keep up-to-date with Heroku\n\nIf you deployed manually, move to step 2.\n\n0. Get project to your PC:\n\n    ```bash\n    heroku git:clone -a {your app name}\n    ```\n1. Init upstream repo (this repository or its fork)\n\n    ```bash\n    git remote add origin https://github.com/khoben/telemirror\n    ```\n2. Get latest changes\n\n    ```bash\n    git pull origin master\n    ```\n3. Push latest changes to heroku\n\n    ```bash\n    git push heroku master -f\n    ```\n\u003c/details\u003e\n\n### Locally:\n1. Create and activate python virtual environment\n\n    ```bash\n    python -m venv venv\n    source ./venv/Scripts/activate # linux\n    venv\\Scripts\\activate # windows\n    ```\n2. Install dependencies\n\n    ```bash\n    pip install -r requirements.txt\n    ```\n3. Run\n\n    ```bash\n    python main.py\n    ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhoben%2Ftelemirror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhoben%2Ftelemirror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhoben%2Ftelemirror/lists"}