24

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?

6 Answers 6

3

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)

6

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

3
  • 1
    Welcome 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.
    – Ob1lan
    Jun 26, 2015 at 8:05
  • 1
    Hi, tried the script. works like a charm. But it doesn't backup the media is it? or am I doing something wrong?
    – Jun
    Jul 6, 2015 at 17:55
  • @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.
    – Samim
    Jul 12, 2015 at 5:57
5

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.

3
  • Can your script save media files and attachments?
    – Ertugrul
    Jul 25, 2015 at 22:25
  • They just mention the media type Jul 25, 2015 at 23:17
  • can you please guide me how I can change the limit?. which part of the telegram-cli 's code should be changed?
    – Freelancer
    Feb 17, 2016 at 15:57
3

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
2
  • 6
    Thank 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.
    – Ertugrul
    Jun 25, 2015 at 18:57
  • I 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 ;-)
    – anneblue
    Dec 16, 2015 at 17:49
2

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:

  1. chat_name_that_you_want_to_download
  2. /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
0

The simple way if you want to export it to text or HTML (if you want your messages colored).

You can

  • login with telegram-cli
  • open your chat history
  • export your terminal content

In my case I use Konsole, so I do File > Save output as, I prefer it in HTML.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .