License: MIT
Author: Eyad Jawad
I have used this tool to archive 1 million text messages in less than 4 hours, this is around the maximum speed set by the Telegram api, which is 100 msg/s, factoring floodwaits in, and you get a similar number.
Know that the numbers above do not put multimedia into account, in such a case the speed would depend wholly on your internet speed, and probably a stricter floodwait protocol set by Telegram, I personally have not tried to use this tool to archive a huge number of files.
Use this tool on your own accord, it is still possible to get banned for spam if you use it "too aggressively", I used it very much so, but haven't gotten into any problem or what so ever, however, be careful when you using it.
You have to get the API keys from telegram and then set them in the .env:
TELEGRAM_API_KEY = "123456"
TELEGRAM_API_HASH = "abcdefg"
This is probably the safest way possible to ensure that your keys don't get leaked, I would never put mine straight into the program, you could read them from a file, but don't forget to add it to the gitignore.
You could use uv to do it:
pip install uv
uv sync
uv run main.py -t -d
Or if you have docker installed just run this command:
docker build -t telegram-archiver .
And then when you run it you must do this:
docker run -it --rm \
-v "$(pwd)/Media:/usr/src/telegramArchiver/Media" \
-v "$(pwd)/telegram.db:/usr/src/telegramArchiver/telegram.db" \
-v "$(pwd)/archiving.log:/usr/src/telegramArchiver/archiving.log" \
telegram-archiver -t -d
The last two things -t -d are arugments for the program, read the next section to know them
-a, --archive-all: archive everything
-t, --archive-text: archive text messages (including forward, reply, edit, and sender_id)
-r, --archive-reactions: archive message reactions
-d, --archive-dialog-info: archive dialog info like title, bio, pfps, and etc.
-u, --archive-user-info: archive info of users in a dialog, like name, bio, pfps, and etc.
-k, --archive-stickers-info: archive info of sticker sets like links and the sort.
-f, --archive-file: archive files, like photos, videos, documents, and etc. with a size threshold (default: 100MB)
-b, --archive-big-files: archive all files ignoring the default of 100MB
-s, --size-threshold : the size threshold for files (default: 100MB)
After that, you just have to run the command:
python main.py -t -r -f -s 10
There are tests covering all of the helper module, and some classe, the coverage as reported by coverage is 75%, to run the tests run:
python -m pytest
Or you could use uv, you can also run:
pip install uv
uv sync
uv run python -m pytest
uv run ruff check .
uv run black .
uv run mypy .
I learnt a lot about file managment, and how to parse things in general, but the coolest thing if you ask me is the progress bar, that is cool.
This project did take a good chunk of time to finish, or at least get it to work, and I did it mainly because I love archiving things locally, it works pretty well in my opinion.
I also learnt a good amount of error handling, while it is not sublime, error handling is good here.
I'd like to add a way to reverse the process and get a GUI out of it, I've seen that on discord archivers, I'd also want to add a way to compress stuff, like files, or at least do something about them because they take A LOT of space.
All in all, I'm pretty much satisfied with this project, it took me about 50h? idk (probably 70h+ by now (prolly 100h by now(even 150h by now))), but I do feel like I'm missing some features.
I have listed a good list of todos and fixme in the code, I might do them one day...? idk, I hopne it'll be good, inshallah.
Update: I did get a good hand-on exp. on SQLite and pytest (:
Thank you for reading
- Eyad.
