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