3

我想通过检查数据是否被 Luis 识别为实体(比如说 randomEntity)来验证数据。如果输入的数据被识别为randomEntity,则继续前进,否则使用重试提示。但这不能使用 promptContext-

const luisResult = await this.luisRecognizer.recognize(promptContext.context);

这是示例代码-

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

        this.addDialog(new TextPrompt('firstPrompt', this.firstStepValidator));


        this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
            this.firstStep.bind(this),

        ]));

        this.initialDialogId = WATERFALL_DIALOG;

        let luisConfig = {
            applicationId: 'myid',
            endpointKey: 'myendpointkey',
            endpoint: 'myendpoint',
        };
        this.luisRecognizer = new LuisRecognizer(
            luisConfig, 
            {
                includeAllIntents: true,
                log: true,
                staging: false            
            },
            true
            );        
    }

    /**
     * The run method handles the incoming activity (in the form of a TurnContext) and passes it through the dialog system.
     * If no dialog is active, it will start the default dialog.
     * @param {*} turnContext
     * @param {*} accessor
     */
    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 firstStep(stepContext) {


        const promptOptions = { 
            prompt: 'Please enter xyz id', 
            retryPrompt: 'Please enter a valid xyz id' };

        return await stepContext.prompt('firstPrompt', promptOptions);
    }

    async firstStepValidator(promptContext) {

        const luisResult = await this.luisRecognizer.recognize(promptContext.context); //THROWS ERROR: TypeError: Cannot read property 'recognize' of undefined
        //do something with result

    }
4

0 回答 0