app.js sometimes returns TypeError: Cannot read property '0' of undefined on full questions

app.js sometimes returns TypeError: Cannot read property '0' of undefined on full questions

我正在使用 Microsoft 代码示例尝试创建一个 LUIS 机器人,该机器人使用意图触发 QNA Maker。

目前 QnA Maker returns 有时会产生结果,但有时会 returns "TypeError: Cannot read property '0' of undefined".

问题"Price change"以下代码returns来自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();
}


]);

但是,如果我将问题更改为 "Price change approved but finally rejected by the System",这是 QnA Maker 中的完整问题 returns "TypeError: Cannot read property '0' of undefined"。完整的错误是

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)

我目前无法锻炼,如果是因为我答错了问题,或者它只是通过了问题的一部分。

当您在 LUIS 中有同名意图时,似乎会发生这种情况。删除意向后,QnA 意向将正确启动并将消息发送到 QnA 知识库。