node package manager

botmaster-fulfill

Build Status Coverage Status

Botmaster fulfill

Battle-tested middleware for botmaster https://botmasterai.github.io/).

Enable chatbots to perform actions on Node.js.

Developers write "action specs" that specify how an XML tag should be replaced in a chatbot response, such as confirming that the action was performed simply returning an empty string so that the tag is removed.

Chatbot designers then place the XML tags in their flows for easy integration.

Also check out our pre-made actions:

Actions Repository
pause, greet botmaster-fulfill-actions
button, buttons botmaster-button

Quick start

const Botmaster = require('botmaster');
const {fulfillOutgoingWare} = require('botmaster-fulfill');
const botsSettings = require('./my-bots-settings');
const botmaster = new Botmaster({botsSettings});
const actions = {
        hi: {
            controller: () => 'hi there!'
        },
        bye: {
            controller: () => 'bye please come again'
        }
}
botmaster.use('outgoing', outgoing({actions}));
botmaster.once('update', bot => bot.sendMessage('<hi />'));
botmaster.once('update', bot => bot.sendMessage('<bye />'));

API Reference

isPendingActions

Test for remaining actions in a string

Parameters

  • string String input string to test for actions
  • actions Object actions to test for

Returns Boolean whether any actions were found

fulfill

Fulfill any actions found in the input text

Parameters

  • actions Object actions to run
  • context Object an object of aditional properties to expost though params
  • input String the string to look for actions in
  • tree Array? provided as a way to speed up recursion. You probably don't need to use this and providing it without fulfillPromise (or vice versa) will cause an error.
  • fulfillPromise Array? Used to let controllers know that fulfill has completed (or hit an error) even though this is a recursed function. You probably don't need to use this.
  • cb Function error first callback

defaultInput

Default function to extraxt input for fulfill from botmaster context. Uses simply message.message.text. If it does not exist then fulfill does not run.

Parameters

  • $0 Object object consisting of botmaster objects and next
    • $0.message Object the botmaster message

defaultResponse

Default function to update botmaster middleware context with fulfill response and call next. It only sets message.message.text if the response is a non empty string after trimming. Otherwise it calles next with an error.

Parameters

  • $0 Object object consisting of botmaster objects, fulfill response, and next
    • $0.message Object botmaster message
    • $0.next Function next function from botmaster outgoing middleware
    • $0.response String respopnse from fulfill

FulfillWare

Generate outgoing middleware for fulfill

Parameters

  • options
    • options.actions Object the actions to use
    • options.inputTransformer Function? a function that receives {bot, message, update} and returns the fulfill input or a falsy value to skip running fulfill.
    • options.reponseTransformer Function? a function that receives ({bot, message, update, response, next}) updates the message and calls next.
    • options.params Object? an object of additional names to provide in params.

Returns function outgoing middleware