bottender-recognizer

0.3.0 • Public • Published

bottender-recognizer

npm CircleCI License: MIT

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

Dependents (0)

Package Sidebar

Install

npm i bottender-recognizer

Weekly Downloads

2

Version

0.3.0

License

MIT

Unpacked Size

27 kB

Total Files

28

Last publish

Collaborators

  • chentsulin
  • etrexkuo
  • tw0517tw
  • link515