Classes
Functions
- markAsHandled([aiHandled]) ⇒ 
Request Mark request as handled - usefull for AI analytics
Ai
Kind: global class
- Ai
- .confidence : 
number - .threshold : 
number - .logger : 
Object - .prefixTranslator(prefix, req)
 - .mockIntent([intent], [confidence]) ⇒ 
this - .onConfirmMiddleware(onIntentConfirmed, getMeta) ⇒ 
function - .register(model, options, prefix) ⇒ 
WingbotModel - .match(intent, [confidence], [prefix]) ⇒ 
function - .navigate(knownIntents, [threshold], [confidence], [prefix]) ⇒ 
function - .makeSure(knownIntents, [threshold], [confidence], prefix) ⇒ 
function 
 - .confidence : 
 
ai.confidence : number
Upper threshold - for match method and for navigate method
Kind: instance property of Ai  
ai.threshold : number
Lower threshold - for navigate and makeSure methods
Kind: instance property of Ai  
ai.logger : Object
The logger (console by default)
Kind: instance property of Ai  
ai.prefixTranslator(prefix, req)
The prefix translator - for request-specific prefixes
Kind: instance method of Ai  
| Param | Type | 
|---|---|
| prefix | string | 
| req | Request | 
ai.mockIntent([intent], [confidence]) ⇒ this
Usefull method for testing AI routes
Kind: instance method of Ai  
| Param | Type | Default | Description | 
|---|---|---|---|
| [intent] | string | 
null | 
intent name | 
| [confidence] | number | 
 | 
the confidence of the top intent | 
Example
const { Tester, ai, Route } = require('bontaut');
const bot = new Route();
bot.use(['intentAction', ai.match('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.onConfirmMiddleware(onIntentConfirmed, getMeta) ⇒ function
When user confirms their intent, onIntentConfirmed handler will be called. To create meta data from recognized request use getMeta handler. Its useful for updating training data for AI
Kind: instance method of Ai  
| Param | Type | Default | Description | 
|---|---|---|---|
| onIntentConfirmed | function | 
handler, which will be called when intent is confirmed | |
| getMeta | function | 
 | 
handler, which will be called when intent is confirmed | 
Example
const { Router, ai } = require('botnaut');
bot.use(ai.onConfirmMiddleware((senderId, intent, text, timestamp, meta) => {
    // log this information
}, (req) => {
    // create and return meta data object
}));
bot.use(ai.makeSure(['intent1', 'intent2']), (req, res) => {
    console.log(req.confidences); // { intent1: 0.8604, intent2: undefined }
    res.text('What you mean?', res.ensures({
        intent1: 'Intent one?',
        intent2: 'Intent two?',
        anyOther: 'Niether'
    }));
});
ai.register(model, options, prefix) ⇒ WingbotModel
Registers Wingbot AI model
Kind: instance method of Ai  
| Param | Type | Description | 
|---|---|---|
| model | string | 
model name | 
| options | Object | 
the configuration | 
| [options.cacheSize] | number | 
remember number of caches | 
| [options.matches] | number | 
ask AI for number of matches | 
| prefix | string | 
model prefix | 
ai.match(intent, [confidence], [prefix]) ⇒ function
Returns matching middleware
Kind: instance method of Ai
Returns: function - - the middleware  
| Param | Type | Default | |
|---|---|---|---|
| intent | string \ | 
Array | 
|
| [confidence] | number | 
 | 
|
| [prefix] | string | 
Example
const { Router, ai } = require('botnaut');
ai.register('app-model');
bot.use(ai.match('intent1'), (req, res) => {
    console.log(req.confidences); // { intent1: 0.9604 }
    res.text('Oh, intent 1 :)');
});
ai.navigate(knownIntents, [threshold], [confidence], [prefix]) ⇒ function
Create AI middleware, which resolves multiple replies
and makes postback, when it's confident
Confidence should be between threshold and confidence to proceed
to next resolver
Kind: instance method of Ai
Returns: function - - the middleware  
| Param | Type | Default | Description | |
|---|---|---|---|---|
| knownIntents | Array \ | 
Object | 
list or map of accepted intents | |
| [threshold] | number | 
 | 
lower threshold | |
| [confidence] | number | 
 | 
upper threshold for confidence | |
| [prefix] | string | 
model name | 
Example
const { Router, ai } = require('botnaut');
bot.use(ai.navigate(['intent1', 'intent2']), (req, res) => {
    console.log(req.confidences); // { intent1: 0.8604, intent2: undefined }
    res.text('What you mean?', res.ensures({
        intent1: 'Intent one?',
        intent2: 'Intent two?',
        anyOther: 'Niether'
    }));
});
ai.makeSure(knownIntents, [threshold], [confidence], prefix) ⇒ function
Create AI middleware, which resolves multiple replies.
Confidence should be between threshold and confidence to proceed
to next resolver
Kind: instance method of Ai
Returns: function - - the middleware  
| Param | Type | Default | Description | |
|---|---|---|---|---|
| knownIntents | Array \ | 
Object | 
list or map of accepted intents | |
| [threshold] | number | 
 | 
lower threshold | |
| [confidence] | number | 
 | 
upper threshold for confidence | |
| prefix | string | 
model name | 
Example
const { Router, ai } = require('botnaut');
bot.use(ai.makeSure(['intent1', 'intent2']), (req, res) => {
    console.log(req.confidences); // { intent1: 0.8604, intent2: undefined }
    res.text('What you mean?', res.ensures({
        intent1: 'Intent one?',
        intent2: 'Intent two?',
        anyOther: 'Niether'
    }));
});
markAsHandled([aiHandled]) ⇒ Request
Mark request as handled - usefull for AI analytics
Kind: global function
| Param | Type | Default | Description | 
|---|---|---|---|
| [aiHandled] | boolean | 
true | 
true by default | 
Example
bot.use('some other query', (req, res) => {
    req.markAsHandled();
});