Configuring activation rules
The chatbot developer can define the state triggering mechanism when intents, patterns and example groups are used together.
The context ctx that contains the nluResults field is passed to the handler function as a parameter. The object nluResults contains the following fields:
patterns— an array of results from the pattern matcher;examples— an array of results from the examples;intents— an array of results from the intents;selected— the result selected by default.
To change the result source, change the value of the field selected.
An example
theme:/
init: //declare the handler
bind("selectNLUResult", function(ctx) { //define the handler for the `selectNLUResult` phase
log(ctx.nluResults); // output the results to the log
if (ctx.nluResults.intents.length > 0){
ctx.nluResults.selected = ctx.nluResults.intents[0]; // use the result from the intents
return;
}
if (ctx.nluResults.patterns.length > 0){
ctx.nluResults.selected = ctx.nluResults.patterns[0]; // if there is no result from the intents, use patterns
return;
}
if (ctx.nluResults.examples.length > 0){
ctx.nluResults.selected = ctx.nluResults.examples[0]; // if there is no result either from the intents or from the patterns, use the examples
}
})- We declare the handler in the
initsection. You can also specify the handler in a separate JS file and connect it to the script usingrequire. - Define the handler for the
selectNLUResultphase. - Output the results to the log:
log(ctx.nluResults). - Then we define the order in which the results are used:
- use the result from the intents:
ctx.nluResults.selected = ctx.nluResults.intents\[0]; - use the result from the pattern matcher:
ctx.nluResults.selected = ctx.nluResults.patterns\[0]; - use the result from the examples:
ctx.nluResults.selected = ctx.nluResults.examples\[0].
- use the result from the intents: