Skip to content

Commit 5535581

Browse files
ernadoclaude
andcommitted
fix(examples/rich): drop inline ctors the server rejects in rich messages
/text triggered RICH_VALIDATE_CTOR_NOT_ALLOWED: Mention, Hashtag, Cashtag, BotCommand and BankCard map to telegram_api RichText ctors the Telegram server does not accept raw. The official server (WebPageBlock.cpp get_input_rich_text) reduces them to their inner plain text before sending, so a direct MTProto send is rejected. Remove them, keep MentionName and Date (both kept by the server), and update the doc comment and CHANGELOG allowlist. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f796743 commit 5535581

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ messages follow [Conventional Commits](https://www.conventionalcommits.org/).
2121
`SendRichMarkdown` send structured page-block content built with
2222
`github.com/gotd/td/telegram/message/rich`. The `examples/rich` bot showcases
2323
the page-block and rich-text constructors valid in a bot-sent message.
24-
(Instant-View-page-only blocks — Title, Subtitle, Header, Subheader, Kicker,
25-
AuthorDate, Cover, RelatedArticles — and the auto-link inline styles are
26-
rejected by the server with `RICH_VALIDATE_CTOR_NOT_ALLOWED`.)
24+
(Instant-View-page-only constructors are rejected by the server with
25+
`RICH_VALIDATE_CTOR_NOT_ALLOWED`: page blocks Title, Subtitle, Header,
26+
Subheader, Kicker, AuthorDate, Cover, RelatedArticles; and inline styles
27+
Mention, Hashtag, Cashtag, BotCommand, BankCard, AutoURL/AutoEmail/AutoPhone.)
2728
- **Background sends**`Bot.Background()` / `Context.Background()` expose a
2829
run-lifetime context for proactive sends to any chat from timers, queues or
2930
goroutines, instead of the per-update handler context. Plus `Bot.Logger()`.

examples/rich/main.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
// /map a map block
1111
// /media photo/audio/image/custom-emoji/collage/slideshow (need real ids)
1212
//
13-
// Not every page block is valid in a bot-sent rich message. Per the official Bot
14-
// API server (telegram-bot-api, td/td/telegram/WebPageBlock.cpp), these are
15-
// Instant-View-page-only and the server rejects them with
16-
// RICH_VALIDATE_CTOR_NOT_ALLOWED, so they are intentionally not used here:
17-
// Title, Subtitle, Header, Subheader, Kicker, AuthorDate, Cover,
18-
// RelatedArticles — and the inline auto-link styles (AutoURL/AutoEmail/
19-
// AutoPhone). Video is omitted too.
13+
// Not every constructor is valid in a bot-sent rich message. Per the official
14+
// Bot API server (telegram-bot-api, td/td/telegram/WebPageBlock.cpp), these are
15+
// Instant-View-page-only: the server reduces them to plain text or drops them,
16+
// and Telegram rejects them raw with RICH_VALIDATE_CTOR_NOT_ALLOWED, so they are
17+
// intentionally not used here. Page blocks: Title, Subtitle, Header, Subheader,
18+
// Kicker, AuthorDate, Cover, RelatedArticles. Inline text: Mention, Hashtag,
19+
// Cashtag, BotCommand, BankCard and the auto-link styles AutoURL/AutoEmail/
20+
// AutoPhone (MentionName and Date are allowed). Video is omitted too.
2021
//
2122
// Run it with an MTProto app identity (https://my.telegram.org) and a BotFather
2223
// token. To exercise /media's media-by-id blocks, also set any of PHOTO_ID,
@@ -103,12 +104,7 @@ func main() {
103104
rich.Plain(", inline math "), rich.Math("a^2+b^2=c^2"),
104105
)),
105106
rich.Paragraph(rich.Concat(
106-
rich.Mention(rich.Plain("@durov")), sp(),
107-
rich.MentionName(rich.Plain("Ada"), 1), sp(),
108-
rich.Hashtag(rich.Plain("#golang")), sp(),
109-
rich.Cashtag(rich.Plain("$TON")), sp(),
110-
rich.BotCommand(rich.Plain("/start")), sp(),
111-
rich.BankCard(rich.Plain("4111111111111111")),
107+
rich.Plain("mention by name: "), rich.MentionName(rich.Plain("Ada"), 1),
112108
)),
113109
rich.Paragraph(rich.Concat(
114110
rich.Email(rich.Plain("hi@example.com"), "hi@example.com"), sp(),

0 commit comments

Comments
 (0)