This site is no longer updated.Go to new Conversational Cloud docs

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
        }

        })
  1. We declare the handler in the init section. You can also specify the handler in a separate JS file and connect it to the script using require.
  2. Define the handler for the selectNLUResult phase.
  3. Output the results to the log: log(ctx.nluResults).
  4. 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].