/lumex:rich-messagesfrom lumex
Builds, sends, edits and reads Telegram rich messages using kbgod/lumex: Markdown, HTML or explicit blocks, media, tables, lists, buttons, maps, formulas, streaming drafts and common pitfalls.
Ships in lumex. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A rich message is a structured message: headings, paragraphs, lists,
tables, media blocks, quotations, collapsible details, footnotes, formulas,
maps and buttons inside the message itself. It is sent with sendRichMessage,
not sendMessage, and described by an *lumex.InputRichMessage.
Use a plain sendMessage + ParseMode for chat-style text. Reach for a rich
message when the content has structure: a report, a receipt, a table of
results, an article, an answer with code and formulas, a card with buttons.
msg := lumex.MarkdownRichMessage("# Order #42\n\n**Total:** 12.50 €")
// In a handler — there is no Context shortcut, call the method through ctx.Bot:
_, err := ctx.Bot.SendRichMessage(ctx.Context(), ctx.ChatID(), msg)
// Optional parameters work as for any send method:
_, err = ctx.Bot.SendRichMessage(ctx.Context(), ctx.ChatID(), msg, lumex.SendRichMessageOpts{
ReplyMarkup: lumex.NewInlineMenu().Row(lumex.CallbackBtn("Pay", "pay:42")).Unwrap(),
ReplyParameters: &lumex.ReplyParameters{MessageID: replyTo},
})
Rich content is accepted in a few more places:
| Where | How |
|---|---|
| edit a message (text or rich) | bot.EditMessageText(ctx, lumex.EditMessageTextOpts{ChatID: …, MessageID: …, RichMessage: msg}), or in a handler ctx.EditMessageText("", lumex.EditMessageTextOpts{RichMessage: msg}) (the empty text is left out) |
| edit an ephemeral message | bot.EditEphemeralMessageText(ctx, chatID, receiverID, ephemeralID, lumex.EditEphemeralMessageTextOpts{RichMessage: msg}) |
| an inline query result | &lumex.InputRichMessageContent{RichMessage: msg} as a result's InputMessageContent — only previously uploaded files |
| a streamed draft | bot.SendRichMessageDraft(ctx, chatID, draftID, msg, opts) — see §8 |
An InputRichMessage takes exactly one of HTML, Markdown or Blocks.
| Use it when | Constructor | |
|---|---|---|
| Markdown | the text is written by a person or a model; quickest to type. GitHub-flavoured, may embed HTML tags | lumex.MarkdownRichMessage(md) |
| HTML | the content comes from a template, or needs something Markdown has no syntax for (underline, sub/superscript, anchors, pull quotes, maps, collage captions, buttons) | lumex.HTMLRichMessage(html) |
| Blocks | the content is assembled in code from data: rows of a table, items of a slice, user input. No escaping, type-checked, and files upload through InputFile | lumex.BlocksRichMessage(blocks...) |
Escape user data in HTML and Markdown. A username with < or * breaks the
markup or changes its meaning. For HTML use html.EscapeString (numeric entities
such as ' are supported; of the named ones only < > & " ' … — – ‘ ’ “ ” are).
When most of the content is data, build blocks instead: a PlainText is never
parsed.
Fluent options on any of the three (each returns the message, so they chain):
msg := lumex.HTMLRichMessage(body).
RTL(). // shown right-to-left
SkipEntities(). // no automatic links, @mentions, #hashtags, phone numbers, …
AddMedia(lumex.RichMedia("p1", lumex.NewInputMediaPhoto(lumex.InputFileID(fileID))))
Inline: **bold**, *italic*, ~~strike~~, `code`, ==marked==,
||spoiler||, [link](https://…), [mail](mailto:…), [call](tel:…),
[mention](tg://user?id=…),  (custom emoji),
, $x^2$ (formula),
text[^note] + [^note]: footnote.
Blocks: #…###### headings, paragraphs, fenced code with a language,
--- divider, -/*/+ and 1. lists, - [ ] / - [x] task lists, >
quotations, GFM tables (:--- / :---: / ---: alignment), $$…$$ or
```math formula blocks,  media.
HTML-only (also usable inside Markdown): <u>, <sub>, <sup>,
<a name="x"></a> anchors and <a href="#x"> links to them,
<tg-reference name="n"> + <a href="#n">, <aside>pull quote<cite>Author</cite></aside>,
<blockquote expandable>, <details open><summary>…</summary>…</details>,
<footer>, <tg-map lat long zoom/>, <tg-collage> / <tg-slideshow> with
<figcaption>, <figure> captions, <img tg-spoiler/>,
<tg-button type="url|callback_data|web_app|login_url|switch_inline_query|…">
and <tg-button-row align="left|center|right">, <tg-thinking> (drafts only).
The full list is in the Bot API docs, "Rich Message Formatting Options".
Rules worth remembering:
tg://…?id=
links (§4) — never inline in a sentence.<details>,
<tg-collage> and <tg-slideshow>.Every block has a generated constructor lumex.NewInputRichBlock<Kind>(required…)
that returns a pointer; set optional fields on it afterwards. The type
discriminator is filled in when the block is marshalled — never set Type.
| Block | Constructor (required args) | Optional fields |
|---|---|---|
| paragraph | NewInputRichBlockParagraph(text) | |
| heading | NewInputRichBlockSectionHeading(text, size) — size 1 (largest) … 6 | |
| code block | NewInputRichBlockPreformatted(text) | Language |
| footer | NewInputRichBlockFooter(text) | |
| divider | NewInputRichBlockDivider() | |
| formula | NewInputRichBlockMathematicalExpression(latex) | |
| anchor | NewInputRichBlockAnchor(name) | |
| list | NewInputRichBlockList(items) | per item: HasCheckbox, IsChecked, Value, Type (label of an ordered list) |
| quotation | NewInputRichBlockBlockQuotation(blocks) | Credit |
| expandable quotation | NewInputRichBlockExpandableBlockQuotation(blocks) | Credit |
| pull quotation | NewInputRichBlockPullQuotation(text) | Credit |
| details (collapsible) | NewInputRichBlockDetails(summary, blocks) | IsOpen |
| table | NewInputRichBlockTable(cells) | IsBordered, IsStriped, IsCompact, Caption |
| collage | NewInputRichBlockCollage(blocks) | Caption |
| slideshow | NewInputRichBlockSlideshow(blocks) | Caption |
| map | NewInputRichBlockMap(&lumex.Location{Latitude: …, Longitude: …}) | Zoom (0-24), Width, Height, Caption |
| photo / video / animation | NewInputRichBlockPhoto(lumex.NewInputMediaPhoto(file)), …Video, …Animation | Caption |
| audio / voice note / document | NewInputRichBlockAudio(…), …VoiceNote(…), …Document(…) | Caption |
| buttons | prefer lumex.NewRichMenu() (§6) | Align |
| "Thinking…" placeholder | NewInputRichBlockThinking(text) — drafts |
text, summary, Credit and a table's Caption are RichText (§5). Media,
collage, slideshow and map captions are *lumex.RichBlockCaption{Text, Credit}.
items := make([]lumex.InputRichBlockListItem, 0, len(tasks))
for _, t := range tasks {
items = append(items, lumex.InputRichBlockListItem{
Blocks: []lumex.InputRichBlock{lumex.NewInputRichBlockParagraph(lumex.PlainText(t.Title))},
HasCheckbox: true,
IsChecked: t.Done,
})
}
code := lumex.NewInputRichBlockPreformatted(lumex.PlainText(`fmt.Println("hi")`))
code.Language = "go"
more := lumex.NewInputRichBlockDetails(lumex.PlainText("Show the log"), []lumex.InputRichBlock{
lumex.NewInputRichBlockPreformatted(lumex.PlainText(logTail)),
})
msg := lumex.BlocksRichMessage(
lumex.NewInputRichBlockSectionHeading(lumex.PlainText("Today"), 1),
lumex.NewInputRichBlockList(items),
code,
more,
lumex.NewInputRichBlockFooter(lumex.PlainText("Updated just now")),
)
Container blocks (quotations, details, list items, collages, slideshows) take
[]lumex.InputRichBlock, so they nest — up to 16 levels.
NewInputRichBlockTable takes rows of lumex.RichBlockTableCell. Align and
Valign have no omitempty — set both on every cell. A small helper keeps it
readable:
cell := func(s string, header bool) lumex.RichBlockTableCell {
return lumex.RichBlockTableCell{
Text: lumex.PlainText(s),
IsHeader: header,
Align: lumex.RichBlockTableCellAlignLeft,
Valign: lumex.RichBlockTableCellValignMiddle,
}
}
rows := [][]lumex.RichBlockTableCell{{cell("Item", true), cell("Qty", true)}}
for _, it := range order.Items {
rows = append(rows, []lumex.RichBlockTableCell{cell(it.Name, false), cell(strconv.Itoa(it.Qty), false)})
}
table := lumex.NewInputRichBlockTable(rows)
table.IsStriped = true
Colspan / Rowspan merge cells; a cell without Text is invisible. At most
20 columns.
In blocks a media block wraps the usual InputMedia constructor, so any
InputFile works — InputFileID, InputFileURL, InputFileReader, or
InputFilePath (which opens the file, hence its error). Files nested anywhere
in the blocks are collected and uploaded automatically (multipart); nothing to
do by hand. The media's own caption is ignored — put it on the block:
chart, err := lumex.InputFilePath("chart.png")
if err != nil {
return err
}
photo := lumex.NewInputRichBlockPhoto(lumex.NewInputMediaPhoto(chart))
photo.Caption = &lumex.RichBlockCaption{Text: lumex.PlainText("Sales, Q3")}
gallery := lumex.NewInputRichBlockCollage([]lumex.InputRichBlock{photo, otherPhoto})
In HTML / Markdown a media block is either an HTTP(S) URL Telegram fetches
itself, or a tg://photo?id=…, tg://video?id=…, tg://document?id=… or
tg://audio?id=… link bound to a file with AddMedia(RichMedia(id, media)) —
that's how you upload a local file or reuse a file_id. Ids are 1-64 characters
of A-Z a-z 0-9 _ -. In Markdown the brackets stay empty and a caption is a
quoted title after the URL:
report, err := lumex.InputFilePath("q3.pdf")
if err != nil {
return err
}
msg := lumex.MarkdownRichMessage("Here's the report:\n\n").
AddMedia(lumex.RichMedia("r1", lumex.NewInputMediaDocument(report)))
No new uploads (and no URL uploads) in drafts, in inline query results, or when
editing an inline message: use files Telegram already has (InputFileID).
RichTextEvery text slot of a block is a lumex.RichText — a union that is a plain
string, an array of rich texts, or one of the formatting types.
lumex.PlainText("…") — a plain string (never parsed, so safe for user input).lumex.RichSequence(parts...) — several parts in a row.&lumex.RichTextBold{Text: …}, RichTextItalic, RichTextUnderline,
RichTextStrikethrough, RichTextSpoiler, RichTextCode, RichTextMarked,
RichTextSubscript, RichTextSuperscript (all {Text});
RichTextURL{Text, URL}, RichTextEmailAddress{Text, EmailAddress},
RichTextPhoneNumber{Text, PhoneNumber}, RichTextMention{Text, Username},
RichTextTextMention{Text, User}, RichTextHashtag, RichTextCashtag,
RichTextBotCommand, RichTextBankCardNumber, lumex.TONAddress(addr, label...);
RichTextCustomEmoji{CustomEmojiID, AlternativeText},
RichTextDateTime{Text, UnixTime, DateTimeFormat},
RichTextMathematicalExpression{Expression} (inline LaTeX);
RichTextAnchor{Name} / RichTextAnchorLink{Text, AnchorName} (in-message
links; an empty name jumps to the top), RichTextReference{Text, Name} /
RichTextReferenceLink{Text, ReferenceName} (footnotes);
RichTextButton{Button} — a button inside the text.Formatting nests (Bold{Text: Italic{…}}). Small local helpers read best:
bold := func(s string) lumex.RichText { return &lumex.RichTextBold{Text: lumex.PlainText(s)} }
link := func(s, url string) lumex.RichText { return &lumex.RichTextURL{Text: lumex.PlainText(s), URL: url} }
p := lumex.NewInputRichBlockParagraph(lumex.RichSequence(
lumex.PlainText("Your order "), bold("#42"), lumex.PlainText(" is ready — "),
link("track it", "https://example.com/t/42"), lumex.PlainText("."),
))
lumex.NewRichMenu() builds a buttons block: one row of 1-8 buttons with a
shared alignment. Styles: RichMessageButtonStyleDanger, …Success,
…Primary, …Link (a borderless link — callback buttons only).
buttons := lumex.NewRichMenu(lumex.WithRichMenuAlign(lumex.InputRichBlockButtonsAlignCenter)).
CallbackBtn("Approve", "order:approve:42", lumex.RichMessageButtonStyleSuccess).
CallbackBtn("Reject", "order:reject:42", lumex.RichMessageButtonStyleDanger).
URLBtn("Details", "https://example.com/o/42").
Unwrap()
msg := lumex.BlocksRichMessage(paragraph, buttons)
Also .WebAppBtn (private chats only), .LoginBtn, .SwitchInlineQueryBtn,
.SwitchInlineCurrentChatBtn, and .Btn(lumex.RichMessageButton{…}) for the
rest (copy-text, disabled, chosen-chat switch, a rich-text label). A button's
label may hold only plain text, custom emoji and date-time. Callback buttons
arrive as ordinary callback_query updates — route them with
OnCallbackPrefix etc. A regular inline keyboard under the message still works
through ReplyMarkup.
msg.RichMessage (*lumex.RichMessage{Blocks []lumex.RichBlock, IsRtl}) is set
on a message that carries one; route with r.OnRichMessage(handler).
RichBlock and RichText are unions with many variants, so use a type switch
(there are no As…() accessors for them):
for _, b := range ctx.Message().RichMessage.Blocks {
switch b := b.(type) {
case *lumex.RichBlockParagraph:
// b.Text is a RichText
case *lumex.RichBlockTable:
// b.Cells
}
}
lumex.DecodeRichBlock(raw) / lumex.DecodeRichText(raw) decode raw JSON.
For output produced over time (a model's answer), stream a draft into a private chat, then send the final message:
const draftID = 1 // non-zero; reuse it so updates animate instead of replacing
_, _ = ctx.Bot.SendRichMessageDraft(ctx.Context(), chatID, draftID,
lumex.BlocksRichMessage(lumex.NewInputRichBlockThinking(lumex.PlainText("Thinking…"))))
for partial := range chunks {
_, _ = ctx.Bot.SendRichMessageDraft(ctx.Context(), chatID, draftID, lumex.MarkdownRichMessage(partial),
lumex.SendRichMessageDraftOpts{CanStop: true})
}
_, err := ctx.Bot.SendRichMessage(ctx.Context(), chatID, lumex.MarkdownRichMessage(final))
A draft is an ephemeral ~30-second preview; only sendRichMessage keeps the
message. CanStop shows a stop button, whose press arrives as a
stopped_message_generation update. Drafts can't upload new files.
Split longer content over several messages rather than truncating mid-block.
PlainText.&lumex.RichTextBold{…}), strings
through PlainText.Align and Valign.InputMedia. with empty
brackets, each id bound with AddMedia(RichMedia(…)).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub kbgod/lumex --plugin lumex5 skills in this plugin
/dialog-flowsBest practices for building multi-step conversation flows (wizards / FSM) with the kbgod/lumex Telegram framework — collecting inputs across states (ask name → city → photo → confirm), local fallbacks for invalid input, cancel/back navigation, state persistence, and naming conventions. Use whenever the user wants a bot that asks the user for information step by step, a multi-step form, a wizard, or a stateful dialog. Pairs with the `lumex` skill (framework reference); this one is the flow playbook./lumexHow to build Telegram bots with the kbgod/lumex Go framework (github.com/kbgod/lumex/v2). Use whenever writing or reviewing lumex bot code: the typed Bot API client, the router (handlers, filters, middleware, groups, FSM state), the Context helpers (Reply/Answer/Edit/…), the menu & rich-message builders, and long-polling or webhook wiring. NOT about the code generator — for that read CLAUDE.md./mini-app-authHow to authenticate Telegram Mini App (Web App) users on a Go backend next to a kbgod/lumex bot: send Telegram.WebApp.initData (never initDataUnsafe) to the server, parse it into a map of every field — not a fixed struct, or new fields break verification — and verify it either with the bot token (HMAC "hash", for your own bot) or with Telegram's Ed25519 public key ("signature", for another bot's Mini App, with an allowlist of bot ids); the exact data-check-string rules for each, auth_date freshness, constant-time comparison, duplicate keys, the test-environment key, sessions and replay. Use whenever a Mini App calls a backend, or a service accepts initData from Telegram. Pairs with the `lumex` skill (framework reference)./telegram-widgetsHow to write Telegram HTML widgets (Bot API 10.4) and drive them from a Go bot with kbgod/lumex: what HTML, CSS and JavaScript the widget sandbox supports and what it strips, the hard limits (32768/4096 bytes of HTML, 1024-byte state, 64-byte requests, 15 s to answer), the window.TelegramWidget API, static vs shared widgets and their two states, and the request cycle sendWidget → widget_query → answerWidgetQuery → editMessageWidgetData. Use whenever writing or reviewing widget HTML, or the bot handlers behind it. Pairs with the `lumex` skill (framework reference).Other plugins' skills for the same job