#/bin/sh -xe
cat decrubru_channel-2025-11-04/result.json | jq -c '.messages[] | select(.type=="message") | [.id, (.text | if type == "array" then . else [.] end | tojson)] | @sh' --raw-output0 | xargs -0r -I {} sh -c 'set -- {}; filename=post-id_$(printf %04d $1).json; shift; printf %s "$@" > $filename';# Specification: https://github.com/telegramdesktop/tdesktop/blob/6fea6393c62106dc60c589304e42fb39b59f03a0/Telegram/SourceFiles/export/output/export_output_json.cpp
def trim: gsub("(^\\s*|\\s*$)"; "");
def getText: .text | trim;
def wrap(str): "\(str)\(getText)\(str)";
def wrapInTag(n): "<\(n)>\(getText)</\(n)>";
def is(t): .type == t;
map(
if type == "string" then .
elif is("bold") then wrap("__")
elif is("italic") then wrap("*")
elif is("underline") then wrapInTag("u")
elif is("strikethrough") then wrap("~~")
elif is("code") then wrap("```")
elif is("pre") then wrap("`")
elif is("blockquote") then "> \(getText)"
elif is("spoiler") then wrapInTag("details")
elif is("mention") then getText
elif is("link") then getText
elif is("text_link") then getText
elif is("emoji") then getText
elif is("hashtag") then getText
else
"UNKNOWN TYPE"
end | tostring
) | join("")cat SOME_POST.json | jq -f FILE_WITH_THE_SCRIPT_ABOVE.jqI've dumped my telegram channel to jsonl with tegracli python package and
converted all posts to markdown with the script below.
Unfortunately tegracli doesn't preserve formatted text (quotes, code, spoilers, etc.)
so I just resorted to other tools.
Still share the script though.
https://pypi.org/project/tegracli/
# Dump jsonl from tegracli to `dump.jsonl`.
# Then convert it to markdown:
cat ../dump.jsonl | jq -c 'select(.["_"]=="Message" and has("message")) | [.id, .date, .message] | @sh' --raw-output0 | sort -zu | xargs -0r -I {} sh -c 'set -- {}; filename=post_$1.txt; shift 2; echo "$@" > $filename;'