Repository navigation
fix(messages): show and index the text of rich messages - #178
Merged
neoromantic merged 1 commit intoNov 18, 2026
Merged
neoromantic merged 1 commit into
neoromantic merged 1 commit into
Conversation
A rich message has an empty text and its content in page blocks, so tg messages printed it as text null and search could not find it. Its blocks are rendered in Telegram's rich Markdown when the message is cached, and read from raw_json for rows cached earlier; the background migration messages_rich_text makes those rows searchable. messageType stays text. Co-Authored-By: Claude Fable 5.2 <[email protected]>
3 tasks done
3 tasks done
neoromantic
added a commit
that referenced
this pull request
Nov 18, 2026
fix(messages): show and index the text of rich messages (#178)
ertembiyik
added a commit
to ertembiyik/telegram-sync-cli
that referenced
this pull request
Nov 18, 2026
main now has neoromantic#178 (neoromantic#186) and neoromantic#179 (neoromantic#188). No conflict. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
A rich message (headings, tables, lists, a whole report) has an empty
messageand its content inrichMessage.blocks, sotg messages list,getandsearchprint it astext: nulland search can't find it. An agent reading a chat sees an empty message where a table was sent. This renders the blocks as text, in Telegram's own rich Markdown, wherever a message is printed or indexed. It is the reading side of #175, but stands alone: it affects every rich message received, not only the onestgsends.Before (
tg messages get --chat @gardenclub --id 2on a made-up seeded cache):{ "messageId": 2, "text": null, "messageType": "text", "hasMedia": false, "attachment": null, "action": null }tg messages search --query zucchinireturns 0 results.After:
{ "messageId": 2, "text": "# Garden report\n\nHarvest is **on track**\n\n| Crop | Kg |\n|---|---:|\n| Zucchini | 12 |\n\n- [x] water beds\n- [ ] order seeds", "messageType": "text", "hasMedia": false, "attachment": null, "action": null }The same search returns message 2. (Both outputs are real, with the unchanged fields left out.)
Where the text is produced:
writeMessageinsrc/db/messages-cache.tsis the one place that inserts intomessages_cache, so live updates, history, catch-up andtg sendall get it. When a message has no text and itsraw_jsonhas arichMessage, the rendered text is stored, and the existing FTS triggers index it. A substring check runs before any JSON parse.messageItemReaderreadsraw_jsonfor atextrow with empty text, the way fix(messages): show what a service message did (calls, pins, group changes) #159 readsattachmentandaction, so rows cached by 0.13.1 print correctly at once.messages_rich_text, fills their text. Until it reaches a row, that row prints but isn't found.onEditMessageuses the rendered text when mtcute'smsg.textis empty, so editing a rich message doesn't blank it.How blocks are rendered (
src/utils/rich-message.ts, a pure function):#headings,**bold**,*italic*,~~strike~~,`code`,==marked==,||spoiler||, links, fenced code with its language, lists and task lists,>quotations,---, pipe tables with the alignment row,$…$and$$…$$, footnotes.<u>,<sub>,<sup>,<details><summary>,<aside>.[photo: caption],[document plan.pdf],[map 41.9, 12.5],[button: label (url)].[typeName], so a block Telegram adds later doesn't blank the message again.Decisions you may want to change:
messageTypestays"text"and there is no new flag. Changing the type would break caches and scripts that filter ontext. An additiveisRichis easy to add if you want one.tg statusandtg db migrate. Say the word and I'll drop it.*in a paragraph comes out as is: better to read, not a guaranteed round trip.Known limits: a table's first-column alignment can't be told from "no alignment" in Telegram's data; the bordered and striped flags of a table and the collapsed state of a quotation are not shown.
How I checked it
Unit tests in
src/__tests__/rich-message.test.ts(21): every block and rich-text type the renderer maps, nesting (a list in details, bold in a table cell), unknown types, and both the object and theraw_jsonform, each fixture taken throughtoRawJson.E2E in
src/__e2e__/messages.e2e.test.ts:messages list(including a row cached the old way),messages get, andmessages searchon a word that appears only in a table cell. Migration tests cover filling empty text and leaving other rows alone.Against real data, read-only and outside the repo: the renderer over four real rich messages (Markdown and HTML sources, with a table, task list, quotation, code block, details, formula and footnote) gave readable text for each.
Not verified: media, map, embed and button blocks against real messages (built from the TL schema), and the live edit path against a real edit.
bun run check: clean.bun run test: 2324 pass, 0 fail.bun run test:e2e: 435 pass, 0 fail.Tests pass locally and use made-up data only
README, docs and affected demos follow the product content standard (
docs/cli-commands.md,docs/database-schema.md, thetextschema annotation, README, CHANGELOG)Title follows the repo's commit style: Conventional Commits (
feat: …,fix: …) unlessAGENTS.mdsays otherwise🤖 Generated with Claude Code