Multiple Intents found: Send dynamic quick replies based on the list of understood intents

The more intents a Flow contains, the more likely multiple topics could be meant by the user. In order to prevent misunderstandings and provide intent confirmations, the input.nlu.intentMapperResults can be used. Since this list of found intents is dynamic, the confirmation question should consist of a dynamic number of quick replies as well.

Intent Mapper Result

All understood intents, if multiple were found, are listed in input.nlu.intentMapperResults.score:

{
    "nlu": {
        "intentMapperResults": {
            "scores": [
              {
                    "id": "...",
                    "name": "Forgot Password",
                    "score": 0.13149820293393646,
                    "negated": false,
                    "confirmationSentence": null,
                    "confirmationSentences": null,
                    "disambiguationSentence": null,
                    "flow": "..."
              },
{
...
}
          ]
      }
  }
}

 

Create a dynamic Quick Reply message

In order to output the dynamic message, a Code Node can be used, while the following content should be provided:

interface INLUResult {
    id: string;
    name: string;
    score: string;
    negated: boolean;
    confirmationSentence: any;
    confirmationSentences: any;
    disambiguationSentence: any;
    flow: string;
}

interface IQuickReply {
    content_type: string;
    condition: string;
    title: string;
    image_url: string;
    payload: string;
}

const createQuickReplies = (nluResults: INLUResult[]) => {
    let quickReplies: IQuickReply[] = [];

    for (let result of nluResults) {
        quickReplies.push({
            "content_type": "text",
            "condition": "",
            "title": result.name,
            "image_url": "",
            "payload": `cIntent:${result.name}`
      });

    }

    return quickReplies;
}

api.say('', {
    "_cognigy": {
        "_default": {
            "message": {
                "text": "I am not exactly sure what you mean. Please choose your topic:",
                "quick_replies": createQuickReplies(input.nlu.intentMapperResults.scores)
          }
      },
        "_webchat": {
            "message": {
                "text": "I am not exactly sure what you mean. Please choose your topic:",
                "quick_replies": createQuickReplies(input.nlu.intentMapperResults.scores)
          }
      }
  }
});

 

Last but not least, the message will be displayed in the interaction panel and webchat -- based on the example from above.

 

 


Comments

0 comments

Article is closed for comments.

Was this article helpful?
0 out of 0 found this helpful