You use Telegram to store stuff, e.g. notes to yourself, files, etc. Possibly you even use it together with another person to share notes, e.g. your grocery store list.
But: you created a group in the past, which now blocks you from editing the messages of yourself or the other person. You want to get rid of the group and use a much-cooler channel, but you refrain from copying all the content of the group by yourself.
This script is for you.
This script copies messages from a source chat to a destination chat.
It will display the list of available chats/groups/channels first, and you can select source and destination.
It keeps a list of already-copied messages on file, so you can run it multiple times without copying everything again.
-
Clone this repository and cd into the corresponding directory:
git clone git@github.com:rgiessmann/telegram-copy-messages.git cd telegram-copy-messages
-
Copy
.env.example
to.env
.cp .env.example .env
-
Fill in your phone number in the
.env
file. Obtainapi_id
andapi_hash
from this link and fill it insideTelegram Configuration
section of the.env
file. -
Run the script via python:
pip install -r requirements.txt python main.py
or with Docker:
docker build --no-cache -t telegramcopymessages . docker run --rm --env-file=.env -v td-data:/tmp/.tdlib_files -v telegramcopymessages-data:/app/data telegramcopymessages
-
After logging in, you will see your chat names and their chat id. Copy chat ids of source and destination chats and put them inside
App Configuration
section of the.env
file. -
Run the script or container again (with the commands from above) and it will do the job. The links between messages are saved persistently in either your local directory (under "data") or in the Docker volume telegramcopymessages-data.
Kudos to https://github.com/radinshayanfar/TGCopyBot/ and https://github.com/alexander-akhmetov/python-telegram/blob/master/examples/ !