bottender-form

0.2.1 • Public • Published

bottender-form

npm Build Status License: MIT

An experimental package for handling conversational form with Bottender.

Installation

npm install bottender-form

Usage

const { middleware } = require('bottender');
const form = require('bottender-form');
 
const handleForm = form({
  name: 'user',
  shouldStart: context => context.event.text === '/form',
  steps: [
    {
      question: "What's your name?",
      stateKey: 'user.name',
    },
    {
      question: 'How old are you?',
      validation: text => /\d+/.test(text),
      map: numstr => +numstr,
      stateKey: 'user.age',
    },
  ],
});
 
bot.onEvent(
  middleware([
    handleForm,
    async context => {
      if (context.event.isMessage) {
        await context.sendText(`user: ${JSON.stringify(context.state.user)}`);
      }
    },
  ])
);

Options

name

text

shouldStart

Default: () => false.

shouldStop

Default: () => false.

retryMessage

Default: Validation failed. Please try again..

retryTimes

Default: 3.

didFinish

Default: () => {}.

Step

question

text | async context => void

stateKey

text

validation

text => boolean | async text => boolean

map

text => any

License

MIT © Yoctol

/bottender-form/

    Package Sidebar

    Install

    npm i bottender-form

    Weekly Downloads

    10

    Version

    0.2.1

    License

    MIT

    Last publish

    Collaborators

    • chentsulin
    • etrexkuo
    • tw0517tw
    • link515