1

How do I have multiple answers to same question?

I use Node and I'm pretty new to this, exampels?

This thread has an answer to my problem but its in C# How can i use QnAMaker to provide random answers to same query

2 Answers2

1

I'll assume you've already got a handle on how to use the botbuilder-cognitive services package.

Just like in the C# version, you can override respondFromQnAMakerResult(). You can see in the source code that you don't need to check if there are any answers because respondFromQnAMakerResult() is only called if there's at least one answer.

This is basically the solution from the other question translated into JavaScript:

basicQnAMakerDialog.respondFromQnAMakerResult = function(session, qnaMakerResult) {
    var msg = qnaMakerResult.answers[0].answer;
    var answersforhowareyou = msg.split('|');

    if (answersforhowareyou.count() > 1)
    {
        var index = Math.floor(Math.random() * answersforhowareyou.length);
        msg = answersforhowareyou[index];
    }

    session.send(msg);
}
Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
-1

Trying to implement this, errors as below

ReferenceError: answer is not defined at QnAMakerDialog.basicQnAMakerDialog.respondFromQnAMakerResult (D:\home\site\wwwroot\app.js:123:38) at QnAMakerDialog.invokeAnswer (D:\home\site\wwwroot\node_modules\botbuilder-cognitiveservices\lib\QnAMakerDialog.js:76:22) at D:\home\site\wwwroot\node_modules\botbuilder-cognitiveservices\lib\QnAMakerDialog.js:52:31 at next (D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentRecognizer.js:68:17) at IntentRecognizerSet.IntentRecognizer.filter (D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentRecognizer.js:71:9) at D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentRecognizer.js:20:31 at D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentRecognizerSet.js:80:17 at D:\home\site\wwwroot\node_modules\async\lib\async.js:52:16 at replenish (D:\home\site\wwwroot\node_modules\async\lib\async.js:306:28) at D:\home\site\wwwroot\node_modules\async\lib\async.js:326:29 at D:\home\site\wwwroot\node_modules\async\lib\async.js:44:16 at D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentRecognizerSet.js:72:21 at D:\home\site\wwwroot\node_modules\botbuilder-cognitiveservices\lib\QnAMakerRecognizer.js:52:21 at Request._callback (D:\home\site\wwwroot\node_modules\botbuilder-cognitiveservices\lib\QnAMakerRecognizer.js:107:25) at Request.self.callback (D:\home\site\wwwroot\node_modules\request\request.js:185:22) at emitTwo (events.js:106:13)