Have ideas to improve npm?Join in the discussion! ¬Ľ

    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

    Install

    npm i bottender-form

    DownloadsWeekly Downloads

    3

    Version

    0.2.1

    License

    MIT

    Last publish

    Collaborators

    • avatar