I'm using the Microsoft code samples to try and create a LUIS bot that uses an intent to trigger the QNA Maker.
At the moment the QnA Maker returns results sometimes but other times it returns "TypeError: Cannot read property '0' of undefined".
The question "Price change" with the following code returns the correct answer from QnA maker.
var customQnAMakerTools = new customQnAMakerTools.CustomQnAMakerTools();
bot.library(customQnAMakerTools.createLibrary());
var intents = new builder.IntentDialog({ recognizers: [recognizer,
r12recognizer] });
bot.dialog('/', intents);
var basicQnAMakerDialog = new builder_cognitiveservices.QnAMakerDialog({
recognizers: [r12recognizer],
defaultMessage: 'Sorry i did not understand that. Try asking the
question again.',
qnaThreshold: 0.3,
feedbackLib: customQnAMakerTools
});
intents.matches('qna', [
basicQnAMakerDialog.respondFromQnAMakerResult = function(session,
qnaMakerResult){
// Save the question
var question = session.message.text;
session.conversationData.userQuestion = question;
// boolean to check if the result is formatted for a card
var isCardFormat = qnaMakerResult.answers[0].answer.includes(';');
if(!isCardFormat){
// Not semi colon delimited, send a normal text response
session.send(qnaMakerResult.answers[0].answer);
}else if(qnaMakerResult.answers && qnaMakerResult.score >= 0.5){
var qnaAnswer = qnaMakerResult.answers[0].answer;
var qnaAnswerData = qnaAnswer.split(';');
var title = qnaAnswerData[0];
var description = qnaAnswerData[1];
var url = qnaAnswerData[2];
var imageURL = qnaAnswerData[3];
var msg = new builder.Message(session)
msg.attachments([
new builder.HeroCard(session)
.title(title)
.subtitle(description)
.images([builder.CardImage.create(session, imageURL)])
.buttons([
builder.CardAction.openUrl(session, url, "Learn More")
])
]);
}
session.send(msg).endDialog();
}
]);
However, if I change the question to "Price change approved but finally rejected by the System" which is the full question in QnA Maker it returns "TypeError: Cannot read property '0' of undefined". The full error is
TypeError: Cannot read property '0' of undefined
at Array.intents.matches.basicQnAMakerDialog.respondFromQnAMakerResult (D:\home\site\wwwroot\app.js:71:46)
at Object.waterfallHandler [as qna] (D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:139:29)
at IntentDialog.invokeIntent (D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentDialog.js:163:44)
at D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentDialog.js:71:27
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)
I cant currently workout if its because I'm passing the question incorrectly or if its only passing part of the question.
This seems to happen when you have an intent in LUIS with the same name. Once the intent is deleted the QnA intent will kick off correctly and send the messages to the QnA Knowledge base.