npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

botbuilder-forms

v1.0.4

Published

A simple module that allows you to easily add form flows to the Node Bot Builder SDK.

Downloads

21

Readme

Form Builder

Build Status JavaScript Style Guide npm version

A simple module that allows you to add form flows to the Node Bot Builder SDK.

Installation

npm install botbuilder-forms

Usage

const builder = require('botbuilder')
const formBuilder = require('botbuilder-forms')

let connector = new builder.ConsoleConnector().listen()
var bot = new builder.UniversalBot(connector, [
  function (session) {
    session.beginDialog('FormBuilder:/', {questions: questions})
  },
  function (session, results) {
    console.log(results)
  }
])

let questions = [
  {
    field: 'Number',
    question: 'What is your mobile number?',
    prompt: 'Is this your phone number: {Number}?',
    validation: '^(07[0-9]{8,12}|447[0-9]{7,11})$',
    repromptText: 'Sorry, that doesn\'t look right. Please enter a valid mobile number beginning with 07 or +447'
  },
  {
    field: 'Postcode',
    question: 'What is your postcode?'
  }
]

bot.library(formBuilder.createLibrary())

Questions

The questions object is passed into the dialog through the dialog arguments parameter. The questions object can consist of the following properties:

  • field
  • question
  • prompt
  • validation
  • repromptText

The only mandatory properties are field and question, unless you are planning on passing entities as well, in which case the prompt and repromptText fields also become mandatory. The validation property consists of a regex string, which is later converted to a RegExp.

Entities

Entities can be passed to the form builder via the arguments parameter. In order to format them correctly, the entityCheck helper has been included. It takes the following arguments:

  • {array} entities - An array of entity data that been returned from LUIS.
  • {array} requirements - An array of entity titles that you want to detect.
  • {integer} threshold - The minimum LUIS confidence threshold that you want each entity to meet.
  • {function} callback - A callback to return the results.

It can be used as following:

  bot.dialog('EntityExample', [
    function (session, args, next) {
      formBuilder.entityCheck(args.entities, ['Number'], 0.7, function (data) {
        session.dialogData.entities = data
      })
      builder.Prompts.confirm(session, 'Do you want to proceed?')
    },
    function (session, results) {
      session.beginDialog('FormBuilder:/', {questions: questions, entities: session.dialogData.entities})
    },
    function (session, results) {
      console.log(results)
      session.endDialog('Thank you for completing the form.')
    }
  ])

  let questions = [
    {
      field: 'Number',
      question: 'What is your mobile number?',
      prompt: 'Is this your phone number: {Number}?',
      validation: '^(07[0-9]{8,12}|447[0-9]{7,11})$',
      repromptText: 'Sorry, that doesn\'t look right. Please enter a valid mobile number beginning with 07 or +447'
    },
    {
      field: 'Postcode',
      question: 'What is your postcode?'
    }
  ]

A working example can be found in examples/entities.js. Simple run npm install and node examples/entities.

Examples

The following examples are available:

Basic

Basic form flow without LUIS entities. Run with node examples/basic.

Entities

Similar form flow to 'Basic' example, however, it makes use of the entityCheck helper to process any entities LUIS has identified. Run with node examples/entities.

Tests

npm test

Contributing

Pull requests are more than welcome. Please ensure you abide by Standard JS coding standards.