3

I want to validate the data by checking if it is identified as an entity(lets say randomEntity) by Luis or not. If the data entered is recognized as randomEntity, then move ahead, otherwise use retry prompt. But this does not work using promptContext-

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

This is sample code-

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

    }
uitwaa
  • 615
  • 1
  • 12
  • 24
  • A couple of questions... First, what is the error that you are getting? Second, you say you are already passing the LUIS result to your waterfall? You should be able to get the entity from the original result without calling LUIS again. Wouldn't you want to pick up the entity before you prompt the user? I have a good method to skip prompts if entities are identified. – billoverton Jun 01 '20 at 18:23
  • I'm getting this error- TypeError: Cannot read property 'recognize' of undefined. I'm not passing result to waterfall. I'm only passing it in the firstStepValidator. I want to pick the entity from the result which is received after prompting the user. – uitwaa Jun 01 '20 at 19:56
  • Before I put together an answer, are you able or willing to pass the LUIS result to your waterfall? That is how I have approached it, and from there you can just use some logic to check if the entity exists, and if so, skip the entire prompt step for that entity. If you can't or don't want to do that, then you'll need an alternate approach. – billoverton Jun 02 '20 at 20:10
  • I require Luis only in validator step. If I pass Luis result to waterfall, then I will have to use Luis for every step I guess. – uitwaa Jun 03 '20 at 09:06
  • So you are not using LUIS for your intent recognition? Maybe you could share the code that determines which dialog you are are calling? But yes, generally this would result in calling LUIS every turn, depending on how you set up the recognizer. Otherwise you should be able to set up a recognizer in the validator, but I'd need to check a few things before providing a solution. – billoverton Jun 03 '20 at 14:53
  • I have updated my code and added luis recognizer which I had already setup. There will be more steps but I want to add Luis only in the validator step. The issue I'm facing is that when I pass promptContext.context to recognizer it throws error. I want to check whether promptContext.context._activity.text is 'randomEntity' or not. If it is not then, use retry prompt. – uitwaa Jun 03 '20 at 19:16
  • Thanks for the additional context. At first glance, I can't see anything wrong. I assume you're importing this from botbuilder-ai? Can you check the version of that package? – billoverton Jun 04 '20 at 01:41
  • version is 4.8.0 – uitwaa Jun 04 '20 at 05:09
  • I just have a theory right now. The error seems to indicate that `this.luisRecognizer` doesn't exist. Perhaps this is not accessible from the validation function. Just to test, could you see if you set up the validator as a separate waterfall step if you can call `this.luisRecognizer.recognize`? That wouldn't solve your issue with needing to reprompt, but could help us understand why you are not able to use the recognizer. – billoverton Jun 04 '20 at 13:10

0 Answers0