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.

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.

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_list to get an overview of all your contacts.

Use the command history to 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 history also works for groups. There is no groups_list command, but using dialog_list will 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.

Alex 2015-03-14 on 13:57

Great, thanks for this article. I tried this first in a VM with ubuntu-14.04.2-desktop-amd64.iso, didn’t work (always crashed and some users reported the same problems on Github). Then I moved to an AWS EC2 instance and did it from there, worked without problems this time.

Alex

loser 2015-04-07 on 17:46

omg so hard.. i wish somebody could do it for me :(

Oldboy 2015-04-10 on 14:23

It’s strange that there is no easier way of doing this. On my iPhone 5S, Telegram messages are stored in plain text in an SQLite database called “tgdata_index.db”. Making a jailbreak tweak or something wouldn’t be difficult I suppose.

The file can be found at: var/mobile/Containers/Data/Application//Documents/tgdata_index.db

Samim Pezeshki 2015-06-26 on 07:07

Alex 2015-07-19 on 06:01

These instructions and the instructions in the links are frustratingly vague. For example:

2. Now run tg (bin/telegram-cli) and follow the steps to get an activation code.

What on earth does that mean?! Is the user to type in terminal “tg” or “bin/telegram-cli” or “telegram-cli” or “/bin/telegram-cli” or to navigate to the folder? At any rate, this file does not exist, because in step 1, the instructions are all over the place and unclear:

At one point it just says: “Install these ports:

devel/libconfig
devel/libexecinfo
lang/lua52”

Yes. HOW?? With what Terminal-command?? Sorry, this incompleteness is just lazy.

Hope this is useful to someone. (This is on Mac OS X Yosemite, Telegram version Version 1.71.23467)

hasti 2015-08-08 on 05:24

Hello
If we deactivate our telegram and then we install it again..will we be able to recover all previous chats?

Tim 2015-08-12 on 21:00

Thanks for the article! Unfortunately a plain text dump is pretty limited, and both the tg history command and telegram-cli-backup seem to have trouble with large backlogs now. But they did inspire my final solution, which I’ll leave here in case anyone finds it useful.

It’s Python script for tg which will export conversations of any size to newline separated JSON format:

Writing a conversion script to turn the JSON into nicely formatted text would be fairly trivial.

Alex 2015-09-03 on 14:40

Evernote!! (no terminal required)

Open the web-version of your telegram account e.g. in google chrome. have the evernote plugin installed and once you select the desired chat conversation that you want to be archived, click on the evernote button in your chrome menu bar and save the chat thread as “article” – and hurray! ALL your chat including images will be saved (and can then further be exported as html via the evernote export function within its own native app).
Enjoy!

vvvv 2015-09-08 on 10:00

Hi, thanks for these instructions. When I run telegram-cli I get the following error:
*** No public keys found
I do have a public key in .ssh but obviously here something else is meant. Any help would be appreciated!

Matze 2015-12-24 on 13:00

Richard steuart 2016-01-03 on 06:28

Ashkan 2016-02-08 on 08:30

Hi,
when I apply command to connect to Telegram DC IP address, I get this error:

*** Connect with 173.240.5.1:443 Time Out.

I wonder where in what file I can change this IP address to a new one.

Thanks.

angel 2016-02-23 on 07:56

As I can get the information of a group?
Thanks

Wenyan 2016-02-28 on 01:04

Thanks for the article! But I am totally new with computer, is anyone can teach me ? Thanks a lot.

Wenyan

Ivan 2016-02-28 on 08:55

Hey folks, there is a Chome extension available called “Save Telegram Chat History”. It’s very simple, no command line and so forth, just works with your web-browser.

jojo 2016-03-01 on 09:30

@ ivan
thanks man
you made my day !

Bernie Calucci 2016-03-04 on 21:08

WHERE THE FUCK are these files on OS X how is it POSSIBLE that there’s ABSOLUTELY NO DOCUMENTATION as to where this retarded app which claimed to protect our privacy WRITES our PRIVATE conversations! WHERE is the COMPLETE file location list for EVERY platform!?!

Bernie Calucci 2016-03-04 on 21:10

I don’t WANT NO STUPID SCRIPT I WANT ACCESS TO THE ACTUAL FILE TO PROTECT IT!!!! How is it possible that I’ve been hours on the internet and there is no clear documentation about this!!

It\’s actually just installing the Chrome plugin, accessing web.telegram.org, receiving the chat history and saving it.

By the way (and I hope it is okay that I write this here): Yesterday we published our webapp Telegramalyzer where you can analyze your Telegram chat logs (that you retrieved via the Chrome plugin). That way you can see what your most used emojis are, your messages over time, who writes, weekdays, hour chart,…
Would be glad if someone checked it out :)

farda 2018-06-19 on 09:08

Hi, how can I recover deleted telegram chats on my iPhone?
Thanks in advance.

redh 2018-10-03 on 19:40

Hi. What about a service in windows that will actually collect last x messages (I need from a group to fetch last message) with a predefined frequency? Maybe this feature could transform in Telegram to SMS (for those who are in a meeting and want to not miss any important info from a group).

Susan 2018-10-21 on 00:41

I have a very serious problem. Someone has hacked my telegram. I want to change the number, it says I have to delete the other account and I don’t have it. what should I do? please help. Thanks