bottender-recognizer
v0.3.0
Published
Build bottender bots with intent recognizer and action resolver.
Downloads
4
Readme
bottender-recognizer
Build bottender bots with intent recognizer and action resolver.
Installation
npm install bottender-recognizer
Definition
Recognizer
(state, event) => intent | undefined
Example:
async (state, intent) => ({
name: 'INTENT_NAME',
payload: {},
});
Intent
name
- Must have.payload
- Recommended.
Example:
{
name: "INTENT_NAME",
payload: {}
}
Resolver
(state, intent) => action
Example:
(state, intent) => doSomething;
With derivedState
and derivedParam
:
(state, intent) => derivedState + derivedParam + action
Example:
(state, intent) => ({
action: doSomething,
derivedState: {
x: 1,
},
derivedParam: {
y: 2,
},
});
Action
context => void
Example:
async context => {
// ...
};
With parameters:
context + param => void
Example:
async (context, param) => {
// ...
};
API Reference
createHandler({ recognizer, resolver, chatbase, debug })
It creates a bottender handler function.
createHandler({
recognizer,
resolver,
chatbase: {
apiKey: process.env.CHATBASE_KEY,
platform: 'Facebook',
},
debug: true,
});
combineRecognizers(recognizers)
It turns an array of recognizers into a single recognizer that you can pass to createHandler
.
const regex = (state, event) => {
if (event.isText && /^Hi$/i.test(event.text)) {
return {
name: 'GREETING',
payload: {
// other args...
},
};
}
};
const nlu = async (state, event) => {
//...
};
combineRecognizers([regex, nlu]);
License
MIT © Yoctol