Skip to content

feat(send): format a caption with --html - #239

Open
ertembiyik wants to merge 1 commit into
neoromantic:mainfrom
ertembiyik:ertembiyik/send-caption-html
Open

ertembiyik wants to merge 1 commit into
neoromantic:mainfrom
ertembiyik:ertembiyik/send-caption-html

Conversation

@ertembiyik

@ertembiyik ertembiyik commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What and why

A caption is plain text, so it can't carry a link: --html and --markdown refuse --file. --html with --file now formats --caption.

Before (0.16.0)

$ tg send --to me --file ./report.pdf --html --caption 'Q3: <a href="https://example.com/q3">the numbers</a>'
INVALID_ARGS: --html formats --message: a caption is plain text

After (trimmed)

$ tg send --to me --file ./report.pdf --html --caption 'Q3: <a href="https://example.com/q3">the numbers</a>'
"sent": true, "format": "html", "file": { "name": "report.pdf", "sentAs": "document" }

The chat shows Q3: the numbers, with the numbers as a link.

How it works

  • messages.sendMedia takes no rich message, only entities. So the caption is parsed on this machine with the HTML parser @mtcute/bun already ships (no new dependency) and sent as text plus entities. It follows Telegram's HTML style: <b>, <i>, <u>, <s>, <a href>, <code>, <pre>, <blockquote>, <tg-spoiler>. Line breaks stay as written.
  • --markdown still formats --message only (INVALID_ARGS with a file, with a message that names --html). The entity Markdown is a different dialect from a rich message's: __x__ is italic and *x* is literal, so one flag would mean two syntaxes.
  • A link to a user by ID (tg://user?id=…) needs an access hash, so it is INVALID_ARGS before anything connects.
  • --html --file without --caption is INVALID_ARGS.
  • The result's format is html for a formatted caption and null for a plain one, as before. The cached text is the caption without tags.

Independent of #238 (an MP4 or MOV file sent as a video). Both edit the same paragraphs of docs/media.md and docs/cli-commands.md; I will merge main into whichever is left after the first one lands.

How I checked it

  • Unit test: a caption with bold, a link, an escaped & and blank lines becomes the expected text and entities, and sendFile puts them into messages.sendMedia; a plain caption sends no entities.

  • E2E through the real CLI: --markdown --file, --html --file without a caption and a mention by ID are refused before credentials are read; --html --caption passes the argument checks.

  • Live, one send to Saved Messages (a file with a two-line caption holding bold text and a link): the stored message has the text without tags, the line break, messageEntityBold and messageEntityTextUrl at the right offsets.

  • bun run check, bun run test (1339 pass), bun run test:e2e (439 pass).

  • Tests pass locally and use made-up data only

  • README, docs and affected demos follow the product content standard

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

🤖 Generated with Claude Code

--html and --markdown refused a file: a caption was plain text, so it
could not carry a link. messages.sendMedia takes no rich message, only
entities, so --html with --file now parses the caption on this machine
with Telegram's HTML style (bold, italic, links, code, quotes, spoilers)
and sends its text and entities. --markdown keeps formatting --message
only: a rich message's Markdown and the entity dialect differ. A link to
a user by ID needs an access hash the caption has no way to give, so it
is INVALID_ARGS before anything connects.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

This branch has not been deployed

No deployments
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.

1 participant