Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
botmaster-button
Advanced tools
Battle-tested middleware for botmaster http://botmasterai.com/).
Easy cross-platform quick-reply buttons, even on those where only plain text is supported.
Find the documentation at the main botmaster website: http://botmasterai.com/middlewares/fulfill/
const Botmaster = require('botmaster');
const myBotmasterSettings = require('./my-botmaster-settings');
const {bootstrap} = require('botmaster-button');
const botmaster = new Botmaster(myBotmasterSettings);
const actions = {
itsComplicated: {
controller: () => `
<button>It's complicated because we want it to be that way.</button>
<button>It's complicated because life is complicated.</button>
<button>Mind your own business.</button>
`
}
};
bootstrap(botmaster, {
actions,
sessionPath: 'context',
confirmText: 'I am sorry I got multiple matches, can you please confirm.',
mainHandler: (bot, update) => bot.reply(update, `Could you please tell me about your relationship status?
<button image='https://images/ring.png'>I'm in a relationship</button>
<button>I'm not in a relationship.</button>
<button title='3. Its Complicated'><itsComplicated /></button>
`)
});
User sees in plain text channel:
1. I'm in a relationship
2. I'm not in a relationship
3. Its Complicated
They type "3." then they get:
1. It's complicated because we want it to be that way.
2. It's complicated because life is complicated.
3. Mind your own business.
User sees in messenger:
TODO
This package demonstrates the sandwich pattern for botmaster where incoming messages are preprocessed before sending to the main NLU handler and outgoing messages are processed after the main NLU.
It provides:
You can use one or all of these.
const R = require('ramda');
const Botmaster = require('botmaster');
const {EnrichIncomingWare} = require('botmaster-enrich');
const {fulfillOutgoingWare} = require('botmaster-fulfill');
const {ButtonAction, ButtonEnricher, ButtonHandler} = require('botmaster-button');
const myBotmasterSettings = require('./my-botmaster-settings');
const otherActions = require('my-other-actions');
const handler = require('my-handler');
const botmaster = new Botmaster(myBotmasterSettings);
const buttonAction = ButtonAction({sessionPath: 'context'});
const actions = R.merge({button: buttonAction}, otherActions);
const buttonEnricher = ButtonEnricher({actions});
botmaster.use('incoming', EnrichIncomingWare({buttonEnricher}));
botmaster.use('incoming', ButtonHandler({mainHandler: handler}));
botmaster.use('outgoing', fulfillOutgoingWare({actions}))
These buttons work by default through the standard quick-reply functionality where available in a bot class. (Such as in Facebook messenger)
If however the quick reply functionality is not available and you supply sessionPath
in the ButtonAction
options then the payload is stored through session storage and the user is expected to enter a keyword in the title which will generate the resulting payload.
Buttons can contain actions which will be evaluated before your update handlers if you pass an actions
property to ButtonEnricher
of actions that can performed on user input.
The title if not provided will default to the position that the button appears in the text followed by the payload.
Parameter | Description |
---|---|
inner tag content | The payload of the button. This is the input that botmaster will receive when the user clicks or signals the button |
image | url to an image for platforms that support images |
title | the text that the user sees as the button |
Path | Description |
---|---|
button.multiple | if true there are multiple button matches for the user's input |
button.matches | when there are multiple matches they are placed here. Each entry is a button object |
button | when there are not multiple matches button is a single button object. |
buttonPayloads | incoming buttons, these are removed after the button enricher is processed. Each entry follows the button object pattern |
Property | Description |
---|---|
payload | the text to pass to the update handler |
title | the text the user saw - the text to fuzzy match against |
image | the url for an image for the button |
For the truly lazy aka yours truly, a function that sets up button middleware and handler
Parameters
botmaster
Object an instantiated botmaster objectoptions
[Object]
options.actions
[Object] actions that can be invoked through buttonsoptions.sessionPath
[String] dot denoted path of where to get session/context in updatesoptions.confirmText
[String] what to say when we get multiple matches for a buttonButton fulfill action factory function
Parameters
options
OBject
options.sessionPath
String dot denoated path to prop where context is storedoptions.actions
Object actions that can be processedReturns Object action spec for
A botmaster-enrich session/context enricher. If user inputs fuzzy matches the title of a button the matched button is placed in 'button' in session/context. Multiple matches are stored in 'button.matches' and 'button.multiple' is set to true
Returns Object enricher spec
A botmaster update handler that passes through to main handler if there is no match at all or the match is not an action. If there are multiple possible matches to the button then it asks for confirmation.
Parameters
options
Object the options for generated middleware
options.mainHandler
Function the main handler to pass through to if there is no button matchedoptions.sessionPath
String dot denoted patch to session object where the 'button' property that stores button context is located. Defaults to 'session'.options.confirmText
String the text to use to confirm when there multiple matchesReturns Function a botmaster update handler
A botmaster incoming ware factory function that sets up button enricher
Parameters
options
[Object] options for the produced middleware
options.sessionPath
[String] dot denoted path to session in update defaults to "session"options.enrichers
[Object] other enrichers to also evaluateReturns Function botmaster incoming ware that evaluates buttons
Botmaster Button outgoing ware factory function
Parameters
options
[Object]
options.sessionPath
[String] dot denoted path to prop where context is storedoptions.actions
[Object] actions that can be processedReturns Function botmaster middleware for button
Action spec for buttons
<buttons>Option 1, Option 2</buttons>
Parameters
$0
$0.content
FAQs
Botmaster fulfill/enrich middleware for buttons
The npm package botmaster-button receives a total of 22 weekly downloads. As such, botmaster-button popularity was classified as not popular.
We found that botmaster-button demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.