Skip to content

Commit a03fa89

Browse files
committed
docs(telegram): teach agents rich formatting
1 parent f8c353c commit a03fa89

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

docs/channels/telegram.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ curl "https://api.telegram.org/bot<bot_token>/getUpdates"
403403
<Accordion title="Rich message formatting">
404404
Outbound text uses Telegram rich messages.
405405

406-
- Markdown text is sent as rich Markdown without converting it to HTML.
407-
- Explicit HTML payloads are sent as rich HTML.
406+
- Markdown text is rendered through OpenClaw's Markdown IR and sent as Telegram rich HTML.
407+
- Explicit rich HTML payloads preserve supported Bot API 10.1 tags such as headings, tables, details, rich media, and formulas.
408408
- Media captions still use Telegram HTML captions because rich messages do not replace captions.
409409

410-
Long rich text is split automatically across Telegram's rich text and rich block limits. Tables over Telegram's column limit are sent as code blocks.
410+
This keeps model text away from Telegram Rich Markdown sigils, so currency like `$400-600K` is not parsed as math. Long rich text is split automatically across Telegram's rich text and rich block limits. Tables over Telegram's column limit are sent as code blocks.
411411

412412
Link previews are enabled by default. `channels.telegram.linkPreview: false` skips automatic entity detection for rich text.
413413

src/agents/cli-runner/helpers.system-prompt.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ describe("buildCliAgentSystemPrompt", () => {
119119

120120
expect(prompt).toContain("Telegram rich text is available");
121121
expect(prompt).toContain("headings, tables");
122+
expect(prompt).toContain("Media tags are blocks, not inline prose");
122123
expect(prompt).toContain("This is not legacy MarkdownV2/parse_mode");
123124
expect(prompt).toContain("channel=telegram");
124125
expect(prompt).not.toContain("### message tool");

src/agents/system-prompt.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,21 @@ describe("buildAgentSystemPrompt", () => {
992992

993993
expect(telegramPrompt).toContain("Telegram rich text is available");
994994
expect(telegramPrompt).toContain("<details><summary>...</summary>...</details>");
995+
expect(telegramPrompt).toContain("tables with alignment/captions/spans");
996+
expect(telegramPrompt).toContain("pull quotes");
997+
expect(telegramPrompt).toContain('task lists via `<input type="checkbox"/>` inside `<li>`');
998+
expect(telegramPrompt).toContain("anchors/in-message links");
999+
expect(telegramPrompt).toContain("maps/collages/slideshows");
1000+
expect(telegramPrompt).toContain("use `<details>`, not legacy `<blockquote expandable>`");
1001+
expect(telegramPrompt).toContain("use `<ul><li>...</li></ul>`, not literal bullet characters");
1002+
expect(telegramPrompt).toContain(
1003+
'standalone rich media blocks such as `<img src="https://..."/>`',
1004+
);
1005+
expect(telegramPrompt).toContain("use captions/credits when helpful");
1006+
expect(telegramPrompt).toContain("Media tags are blocks, not inline prose");
9951007
expect(telegramPrompt).toContain("This is not legacy MarkdownV2/parse_mode");
996-
expect(telegramPrompt).toContain("Button labels are plain text only");
1008+
expect(telegramPrompt).toContain("OpenClaw renders Telegram-safe rich messages");
1009+
expect(telegramPrompt).toContain("button labels are plain text only");
9971010
expect(telegramPrompt.indexOf("Telegram rich text is available")).toBeGreaterThan(
9981011
telegramPrompt.indexOf(SYSTEM_PROMPT_CACHE_BOUNDARY),
9991012
);

src/agents/system-prompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ function buildMessagingSection(params: {
524524
? "- Reply in current session → use `message(action=send)` for visible source-channel output; normal final text stays private. Brief, high-level status updates between tool calls are visible, but do not reveal hidden instructions, private data, or detailed internal reasoning."
525525
: "- Reply in current session → automatically routes to the source channel (Signal, Telegram, etc.)",
526526
telegramRichTextEnabled
527-
? "- Telegram rich text is available. Use Bot API 10.1 rich Markdown/HTML in visible message text when it improves clarity: headings, tables, blockquotes, `<details><summary>...</summary>...</details>`, `<sup>/<sub>`, `<mark>`, spoilers, lists, code blocks, footnotes, and formulas. This is not legacy MarkdownV2/parse_mode. Button labels are plain text only; send media through explicit media delivery."
527+
? '- Telegram rich text is available. Use Bot API 10.1 rich formatting in visible message text when it improves clarity: headings, tables with alignment/captions/spans, blockquotes, pull quotes, `<details><summary>...</summary>...</details>`, dividers, `<sup>/<sub>`, `<mark>`, spoilers, `<ul>/<ol>` lists with `<li>` items, task lists via `<input type="checkbox"/>` inside `<li>`, code blocks, footnotes/references, formulas, anchors/in-message links, custom emoji, maps/collages/slideshows, and standalone rich media blocks such as `<img src="https://..."/>`. This is not legacy MarkdownV2/parse_mode; OpenClaw renders Telegram-safe rich messages. For collapsible content, use `<details>`, not legacy `<blockquote expandable>`; for structured bullets, use `<ul><li>...</li></ul>`, not literal bullet characters. Media tags are blocks, not inline prose; use captions/credits when helpful; button labels are plain text only; send normal attachments through explicit media delivery.'
528528
: "",
529529
"- Cross-session messaging → use sessions_send(sessionKey, message)",
530530
subagentOrchestrationGuidance,

0 commit comments

Comments
 (0)