Node.js Azure机器人框架V4(NodeJS)-路易斯识别器返回错误?

Node.js Azure机器人框架V4(NodeJS)-路易斯识别器返回错误?,node.js,azure,botframework,chatbot,azure-language-understanding,Node.js,Azure,Botframework,Chatbot,Azure Language Understanding,使用Azure Bot框架和LUIS.ai识别用户意图。使用文本执行对端点的get请求将返回我期望的json对象,但是使用内置Luis识别器,我收到以下错误:“无法读取未定义的属性”get“。从这里的文档来看:这似乎是正确的配置,所以我不确定哪里出了问题。有什么想法吗 const { ComponentDialog, DialogSet, DialogTurnStatus, WaterfallDialog, ChoicePrompt, TextPrompt } = require('botbu

使用Azure Bot框架和LUIS.ai识别用户意图。使用文本执行对端点的get请求将返回我期望的json对象,但是使用内置Luis识别器,我收到以下错误:“无法读取未定义的属性”get“。从这里的文档来看:这似乎是正确的配置,所以我不确定哪里出了问题。有什么想法吗


const { ComponentDialog, DialogSet, DialogTurnStatus, WaterfallDialog, ChoicePrompt, TextPrompt } = require('botbuilder-dialogs');
const { TopLevelDialog, TOP_LEVEL_DIALOG } = require('./topLevelDialog');

const { LuisRecognizer, QnAMaker } = require('botbuilder-ai');
const axios = require('axios');

const MAIN_DIALOG = 'MAIN_DIALOG';
const WATERFALL_DIALOG = 'WATERFALL_DIALOG';
const USER_PROFILE_PROPERTY = 'USER_PROFILE_PROPERTY';
const CHOICE_PROMPT = 'CHOICE_PROMPT';
const TEXT_PROMPT = 'TEXT_PROMPT';


class MainDialog extends ComponentDialog {
    constructor(userState) {
        super(MAIN_DIALOG);
        this.userState = userState;
        this.userProfileAccessor = userState.createProperty(USER_PROFILE_PROPERTY);

        this.addDialog(new TextPrompt(TEXT_PROMPT));
        this.addDialog(new TopLevelDialog());
        this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
            this.initialStep.bind(this),
            this.askIfFinishedStep.bind(this),
            this.finalStep.bind(this)
        ]));

        this.initialDialogId = WATERFALL_DIALOG;

        let luisConfig = {
            applicationId: '',
            endpointKey: '',
            endpoint: '',
        };

        this.Luis = new LuisRecognizer(
            luisConfig, 
            {
                includeAllIntents: true,
                log: true,
                staging: false            
            },
            true
            );        

    }

    async run(turnContext, accessor) {
        const dialogSet = new DialogSet(accessor);
        dialogSet.add(this);

        const dialogContext = await dialogSet.createContext(turnContext);
        const results = await dialogContext.continueDialog();
        if (results.status === DialogTurnStatus.empty) {
            await dialogContext.beginDialog(this.id);
        }
    }

    async initialStep(stepContext) {

        let luisAnalysis = await this.Luis.recognize(stepContext);

        let queryString = encodeURIComponent(stepContext.context._activity.text);

        /*
         Ignore this if statement - only in use with the get request 
        */
        if(luisResponse.data.topScoringIntent.intent === 'TrainingExpiry' && luisResponse.data.topScoringIntent.score > .75)
        {
            return await stepContext.beginDialog(TOP_LEVEL_DIALOG);
        }
        else 
        {
            await stepContext.context.sendActivity("I'm sorry, that is not supported at this time or a high enough intent was not acknowledged.");
            await stepContext.context.sendActivity("Top intent: " + luisResponse.data.topScoringIntent.intent + " Score: " + luisResponse.data.topScoringIntent.score);

            return await stepContext.next();
        }        
    }

    async askIfFinishedStep(stepContext) {
        const promptOptions = { prompt: 'Is there anything else I can assist you with?' };

        return await stepContext.prompt(TEXT_PROMPT, promptOptions);
    }

    async finalStep(stepContext) {

        if(stepContext.context._activity.text.toLowerCase() === 'no')
        {
            await stepContext.context.sendActivity("Good bye");

            return await stepContext.endDialog();
        }
        else 
        {
            return await stepContext.beginDialog(MAIN_DIALOG);
        }
    }
}

module.exports.MainDialog = MainDialog;
module.exports.MAIN_DIALOG = MAIN_DIALOG;


注意:正如@billoverton指出的,问题在于我的参数被传递给识别器。解决方案是传递stepContext.context

查看botbuilder ai模块中的LuisRecogniter.js,错误是因为识别器需要turnContext(具有turnState属性),而您正在发送stepContext。stepContext上不存在turnState,因此get属性失败并导致错误。如果改为发送stepContext.context,将解决问题,即让luisAnalysis=等待this.Luis.recognize(stepContext.context)

查看botbuilder ai模块中的LuisRecogniter.js,错误是因为识别器需要turnContext(具有turnState属性),而您正在发送stepContext。stepContext上不存在turnState,因此get属性失败并导致错误。如果改为发送stepContext.context,将解决问题,即让luisAnalysis=等待this.Luis.recognize(stepContext.context)

您可以发布更多错误消息的详细信息吗?If应该告诉您试图从未定义的属性
获取
的位置。看看这段代码也会很有帮助。我最初的想法是,你的州管理存在一些问题。LUIS配置本身看起来很好。@billoverton我已经用完整的错误消息更新了原始帖子。这似乎是您发送给识别器的stepContext对象的问题。它不包含turnState,我怀疑它可能不是turnContext对象。您能将您的stepContext对象记录到console并将结果添加到您的问题中吗?@billoverton感谢您的跟进-正如您所指出的,问题发生在我的stepContext对象中。传递stepContext.context而不是stepContext解决了我的问题。非常感谢比尔,太好了!我接受了我的评论,并转换成了答案。如果它看起来不错,请接受,这样它可以帮助别人!你能发布更多错误信息的详细信息吗?If应该告诉您试图从未定义的属性
获取
的位置。看看这段代码也会很有帮助。我最初的想法是,你的州管理存在一些问题。LUIS配置本身看起来很好。@billoverton我已经用完整的错误消息更新了原始帖子。这似乎是您发送给识别器的stepContext对象的问题。它不包含turnState,我怀疑它可能不是turnContext对象。您能将您的stepContext对象记录到console并将结果添加到您的问题中吗?@billoverton感谢您的跟进-正如您所指出的,问题发生在我的stepContext对象中。传递stepContext.context而不是stepContext解决了我的问题。非常感谢比尔,太好了!我接受了我的评论,并转换成了答案。如果它看起来不错,请接受,这样它可以帮助别人!非常感谢,非常感谢