AgentSkillsCN

add-wizard-step

【机器人开发者】为向导流程实现 WizardStep。适用于向导中新增步骤,或在 Telegram Bot 库中实现验证、状态存储,以及状态转换逻辑时使用。

SKILL.md
--- frontmatter
name: add-wizard-step
description: [Bot developer] Implements WizardStep for wizard flows. Use when adding a step to a wizard, implementing validation, state storage, or transitions in the telegram-bot library.

Add Wizard Step

Structure

Extend WizardStep. Override onEntry (required) and optionally validate, store, onRetry.

kotlin
object NameStep : WizardStep(isInitial = true) {
    override suspend fun onEntry(ctx: WizardContext) {
        message("What's your name?").send(ctx.user, ctx.bot)
    }
    override suspend fun validate(ctx: WizardContext): Transition {
        val text = (ctx.update as? MessageUpdate)?.message?.text ?: return Transition.Retry()
        return if (text.isNotBlank()) Transition.Next else Transition.Retry("Invalid")
    }
    override suspend fun store(ctx: WizardContext): String? =
        (ctx.update as? MessageUpdate)?.message?.text
}

Lifecycle Methods

MethodRequiredPurpose
onEntry(ctx)YesCalled when entering step. Send prompts, set keyboards.
validate(ctx)NoReturn Transition based on input. Default: Transition.Next
store(ctx)NoReturn value to persist. Type must match a state manager. Default: null
onRetry(ctx, reason)NoCalled when validation returns Transition.Retry. Default: no-op

Transitions

TransitionEffect
Transition.NextMove to next step in sequence
Transition.JumpTo(Step::class)Jump to specific step
Transition.Retry() or Transition.Retry("reason")Stay on step; onRetry is called
Transition.FinishEnd wizard

WizardContext

  • ctx.user, ctx.update, ctx.bot
  • ctx.getState(Step::class), ctx.setState(Step::class, value), ctx.delState(Step::class) — KSP generates type-safe accessors per step

Step ID

Override id if needed: override val id: String = "custom_id". Default: fully qualified class name.

Initial Step

Set isInitial = true on exactly one step. That step runs when the wizard starts.

Related Skills

  • build-wizard-flow — Full wizard flow overview
  • add-wizard-handler — Configure @WizardHandler (trigger, scope, state managers)

Reference