Skip to content

A framework for supporting naive conversation state flow

License

Notifications You must be signed in to change notification settings

dsullivan7/chatbot-flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 [email protected]

About

A framework for supporting naive conversation state flow

Resources

License

Stars

Watchers

Forks

Packages

No packages published