An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# bottender-recognizer

[![npm](https://img.shields.io/npm/v/bottender-recognizer.svg?style=flat-square)](https://www.npmjs.com/package/bottender-recognizer)
[![CircleCI](https://circleci.com/gh/Yoctol/bottender-recognizer.svg?style=shield&circle-token=864a782187e3b51b95c9fdccf815b090fc4abb66)](https://circleci.com/gh/Yoctol/bottender-recognizer)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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)