- No need to be added by the channel's admin
- Listen to update events (new message, message edited, message deleted and etc)
- Live forwarding and updating messages
- Flexible mapping of source and target channels/chats (one-to-one, many-to-one, many-to-many)
- Configurable incoming message filters (will be applied to target channels):
- CompositeMessageFilter - Composite filter that sequentially applies other filters
- EmptyMessageFilter - Do nothing with message
- SkipUrlFilter - Skip messages with URLs
- UrlMessageFilter - URLs filter
- ForwardFormatFilter - Forward formatting filter
- MappedNameForwardFormat - Forward formatting filter with mapped channels name
- KeywordReplaceFilter - Keyword replacing filter
- SkipAllFilter - Skip all messages filter
- SkipWithKeywordsFilter - Skip for keywords message text filter
- RestrictSavingContentBypassFilter -
Saving content restrictionfilter (not ready, PRs are welcome)
-
It's better not to use your main account. Register a new Telegram account
-
Obtain API_ID and API_HASH
-
Setup Postgres database or use InMemoryDatabase with
USE_MEMORY_DB=trueparameter in.envfile -
Fill .env-example with your data and rename it to
.env❗ Note: never push your
.env/.ymlfiles with real crendential to a public repo. Use a separate branch (eg,heroku-branch) with.env/.ymlfiles to push to git-based deployment system like Heroku:git push heroku heroku-branch:master
.env-example contains the minimum environment configuration to run with an in-memory database.
SESSION_STRING can be obtained by running login.py locally (on your PC with installed python 3.9+) with putted API_ID and API_HASH before.
Channels ID can be fetched by using @messageinformationsbot Telegram bot (just send it a message from the desired channel).
.env overview
# Telegram app ID API_ID=test # Telegram app hash API_HASH=test # Telegram session string (telethon session, see login.py in root directory) SESSION_STRING=test # Mapping between source and target channels/chats # Channel/chat id can be fetched by using @messageinformationsbot telegram bot # Channel id should be prefixed with -100 # [id1, id2, id3:id4] means send messages from id1, id2, id3 to id4 # id5:id6 means send messages from id5 to id6 # [id1, id2, id3:id4];[id5:id6] semicolon means AND CHAT_MAPPING=[-100999999,-100999999,-100999999:-1009999999]; # Remove URLs from incoming messages (true or false). Defaults to false REMOVE_URLS=false # Comma-separated list of URLs to remove (reddit.com,youtube.com) REMOVE_URLS_LIST=google.com,twitter.com # Comma-separated list of URLs to exclude from removal (google.com,twitter.com). # Will be applied after the REMOVE_URLS_LIST REMOVE_URLS_WL=youtube.com,youtu.be,vk.com,twitch.tv,instagram.com # Disable mirror message deleting (true or false). Defaults to false DISABLE_DELETE=false # Disable mirror message editing (true or false). Defaults to false DISABLE_EDIT=false # Use an in-memory database instead of Postgres DB (true or false). Defaults to false USE_MEMORY_DB=false # Postgres credentials DATABASE_URL=postgres://user:pass@host/dbname # or DB_NAME=test DB_USER=test DB_HOST=test DB_PASS=test # Logging level (debug, info, warning, error or critical). Defaults to info LOG_LEVEL=info
For more flexible configurations (setup directions and filters), use yaml:
mirror.config.yml overview
# (Optional) Global filters, will be applied in order filters: - ForwardFormatFilter: # Filter name under telemirror/messagefilters.py format: "" # Filters arguments - EmptyMessageFilter - UrlMessageFilter: blacklist: !!set ? t.me - SkipUrlFilter: skip_mention: false # (Optional) Global settings disable_edit: true disable_delete: true # (Required) Mirror directions directions: - from: [-1001, -1002, -1003] to: [-100203] - from: [-100226] to: [-1006, -1008] # (Optional) Targets config targets: # Config will be applied to target channel with id=-100203 - id: -100203 # Overwrite global settings disable_edit: false disable_delete: false # Overwrite global filters filters: - UrlMessageFilter: blacklist: !!set ? t.me
-
Make sure the account has joined source and target channels
Be careful with forwards from channels with restricted saving content. It may lead to an account ban.
If you want to bypass forward restriction, see RestrictSavingContentBypassFilter sources to start.
Heroku
-
Clone project
git clone https://github.com/khoben/telemirror.git
-
Create new heroku app within Heroku CLI
heroku create {your app name} -
Add heroku remote
heroku git:remote -a {your app name} -
Set environment variables to your heroku app from .env by running bash script
./set_heroku_env.bash
-
Upload on heroku host
git push heroku master
-
Start heroku app
heroku ps:scale run=1
If you deployed manually, move to step 2.
-
Get project to your PC:
heroku git:clone -a {your app name} -
Init upstream repo (this repository or its fork)
git remote add origin https://github.com/khoben/telemirror
-
Get latest changes
git pull origin master
-
Push latest changes to heroku
git push heroku master -f
-
Create and activate python virtual environment
python -m venv myvenv source myvenv/Scripts/activate # linux myvenv/Scripts/activate # windows
-
Install dependencies
pip install -r requirements.txt
-
Run
python main.py
