botmasterai / botmaster-fulfill

a text-friendly way to integrate actions with your bot. Supply an object of action-functions that can return synchronously or asynchronously and replace text in the response, generate new responses, or do what the response claims to do.
MIT License
4 stars 2 forks source link

Build Status Coverage Status

Botmaster fulfill

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

Now updated to handle malformed tags! This is a breaking change since it requires negative look-behind in nodejs, so only nodejs > 9 is supported. You can get it at

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

// 1. Import botmaster and setup your bots, for example telegram
const Botmaster = require('botmaster');
const Telegram = require('botmaster-telegram');
const telegramSettings = require('./my-telegram-bots-settings');
const botmaster = new Botmaster();
const telegramBot = new TelegramBot(telegramSettings);
botmaster.addBot(TelegramBot);

// 2. set up any incoming middleware that you might need

// 3. at the end set up fulfill outgoing ware...
const {fulfillOutgoingWare} = require('botmaster-fulfill');
const actions = {
        hi: {
            controller: () => 'hi there!'
        },
        bye: {
            controller: () => 'bye please come again'
        }
}
botmaster.use(fulfillOutgoingWare({actions}));

// Profit. Any messages that telegram bot sends will be processed by fulfill
telegramBot.sendTextMessageTo('<hi />', 1234);
telegramBot.sendTextMessageTo('<bye />', 1234);

API Reference

isPendingActions

Test for remaining actions in a string

Parameters

Returns Boolean whether any actions were found

fulfill

Fulfill any actions found in the input text

Parameters

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

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 calls next with "cancels" which cancels the outgoing message.

Parameters

FulfillWare

Generate outgoing middleware for fulfill

Parameters

Returns function outgoing middleware