@botmesh/core - v2.0.0-alpha.2
    Preparing search index...

    Class FlowBuilder<S>

    Type Parameters

    Index
    • Present a numbered menu and capture the selection. The picked option KEY is stored in c.state[stateKey] (defaults to c.state.choice), so a later .say/.do can read it. An option's then sub-flow runs inline and returns here (sharing c.state); its goto leaves the flow for another conversation.

      Type Parameters

      • O extends Record<string, ChooseOption<S>>
      • K extends string = "choice"

      Parameters

      Returns FlowBuilder<FlowStateWith<S, K, Extract<keyof O, string>>>

    • Stop the flow unless check passes. On failure it sends onFail and ends the conversation, or — with { redirect } — jumps to another conversation:

      .guard(() => esHorarioLaboral(), 'Fuera de horario, vuelve mañana')
      .guard(async (ctx) => isAdmin(ctx.sender), { redirect: 'no-permiso' })

      Parameters

      Returns FlowBuilder<S>

    • Collect a typed form. On providers with capabilities.forms === 'native' (WhatsApp Cloud API → WhatsApp Flows) it sends one native form and waits for its submission; elsewhere it asks field by field. Either way the validated answers are stored in c.state[opts.stateKey ?? definition.id]. The definition is checked here: a malformed one throws a TypeError.

      Parameters

      Returns FlowBuilder<S>

      flow('registro')
      .form({ id: 'signup', title: 'Registro', fields: [
      { type: 'text', name: 'name', label: 'Nombre' },
      { type: 'email', name: 'email', label: 'Correo' },
      { type: 'select', name: 'plan', label: 'Plan', options: { basic: 'Básico', pro: 'Pro' } },
      ] })
      .say((_ctx, c) => `Gracias ${(c.state.signup as { name: string }).name}`)