I am looking to initiate a multi-level, multiple choice dialog from the welcome message in the Bot Framework SDK using JavaScript. I have a main dialog (finalAnswerDialog) that utilizes LUIS for predicting intents, and a multi-level, multiple choice menu dialog (menuDialog) to assist users with navigating to specific intents. Despite my efforts, I have been encountering errors when trying to display the menu dialog from the beginning. Below is the code snippet:
dialogAndWelcomeBot
const { CardFactory } = require('botbuilder');
const { DialogBot } = require('./dialogBot');
const { ActivityHandler, MessageFactory } = require('botbuilder');
const { ActionTypes } = require('botframework-schema');
const { MenuDialog } = require('../dialogs/menuDialog');
class DialogAndWelcomeBot extends DialogBot {
constructor(conversationState, userState, dialog) {
super(conversationState, userState, dialog);
this.onMembersAdded(async (context, next) => {
const membersAdded = context.activity.membersAdded;
for (let cnt = 0; cnt < membersAdded.length; cnt++) {
if (membersAdded[cnt].id !== context.activity.recipient.id) {
await dialog.run(context, conversationState.createProperty('DialogState'));
await step.beginDialog('menuDialog');
}
}
// By calling next() you ensure that the next BotHandler is run.
await next();
});
}
}
module.exports.DialogAndWelcomeBot = DialogAndWelcomeBot;
menuDialog triggers finalAnswerDialog to handle LUIS calls at any stage
class MenuDialog extends ComponentDialog {
constructor(finalAnswerDialog) {
super('menuDialog');
this.answered=true;
this.addDialog(new TextPrompt(TEXT_PROMPT));
this.addDialog(new TextPrompt(NAME_PROMPT));
this.addDialog(new ChoicePrompt(CHOICE_PROMPT));
this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
this.addDialog(finalAnswerDialog);
this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.firstQuestion.bind(this),
this.secondQuestion.bind(this),
this.thirdQuestion.bind(this),
this.answerTheQuestion.bind(this),
this.finalStep.bind(this)
]));
this.initialDialogId = WATERFALL_DIALOG;
}
finalAnswerDialog
class FinalAnswerDialog extends ComponentDialog {
constructor(luisRecognizer) {
super('finalAnswerDialog');
if (!luisRecognizer) throw new Error('[MainDialog]: Missing parameter \'luisRecognizer\' is required');
this.luisRecognizer = luisRecognizer;
// Define the main dialog and its related components.
// This is a sample "book a flight" dialog.
this.addDialog(new TextPrompt('TextPrompt'));
this.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
//this.initStep.bind(this),
this.actStep.bind(this),
]));
this.initialDialogId = MAIN_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 initStep(stepContext) {
return await stepContext.prompt(TEXT_PROMPT, promptOptions);
}
async actStep(stepContext) {
if (!this.luisRecognizer.isConfigured) {
const messageText = 'NOTE: LUIS is not configured. To enable all capabilities, add `LuisAppId`, `LuisAPIKey` and `LuisAPIHostName` to the .env file.';
await stepContext.context.sendActivity(messageText, null, InputHints.IgnoringInput);
return await stepContext.next();
}
const luisResult = await this.luisRecognizer.executeLuisQuery(stepContext.context);
let top_intent = LuisRecognizer.topIntent(luisResult)
//let top_intent="contacto"
console.log("intent predicted by Luis: " + top_intent)
switch (top_intent) {
//SendActivity
index.js
const dialog = new FinalAnswerDialog(luisRecognizer);
const bot = new DialogAndWelcomeBot(conversationState, userState, dialog);
What steps can I take to successfully launch the menu dialog during the welcome sequence?