Skip to content

feat(send): send rich messages from Markdown or HTML - #175

Merged
neoromantic merged 4 commits into
neoromantic:mainfrom
ertembiyik:ertembiyik/NO-TASK/send-rich
Nov 18, 2026
Merged

neoromantic merged 4 commits into
neoromantic:mainfrom
ertembiyik:ertembiyik/NO-TASK/send-rich

Conversation

@ertembiyik

@ertembiyik ertembiyik commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What and why

tg send could only send plain text, so an agent asked to send a table or a formatted report sent a screenshot of one. Telegram's API now takes rich messages, and it parses Markdown or HTML itself, so tg send --markdown and tg send --html pass --message through as a rich message: headings, tables, lists and task lists, quotations, code blocks, collapsible details, formulas and footnotes, next to bold, italic, links and the other inline styles.

Before: the text arrives as written, asterisks and pipes included.

tg send --to me -m '# Prices

| Item | Price |
|:-----|------:|
| Tea  | **3** |'

After: the same text with --markdown arrives as a heading and a real table.

tg send --to me --markdown -m '# Prices

| Item | Price |
|:-----|------:|
| Tea  | **3** |'

The result gains format ("markdown", "html", or null for plain text). When Telegram refuses the message the error names its reason and the limits. This is the real output for a table with 21 columns:

{
  "success": false,
  "error": {
    "code": "TELEGRAM_ERROR",
    "message": "Telegram refused the rich message: RICH_MESSAGE_TABLE_COLS_TOO_MANY",
    "details": { "telegramError": "RICH_MESSAGE_TABLE_COLS_TOO_MANY" },
    "suggestion": "A rich message takes up to 32768 characters, 500 blocks, 16 levels of nesting, 50 media and 20 table columns"
  }
}

How it works:

  • The request is the same messages.sendMessage, with message: "" and richMessage set to inputRichMessageMarkdown or inputRichMessageHTML. Telegram does the parsing, so tg has no parser of its own and supports whatever the syntax supports (Markdown, HTML).
  • --markdown with --html, or either with --file, is INVALID_ARGS before any connection. A caption can't be a rich message, so captions stay plain text.

Decisions you may want to change:

  • Two boolean flags instead of one --format <markdown|html>, because --format is already the output format.
  • Always a rich message, never entities. --markdown -m '**hi**' sends a one-paragraph rich message, not a plain message with a bold entity. That keeps one syntax (Telegram's) and no parser in tg. A plain message with entities, and formatted captions, would need mtcute's parsers, whose Markdown differs from Telegram's; I left that for a separate change if you want it.
  • Media inside a rich message works by URL only (Telegram fetches it). Embedding a local file needs an upload step and isn't in this PR.

Not in this PR, and worth knowing: tg messages prints a rich message with text: null, because its content is in richMessage, not in message. That affects received rich messages as well as the ones this flag sends. I have a fix for the reading side ready to send separately.

Update: main merged in (16dbd92, the 0.14.0 release)

  • Conflict: CHANGELOG.md only; both sides' entries are kept.
  • The error examples above were captured before feat(errors): say whether a retry can work, and what to run #177: every error now also prints retryable.
  • This PR's changelog entries sit under ## [Unreleased] again: the release moved everything that was there into 0.14.0.
  • After the merge: bun run check clean, bun run test 2354 pass, bun run test:e2e 455 pass, 0 fail.

How I checked it

  • Unit tests in src/__tests__/send.test.ts with the mocked client: the request for --markdown and for --html, plain text unchanged, the three argument errors, and the refusal error with its suggestion.

  • E2E in src/__e2e__/send-file.e2e.test.ts: the argument errors, checked before any connection.

  • Live, on a personal account, to Saved Messages only: a Markdown message came back as a rich message with heading, paragraph, table, list, blockquote and preformatted blocks; an HTML one with a table, an ordered list, a pull quote and details. A 21-column table and an empty message were refused with RICH_MESSAGE_TABLE_COLS_TOO_MANY and RICH_MESSAGE_EMPTY. Malformed HTML (an unclosed tag) still sent. I did not test sending to other people, groups or channels.

  • bun run check: clean. bun run test: 2308 pass, 0 fail. bun run test:e2e: 433 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, README feature list and comparison row, CHANGELOG)

  • Title follows the repo's commit style: Conventional Commits (feat: …, fix: …) unless AGENTS.md says otherwise

🤖 Generated with Claude Code

tg send --markdown and --html pass --message to Telegram as a rich
message, which it parses itself: headings, tables, lists and task lists,
quotations, code blocks, details, formulas and footnotes, next to the
inline styles. The result says which in format, and a message Telegram
refuses names its reason with the limits as the suggestion. Captions stay
plain text: a rich message can't be one.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik and others added 3 commits November 18, 2026 14:24
CHANGELOG: both sides' entries kept.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
main now has neoromantic#179 (neoromantic#188). No conflict.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
main is now the 0.14.0 release (neoromantic#189). This PR's changelog entries move
back under Unreleased: a plain merge left them in the released section.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
neoromantic added a commit that referenced this pull request Nov 18, 2026
feat(send): send rich messages from Markdown or HTML (#175)
@neoromantic
neoromantic merged commit f68fd4d into neoromantic:main Nov 18, 2026
ertembiyik added a commit to ertembiyik/telegram-sync-cli that referenced this pull request Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. fetch.ts: the batch fetch is built
on main's shared fetchMessagesByIdRaw, with the peer check kept. README
and CHANGELOG: both sides' entries kept.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik added a commit to ertembiyik/telegram-sync-cli that referenced this pull request Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. README and CHANGELOG: both sides kept. main dropped MessagesHistory.getMany (neoromantic#174): the item is read with get. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik added a commit to ertembiyik/telegram-sync-cli that referenced this pull request Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. README and CHANGELOG: both sides kept. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik added a commit to ertembiyik/telegram-sync-cli that referenced this pull request Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. README and CHANGELOG: both sides kept. main dropped MessagesHistory.getMany (neoromantic#174): the item is read with get. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik added a commit to ertembiyik/telegram-sync-cli that referenced this pull request Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. README and CHANGELOG: both sides kept. main dropped MessagesHistory.getMany (neoromantic#174): the item is read with get. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik added a commit to ertembiyik/telegram-sync-cli that referenced this pull request Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. history.ts and two test files: imports of both sides. CHANGELOG: both sides kept. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik added a commit to ertembiyik/telegram-sync-cli that referenced this pull request Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. skill.ts: main's shared getErrorMessage, the manifest stays removed. CHANGELOG: both sides kept. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik added a commit to ertembiyik/telegram-sync-cli that referenced this pull request Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. helpers.ts: the item reader takes main's raw string, with the transcript kept. sql.test.ts uses main's cache helper. CHANGELOG: both sides kept.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants