dsullivan7 / chatbot-flow

A framework for supporting naive conversation state flow

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Building Conversations for Chatbots

NPM version Build Status Coverage Status License

chatbot-flow is an implementation of finite state machines built with chatbot conversations in mind.

Install

npm install chatbot-flow

Usage

import {Flow} from 'chatbot-flow'

const flowConfig = {
  defaultState: 'ONE',
  states: {
    ONE: {
      next: 'TWO',
      message: {
        text: 'This is an initial statement that doesn\'t need a response',
      },
      noReply: true,
    },
    TWO: {
      next: 'END',
      message: {
        text: 'This is my first question',
      },
    },
    END: {
      noReply: true,
      next: null,
      message: user => ({
        text: `Your answer to my first question was "${user.responses.TWO.text}"`,
      }),
    },
  },
}

const flow = new Flow(flowConfig)

flow.getMessages('123', {text: 'Hey There'})
.then(messages => {
  /*
  messages:
  [{text: 'This is an initial statement that doesn\'t need a response'},
   {text: 'This is my first question'}]

  You can use send this array using whatever platform you choose: Facebook Messenger, Slack, etc...
  */
})
.then(() => flow.getMessages('123', {text: 'This is my answer'}))
.then(messages => {
  /*
  messages:
  [{text: 'Your answer to my first question was "This is my answer"'}]
  */
})

Contact

If you have any feedback, ideas, requests, or other thoughts, feel free to reach out to me at dbsullivan23@gmail.com

About

A framework for supporting naive conversation state flow

License:MIT License


Languages

Language:JavaScript 100.0%