/lumex:dialog-flowsfrom lumex
Best practices for building multi-step conversation flows (wizards/FSM) with the kbgod/lumex Telegram framework. Covers state persistence, input validation, cancel/back navigation, and local fallbacks.
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 dialog flow collects input over several steps (e.g. name → city → photo). Each
step is a state (r.UseState), and a handler validates the input, saves it,
sets the next state, and prompts the next step. This builds directly on the
lumex skill — read its §6 (order matters) and §8 (UseState / state) first;
state is per-update, so you persist it in your own store and load it in a global
middleware.
Before scaffolding a flow, ask the user — both decisions change the code, and guessing wrong makes a worse bot. Use a clarifying question (e.g. AskUserQuestion):
OnUpdate fallback in each
waiting state that says "please send X"./cancel (abort the whole flow) and /back
(return to the previous step and re-ask). Ask which they want; both are common.Default recommendation if the user has no preference: local fallbacks on,
/cancel on, /back optional.
Register a waiting state's routes in this order (order matters — a command is
also a text message, so escape hatches must come before the generic input route,
or /cancel gets captured as the "name"):
enterName := r.UseState(StateEnterName)
enterName.OnCommand("cancel", h.CancelSignup) // 1. escape hatches — BEFORE the input route
enterName.OnCommand("back", h.EnteredNameBack) // 2. optional: go to the previous step
enterName.OnNonCommandText(h.EnteredName) // 3. the expected input
enterName.OnUpdate(h.InvalidName) // 4. local fallback: anything else in this state
OnText, a stray
/foo would be captured as the answer ("name: /foo"): OnText matches it, and
first-match-wins means OnUpdate never gets a look. OnNonCommandText excludes
commands, so /foo falls through to the step's fallback (4). Want a distinct
reply for unknown commands? Add enterName.OnAnyCommand(h.UnknownCommand) just
before the input route.OnMessage — a sticker/photo IS a message, so
matching only what you asked for makes wrong input fall to the fallback (4). Pick
the built-in that fits the step: OnNonCommandText (a text field), OnContact (a
shared phone number), OnPhoto/OnDocument/OnVideo (a media step), OnCaption
/ OnTextOrCaption (a captioned upload). If none fits, write a small custom
filter (lumex skill §7)./help) have to be declared
above the flow states — a state route never falls through to a later global one.OnUpdate registered inside the
state router, so it only fires in this state and (being registered before the
global fallback) shields the user from the generic "unknown command" reply.lumex skill §6/§8),
so per-state fallbacks win inside their state.State is persisted in your store; a global middleware loads it into ctx each
update (see lumex skill §8). Handlers mutate the persisted state:
// advance: save the value, set the NEXT state, prompt the next step
func (h *Handler) EnteredName(ctx *router.Context) error {
h.store.SaveName(ctx.Sender().ID, ctx.Message().Text)
h.store.SetState(ctx.Sender().ID, StateEnterCity)
return ctx.ReplyVoid("Which city are you in?")
}
// invalid input for this step (the local fallback)
func (h *Handler) InvalidName(ctx *router.Context) error {
return ctx.ReplyVoid("Please send your name as text.")
}
// back: set the PREVIOUS state and re-send its prompt
func (h *Handler) EnteredCityBack(ctx *router.Context) error {
h.store.SetState(ctx.Sender().ID, StateEnterName)
return ctx.ReplyVoid("What's your name?")
}
// cancel: clear the state, confirm
func (h *Handler) CancelSignup(ctx *router.Context) error {
h.store.ClearState(ctx.Sender().ID)
return ctx.ReplyVoid("Cancelled.")
}
The step that starts the flow (a command, a button, etc.) just sets the first
state and sends the first prompt — same shape as EnteredCityBack.
Keep flows readable by naming state, router, and handlers consistently:
| Thing | Convention | Example |
|---|---|---|
| State constant | State<Name> | StateEnterTaskName, StateEnterTaskDescription |
| State router var | camelCase of the state | enterTaskName := r.UseState(StateEnterTaskName) |
| Input handler | Entered<State> | h.EnteredTaskName, h.EnteredTaskDescription |
| Back handler | Entered<State>Back | h.EnteredTaskDescriptionBack (sets prev state + re-asks) |
| Invalid-input handler | Invalid<State> | h.InvalidTaskName |
| Cancel handler | named by the flow, not the step | h.CancelTaskCreation, h.CancelTaskUpdate (one per flow, reused across its steps) |
const (
StateEnterTaskName = "StateEnterTaskName"
StateEnterTaskDescription = "StateEnterTaskDescription"
)
// (elsewhere) StartTaskCreation: h.store.SetState(uid, StateEnterTaskName) + "Enter the task name:"
enterTaskName := r.UseState(StateEnterTaskName)
enterTaskName.OnCommand("cancel", h.CancelTaskCreation)
enterTaskName.OnNonCommandText(h.EnteredTaskName) // saves name → StateEnterTaskDescription
enterTaskName.OnUpdate(h.InvalidTaskName) // "Please send the task name as text."
enterTaskDescription := r.UseState(StateEnterTaskDescription)
enterTaskDescription.OnCommand("cancel", h.CancelTaskCreation)
enterTaskDescription.OnCommand("back", h.EnteredTaskDescriptionBack) // → StateEnterTaskName, re-asks name
enterTaskDescription.OnNonCommandText(h.EnteredTaskDescription) // saves desc → next step / finish
enterTaskDescription.OnUpdate(h.InvalidTaskDescription)
Restricting a whole flow to a role (e.g. admin-only): gate WHO enters the states
(only set StateEnterTaskName for admins) or put the flow behind an admin
filter/group — see the lumex skill §5/§7. Avoid nesting UseState inside
another UseState: a route carries only the innermost state, so the outer state
gate is lost.
cancel/back before the input route, input route
before the local OnUpdate fallback.OnNonCommandText/OnContact/OnPhoto/…),
so wrong input hits the local fallback, not the handler.OnNonCommandText, not OnText — otherwise a stray /foo is
saved as the answer.store.SetState), not just ctx.SetState.State…, Entered… / Entered…Back / Invalid… / Cancel<Flow>.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
telegram-bot, state-machine, conversation-flow, lumex, wizard
npx claudepluginhub kbgod/lumex --plugin lumex5 skills in this plugin
/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)./rich-messagesHow to build, send, edit and read Telegram rich messages with kbgod/lumex: choosing HTML, Markdown or explicit blocks; the ready-made constructors (HTMLRichMessage, MarkdownRichMessage, BlocksRichMessage, RichMedia, PlainText, RichSequence, TONAddress, NewRichMenu and the generated NewInputRichBlock* constructors); inline formatting with the RichText types; media, tables, lists, quotations, details, maps, formulas and in-message buttons; streaming drafts; the limits (32768 characters, 500 blocks, 16 nesting levels, 50 media, 20 table columns); and the usual mistakes. Use whenever a bot sends, edits or reads a rich message (sendRichMessage, rich_message, RichBlock, RichText). Pairs with the `lumex` skill (framework reference).Other plugins' skills for the same job