Save Telegram chat log
Solution 1
Official Data Export
From 23-24/06/2018 Telegram added this option, as part of the GDPR changes.
Now you can request to download all you data, and so you can get your chat logs.
- Telegram support for Data Export:
- Telegram Desktop - from 1.3.8 or higher
- Telegram for Android - from 4.8.10 or higher
- Telegram for iOS - from 4.8.3 or higher
- Telegram Webapp - not available yet
- Telegram for Windows Phone - no idea
You can message the @GDPRbot to request your data export, or from the app settings if already available.
Note: For security reasons, the data export is not immediate, so in case someone take control over one of your devices they won't be able to immediately download all your data.
Read the full notice from Telegram's FAQ export
Demonstration from Telegram Desktop
Other options (from GitHub)
Solution 2
tg (telegram-cli) accepts Lua scripts. Here is my script which saves as many messages as you want into a sqlite database.
https://github.com/psamim/telegram-cli-backup
Solution 3
I created my own script based on @Samim's in a gist.
It prints to a file so that you can save it as you like, rather than using a SQL database.
Also, it has a sleep feature so that you can a larger number of dialogs' histories. It is still limited by telegram-cli
's hard limit of 100. I changed that by editing the source and raising the limit.
Solution 4
Answer :
It's not possible to backup your chat history in an automated way with the official application, this feature is not provided yet
Workaround :
You can still make it manually; tested on official client on windows
- Open a chat window
- Click on the last Sent/Received message and maintain you click
- Move the mouse up to select all the messages
- Right click to copy the messages
- Save them into a text file or else
Solution 5
I found pretty php library that works over telegram-cli https://github.com/zyberspace/php-telegram-cli-client
There is script that will download all messages and files.
<?php
require('vendor/autoload.php');
$telegram = new \Zyberspace\Telegram\Cli\Client('unix:///tmp/tg.sck');
$chat = 'chat_name_that_you_want_to_download';
$limit = 50;
$offset = 0;
function save($msg)
{
$path = '/path/where/you/want/to/store/messages';
file_put_contents($path . '/' . $msg->id, json_encode($msg));
}
function download($telegram, $msg)
{
$response = $telegram->exec('load_' . $msg->media->type, $msg->id);
$msg->media->path = $response->result;
}
while($msgList = $telegram->getHistory($chat, $limit, $offset)) {
$offset += $limit;
foreach($msgList as $msg) {
if (isset($msg->media)) {
download($telegram, $msg, $msg->media->type);
}
save($msg);
}
}
You have to change two strings here:
- chat_name_that_you_want_to_download
-
/path/where/you/want/to/store/messages
- Script will save every message (from chat "chat_name_that_you_want_to_download") as separated file in folder "/path/where/you/want/to/store/messages".
- Every file contains json representation of message.
- For files there will be "media->path" with path to downloaded file.
- Files will be stored at telegram-cli default folder: ~/telegram-cli/downloads
Related videos on Youtube
![Harman](https://i.stack.imgur.com/m6NNs.png?s=256&g=1)
Harman
Self-taught software developer with a law practice background. Currently working as an iOS and full-stack developer.
Updated on September 18, 2022Comments
-
Harman almost 2 years
I am not able to save chat log with Telegram. Telegram on Android, Mac OS X, Windows and Linux do not give this option to user, as far as I know. This is a basic feature and it is disappointing and surprising that this software does not have it.
There is a request for this feature here.
Maybe there is a workaround because all history is loaded on the device when you scroll back.
Is it possible to capture/save chat history loaded in the device, make a local backup copy of chat log?
-
Harman about 9 yearsThank you for trying to answer my question. When you have a lot of messages this workaround would take a very long time. Moreover, images and videos are not included during copy & paste. Therefore I will not accept this as an answer.
-
Ob1lan about 9 yearsWelcome to Super User! On this Q&A site we value answers. Hyperlinks alone tend to point toward an answer without actually being one. Please edit your answer so that it includes the essential elements from your linked source, for instance your script itself.
-
Jun almost 9 yearsHi, tried the script. works like a charm. But it doesn't backup the media is it? or am I doing something wrong?
-
Samim almost 9 years@Junaid No it does not backup media files at the moment. Media files are apart from messages. One request should be made for each media message.
-
Harman almost 9 yearsCan your script save media files and attachments?
-
Vedant Agarwala almost 9 yearsThey just mention the media type
-
anneblue over 8 yearsI did this work for a chat of several thousands of messages (saved the images and audio from telegram folders seperately). Unless this was the only way to do it by hand - it is better than nothing ;-)
-
Freelancer over 8 yearscan you please guide me how I can change the limit?. which part of the telegram-cli 's code should be changed?