Classes

Ai
WingbotModel
CachedModel

Typedefs

EntityExpression : Object
IntentRule : string | EntityExpression
Entity : Object
Intent : Object
Result : Object
Entity : Object
Intent : Object
Result : Object
 

Ai

Kind: global class

 

ai.confidence : number

Upper threshold - for match method and for navigate method

Kind: instance property of Ai

 

ai.logger : Object

The logger (console by default)

Kind: instance property of Ai

 

ai.disableBookmarking : boolean

Backward compatibility - to be able to use older "callback" middleware

Kind: instance property of Ai

 

ai.getPrefix(prefix, req)

The prefix translator - for request-specific prefixes

Kind: instance method of Ai
Params

  • prefix string
  • req Request
 

ai.mockIntent([intent], [score]) ⇒ this

Usefull method for testing AI routes

Kind: instance method of Ai
Params

  • [intent] string = null - intent name
  • [score] number = - the score of the top intent

Example

const { Tester, ai, Route } = require('bontaut');

const bot = new Route();

bot.use(['intentAction', ai.localMatch('intentName')], (req, res) => {
    res.text('PASSED');
});

describe('bot', function () {
    it('should work', function () {
        ai.mockIntent('intentName');

        const t = new Tester(bot);

        return t.text('Any text')
            .then(() => {
                t.actionPassed('intentAction');

            t.any()
                .contains('PASSED');
        })
    });
});
 

ai.register(model, prefix) ⇒ WingbotModel | T

Registers Wingbot AI model

Kind: instance method of Ai
Template: T
Params

  • model string | WingbotModel | T - wingbot model name or AI plugin
  • prefix string = "default" - model prefix
 

ai.load()

Middleware, which ensures, that AI data are properly loaded in Request

Kind: instance method of Ai
Example

const { ai, Router } = require('wingbot');

const bot = new Router();

bot.use(ai.load());
 

ai.match(intent, [confidence]) ⇒ function

Returns matching middleware

supports:

  • intents ('intentName')
  • entities ('@entity')
  • complex entities ({ entity:'entity', op:'range', compare:[null,1000] })
  • optional entities ({ entity:'entity', optional: true })
  • wildcard keywords ('#keyword#')
  • phrases ('#first-phrase|second-phrase')
  • emojis ('#😄🙃😛')

Kind: instance method of Ai
Returns: function - - the middleware
Params

Example

const { Router, ai } = require('wingbot');

ai.register('app-model');

bot.use(ai.match('intent1'), (req, res) => {
    console.log(req.intent(true)); // { intent: 'intent1', score: 0.9604 }

    res.text('Oh, intent 1 :)');
});
 

ai.localMatch(intent, [confidence]) ⇒ function

Returns matching middleware, that will export the intent to the root router so the intent will be matched in a local context (nested Router)

Kind: instance method of Ai
Returns: function - - the middleware
Params

Example

const { Router, ai } = require('wingbot');

ai.register('app-model');

bot.use(ai.localMatch('intent1'), (req, res) => {
    console.log(req.intent(true)); // { intent: 'intent1', score: 0.9604 }

    res.text('Oh, intent 1 :)');
});
 

ai.globalMatch(intent, [confidence]) ⇒ function

Returns matching middleware, that will export the intent to the root router so the intent will be matched in a global context

Kind: instance method of Ai
Returns: function - - the middleware
Params

Example

const { Router, ai } = require('wingbot');

ai.register('app-model');

bot.use(ai.globalMatch('intent1'), (req, res) => {
    console.log(req.intent(true)); // { intent: 'intent1', score: 0.9604 }

    res.text('Oh, intent 1 :)');
});
 

WingbotModel

Kind: global class

 

new WingbotModel(options, [log])

Params

  • options Object
    • [.serviceUrl] string
    • .model string
    • [.cacheSize] number
    • [.matches] number
  • [log] Object
 

wingbotModel._queryModel(text) ⇒ Promise.<Result>

Kind: instance method of WingbotModel
Params

  • text string
 

CachedModel

Kind: global class

 

new CachedModel(options, [log])

Params

  • options Object
    • [.cacheSize] number
  • [log] Object
 

cachedModel.resolve(text) ⇒ Promise.<Result>

Kind: instance method of CachedModel
Params

  • text string - the user input
 

cachedModel._queryModel(text) ⇒ Promise.<(Array.<Intent>|Result)>

Kind: instance method of CachedModel
Params

  • text string
 

EntityExpression : Object

Kind: global typedef
Properties

Name Type Description
entity string the requested entity
[optional] boolean entity is optional, can be missing in request
[op] Compare comparison operation (eq ne range)
[compare] Array.<string> \ Array.<number> value to compare with
 

IntentRule : string | EntityExpression

Kind: global typedef

 

Entity : Object

Kind: global typedef
Params

  • entity string
  • value string
  • score number
 

Intent : Object

Kind: global typedef
Params

 

Result : Object

Kind: global typedef
Params

 

Entity : Object

Kind: global typedef
Params

  • entity string
  • value string
  • score number
 

Intent : Object

Kind: global typedef
Params

 

Result : Object

Kind: global typedef
Params

results matching ""

    No results matching ""