Update: Telegram Desktop version 1.3.8 added an option to export all your data as either a set of HTML files or a JSON file. This was added to comply to the European GDPR directive. I’ve tried this out and it works as promised and is now definitely the easiest option to export your data. Thanks European Union!
This article is kept for archiving purposes but the methods outlined probably shouldn’t be used anymore.
Note: i’ve updated this article in april 2016 with a new method that’s still clunky, but works a little bit better.
Considering that WhatsApp was sold in February 2014 to Facebook for a petty $19 billion dollars you might have looked around for alternatives. Currently the most promising messaging client is Telegram, an alternative mostly financed by Pavel Durov, who ironically founded Facebook’s biggest competitor in Russia: VK.
Now some people might suggest switching from WhatsApp to Telegram is simply trading one evil (Facebook) for another (VK). However, Durov has nothing to do with VK anymore and the people behind Telegram say they respect your privacy. Telegram is mostly open source as well. Time will tell if Telegram can stay true to their promises.
Anyway, one missing feature (the only one, in my opinion) is the ‘export chat’ option that is available on WhatsApp. I’m not that interested in transferring messages between devices, but i do think it’s important to have an export of your digital history, whether it’s e-mail, instant messaging or your tweets.
There are multiple feature requests for the various (semi) official apps, but currently there doesn’t seem to be a simple solution.
Anyway, i found a hack, but unfortunately it’s pretty technical and not for those afraid of the command line. Unfortunately it’s only for Linux and Mac systems as well.
Basically you’re using a combination of the command line tg command and a Ruby script called telegram-history-dump. Used in conjunction, you get a set of JSON files that you can further process, for example using a Python script that compiles it to a CSV file you can open in Excel. Here’s something i wrote for that.
Here’s what you should do:
- Open up a Terminal and follow the instructions to install tg for your operating system. On my MacBook with Yosemite i needed this ugly hack to properly install the brew dependencies. On El Capitan i ran into countless other problems including something where i actually needed to comment out some C code in a source file. Following the instructions in this issue solved it for me.
- Now run tg (
bin/telegram-cli) and follow the steps to get an activation code.
- Follow the instructions to install telegram-history-dump. The default configuration worked fine for me.
- Run the script from the command line. This will get you a map of JSONL files that contain your precious messages.
- You could try and run my python script to get CSV files for easier viewing.
Alternatively, if you don’t want to run the telegram-history-dump script for some reason you could also try these steps with just tg:
- Run the command
contact_listto get an overview of all your contacts.
- Use the command
historyto get the chat log. The first argument is the name of your friend (note that tg offers tab completion!), the second one is the number of messages. There doesn’t seem to be a setting for ‘all messages’ so simply pick a high number, e.g.:
history My_Friends_Name 10000
- tg doesn’t offer a way to export the history to a text file, so you either need to copy-paste the stuff from the terminal or save the terminal output to a file (the last option works best for the OS X Terminal).
- Note that
historyalso works for groups. There is no
groups_listcommand, but using
dialog_listwill also show groups.
- Repeat for every user and/or group you want to export.
I know, this is all pretty clunky. Hopefully the people at Telegram and/or the coders who create the clients will create a better export option in the future.