https://github.com/bottenderjs/bottender-recognizer
Build bottender bots with intent recognizer and action resolver.
https://github.com/bottenderjs/bottender-recognizer
Last synced: 5 months ago
JSON representation
Build bottender bots with intent recognizer and action resolver.
- Host: GitHub
- URL: https://github.com/bottenderjs/bottender-recognizer
- Owner: bottenderjs
- License: mit
- Created: 2017-12-05T03:03:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-20T04:33:34.000Z (over 7 years ago)
- Last Synced: 2025-11-29T10:48:52.349Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 116 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# bottender-recognizer
[](https://www.npmjs.com/package/bottender-recognizer)
[](https://circleci.com/gh/Yoctol/bottender-recognizer)
[](https://opensource.org/licenses/MIT)
> Build bottender bots with intent recognizer and action resolver.
## Installation
```sh
npm install bottender-recognizer
```
## Definition
### Recognizer
```
(state, event) => intent | undefined
```
Example:
```js
async (state, intent) => ({
name: 'INTENT_NAME',
payload: {},
});
```
### Intent
* `name` - Must have.
* `payload` - Recommended.
Example:
```js
{
name: "INTENT_NAME",
payload: {}
}
```
### Resolver
```
(state, intent) => action
```
Example:
```js
(state, intent) => doSomething;
```
With `derivedState` and `derivedParam`:
```
(state, intent) => derivedState + derivedParam + action
```
Example:
```js
(state, intent) => ({
action: doSomething,
derivedState: {
x: 1,
},
derivedParam: {
y: 2,
},
});
```
### Action
```
context => void
```
Example:
```js
async context => {
// ...
};
```
With parameters:
```
context + param => void
```
Example:
```js
async (context, param) => {
// ...
};
```
## API Reference
### `createHandler({ recognizer, resolver, chatbase, debug })`
It creates a bottender handler function.
```js
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`.
```js
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](https://github.com/Yoctol/bottender-recognizer)