app.js有时会返回类型错误:无法读取完整问题上未定义的属性'0'



我正在使用Microsoft代码示例尝试创建使用意图触发QNA Maker的Luis Bot。

目前QNA制造商有时会返回结果,但有时它会返回" TypeError:无法读取未定义的属性'0'。

带有以下代码的"价格更改"的问题将返回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();
}

]);

但是,如果我将问题更改为"批准的价格变更但最终被系统拒绝",那是QNA制造商中的完整问题,它返回" TypeError:无法读取未定义的属性'0'。完整错误是

TypeError: Cannot read property '0' of undefined
    at Array.intents.matches.basicQnAMakerDialog.respondFromQnAMakerResult (D:homesitewwwrootapp.js:71:46)
    at Object.waterfallHandler [as qna] (D:homesitewwwrootnode_modulesbotbuilderlibdialogsWaterfallDialog.js:139:29)
    at IntentDialog.invokeIntent (D:homesitewwwrootnode_modulesbotbuilderlibdialogsIntentDialog.js:163:44)
    at D:homesitewwwrootnode_modulesbotbuilderlibdialogsIntentDialog.js:71:27
    at next (D:homesitewwwrootnode_modulesbotbuilderlibdialogsIntentRecognizer.js:68:17)
    at IntentRecognizerSet.IntentRecognizer.filter (D:homesitewwwrootnode_modulesbotbuilderlibdialogsIntentRecognizer.js:71:9)
    at D:homesitewwwrootnode_modulesbotbuilderlibdialogsIntentRecognizer.js:20:31
    at D:homesitewwwrootnode_modulesbotbuilderlibdialogsIntentRecognizerSet.js:80:17
    at D:homesitewwwrootnode_modulesasynclibasync.js:52:16
    at replenish (D:homesitewwwrootnode_modulesasynclibasync.js:306:28)

我目前无法锻炼,如果我是因为我错误地传递了问题或仅通过问题的一部分。

当您对路易斯的意图具有相同名称时,这似乎会发生。删除意图后,QNA意图将正确启动并将消息发送到QNA知识库。

相关内容

最新更新