0
votes

I have a Main Dialog in which I am having a Waterfall Dialog of only one step which is to Identify Intent and depending on the intent, I am deciding whether to call another dialog (which is another Waterfall Dialog with 3 steps) or directly reply back the user with response for intents like Greeting and Cancel. Below is the code for my Main Dialog -

const chalk = require('chalk')
const path = require('path');

const {
  ComponentDialog,
  DialogSet,
  DialogTurnStatus,
  WaterfallDialog
} = require('botbuilder-dialogs');
const {
  TopLevelDialog,
  TOP_LEVEL_DIALOG
} = require('./topLevelDialog');
const ENV_FILE = path.join(__dirname, '../.env');
require('dotenv').config({
  path: ENV_FILE
});

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

const MAIN_DIALOG = 'MAIN_DIALOG';
const WATERFALL_DIALOG = 'WATERFALL_DIALOG';
const USER_PROFILE_PROPERTY = 'USER_PROFILE_PROPERTY';

const dispatchRecognizer = new LuisRecognizer({
  applicationId: process.env.LuisAppId,
  endpointKey: process.env.LuisAPIKey,
  endpoint: `https://${process.env.LuisAPIHostName}`
}, {
  includeAllIntents: true,
  includeInstanceData: true
}, true);

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

    this.addDialog(new TopLevelDialog());
    this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
      this.initialStep.bind(this),
    ]));
    this.initialDialogId = WATERFALL_DIALOG;
  }
  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) {
    const recognizerResult = await dispatchRecognizer.recognize(stepContext.context);
    const intent = LuisRecognizer.topIntent(recognizerResult);
    console.log(chalk.yellow(intent))
    await this.dispatchToTopIntentAsync(stepContext, intent);
    console.log(chalk.green('after dispatch'))
    return await stepContext.endDialog();
  }
  async dispatchToTopIntentAsync(stepContext, intent) {
    console.log(chalk.blue('in dispatch to top intent'))
    switch (intent) {
      case 'Greeting':
        console.log(chalk.red('greeting'))
        return await this.greeting(stepContext);
      default:
        console.log(`Dispatch unrecognized intent: ${ intent }.`);
        await stepContext.context.sendActivity(`Dispatch unrecognized intent: ${ intent }.`);
        return await stepContext.beginDialog(TOP_LEVEL_DIALOG);
    }
  }

  async greeting(stepContext) {
    return await stepContext.context.sendActivity(`Welcome! how can I help you`);
  }
}
module.exports.MainDialog = MainDialog;
module.exports.MAIN_DIALOG = MAIN_DIALOG;

In my case, the TOP_LEVEL_DIALOG is being when I type any query related to that intent, and ask the first step of that waterfall (asks for Name). But when I type my name it comes out of that waterfall dialog and shows the greeting response as LUIS is identifying my name as Greeting intent.

How to solve this kind of issue?

1

1 Answers

0
votes

I don't believe the issue is with your code, but with your LUIS model. If you type in your name and it returns the Greeting intent, then you should start by reviewing the utterances in your Greeting intent and how your LUIS model is trained/published.

You should navigate to the LUIS.ai site and test your model by entering your name and see what returns.

enter image description here