Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(logger) {
super('MainDialog');
if (!logger) {
logger = console;
logger.log('[MainDialog]: logger not passed in, defaulting to console');
}
this.logger = logger;
// Define the main dialog and its related components.
this.addDialog(new ChoicePrompt('cardPrompt'));
this.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
this.choiceCardStep.bind(this),
this.showCardStep.bind(this)
]));
// The initial child Dialog to run.
this.initialDialogId = MAIN_WATERFALL_DIALOG;
}
if (!conversationIdFactory) throw new Error('[MainDialog]: Missing parameter \'conversationIdFactory\' is required');
if (!process.env.MicrosoftAppId) throw new Error('[MainDialog]: Missing parameter \'MicrosoftAppId\' is required');
if (!process.env.SkillHostEndpoint) throw new Error('[MainDialog]: Missing parameter \'SkillHostEndpoint\' is required');
this.activeSkillPropertyName = `${ MAIN_DIALOG }.activeSkillProperty`;
this.activeSkillProperty = conversationState.createProperty(this.activeSkillPropertyName);
this.skillsConfig = skillsConfig;
this.selectedSkillKey = `${ MAIN_DIALOG }.selectedSkillKey`;
// Use helper method to add SkillDialog instances for the configured skills.
this.addSkillDialogs(conversationState, conversationIdFactory, skillClient, skillsConfig, process.env.MicrosoftAppId);
// Define the main dialog and its related components.
// Add ChoicePrompt to render available skills.
this.addDialog(new ChoicePrompt(SKILL_PROMPT))
// Add ChoicePrompt to render skill actions.
.addDialog(new ChoicePrompt(SKILL_ACTION_PROMPT, this.skillActionPromptValidator))
// Add main waterfall dialog for this bot.
.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.selectSkillStep.bind(this),
this.selectSkillActionStep.bind(this),
this.callSkillActionStep.bind(this),
this.finalStep.bind(this)
]));
this.initialDialogId = WATERFALL_DIALOG;
}
// Continue the current dialog
await dc.continueDialog();
// Show menu if no response sent
if (!context.responded) {
await dc.beginDialog('mainMenu');
}
}
});
});
const dialogs = new DialogSet();
// Add prompts
dialogs.add('choicePrompt', new ChoicePrompt());
dialogs.add('confirmPrompt', new ConfirmPrompt());
dialogs.add('datetimePrompt', new DatetimePrompt());
dialogs.add('numberPrompt', new NumberPrompt());
dialogs.add('textPrompt', new TextPrompt());
dialogs.add('attachmentPrompt', new AttachmentPrompt());
//-----------------------------------------------
// Main Menu
//-----------------------------------------------
dialogs.add('mainMenu', [
async function(dc) {
function choice(title: string, value: string): Choice {
return {
value: value,
yield dc.context.sendActivity(`ok...`);
}
return yield dc.endDialog();
});
// waterfall dialog for dealing with multiple dialogs
this.addDialog(new botbuilder_dialogs_1.WaterfallDialog(DELETE_MULTI_DIALOG, [
this.chooseAlarmStep,
this.deleteChosenAlarmStep
]));
// waterfall dialog for deleting a single dialog
this.addDialog(new botbuilder_dialogs_1.WaterfallDialog(DELETE_SINGLE_DIALOG, [
this.confirmDeleteSingleStep,
this.confirmedDeleteSingleAlarmStep
]));
// Add support prompts
this.addDialog(new botbuilder_dialogs_1.ChoicePrompt(CHOOSE_ALARM_PROMPT));
this.addDialog(new botbuilder_dialogs_1.ConfirmPrompt(CONFIRM_DELETE_PROMPT));
}
// NOTE: since waterfall steps are passed in as a function to the waterfall dialog
constructor(conversationState, userState) {
// Create a new state accessor property. See https://aka.ms/about-bot-state-accessors to learn more about bot state and state accessors.
this.conversationState = conversationState;
this.userState = userState;
this.dialogState = this.conversationState.createProperty(DIALOG_STATE_PROPERTY);
this.userProfile = this.userState.createProperty(USER_PROFILE_PROPERTY);
this.dialogs = new DialogSet(this.dialogState);
// Add prompts that will be used by the main dialogs.
this.dialogs.add(new TextPrompt(NAME_PROMPT));
this.dialogs.add(new ChoicePrompt(CONFIRM_PROMPT));
this.dialogs.add(new NumberPrompt(AGE_PROMPT, async (prompt) => {
if (prompt.recognized.succeeded) {
if (prompt.recognized.value <= 0) {
await prompt.context.sendActivity(`Your age can't be less than zero.`);
return false;
} else {
return true;
}
}
return false;
}));
// Create a dialog that asks the user for their name.
this.dialogs.add(new WaterfallDialog(WHO_ARE_YOU, [
this.promptForName.bind(this),
constructor() {
super('MainDialog');
// Define the main dialog and its related components.
this.addDialog(new ChoicePrompt('cardPrompt'));
this.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
this.choiceCardStep.bind(this),
this.showCardStep.bind(this)
]));
// The initial child Dialog to run.
this.initialDialogId = MAIN_WATERFALL_DIALOG;
this.lgTemplates = Templates.parseFile('./resources/MainDialog.lg');
}
module.exports = function createBotLogic(conversationState) {
const dialogs = new DialogSet();
// Create a choice prompt and change the list style
const cardPrompt = new ChoicePrompt().style(ListStyle.list);
// Create our prompt's choices
const cardOptions = [
{
value: 'Adaptive card',
synonyms: ['1', 'adaptive card']
},
{
value: 'Animation card',
synonyms: ['2', 'animation card']
},
{
value: 'Audio card',
synonyms: ['3', 'audio card']
},
{
super(QnADialog.name);
// validate what was passed in
if (!userDataAccessor) throw new Error('QnA constructor missing parameter: userDataAccessor is required.');
if (!qnaRecognizers) throw new Error('QnA constructor missing parameter: qnaRecognizers is required.');
this.userDataAccessor = userDataAccessor;
this.qnaRecognizers = qnaRecognizers;
this.addDialog(new WaterfallDialog(QNA_DIALOG, [
this.queryQnAServiceStep.bind(this),
this.promptFeedbackStep.bind(this),
this.endFeedbackStep.bind(this)
]));
this.addDialog(new ChoicePrompt(ASK_FEEDBACK_PROMPT, this.validateFeedback));
}
const utterance = (context.activity.text || '').trim().toLowerCase();
if (utterance === 'menu' || utterance === 'cancel') {
yield dc.endAll();
}
// Continue the current dialog
yield dc.continueDialog();
// Show menu if no response sent
if (!context.responded) {
yield dc.beginDialog('mainMenu');
}
}
}));
});
const dialogs = new botbuilder_dialogs_1.DialogSet();
// Add prompts
dialogs.add('choicePrompt', new botbuilder_dialogs_1.ChoicePrompt());
dialogs.add('confirmPrompt', new botbuilder_dialogs_1.ConfirmPrompt());
dialogs.add('datetimePrompt', new botbuilder_dialogs_1.DatetimePrompt());
dialogs.add('numberPrompt', new botbuilder_dialogs_1.NumberPrompt());
dialogs.add('textPrompt', new botbuilder_dialogs_1.TextPrompt());
dialogs.add('attachmentPrompt', new botbuilder_dialogs_1.AttachmentPrompt());
//-----------------------------------------------
// Main Menu
//-----------------------------------------------
dialogs.add('mainMenu', [
function (dc) {
return __awaiter(this, void 0, void 0, function* () {
function choice(title, value) {
return {
value: value,
action: { type: botbuilder_1.ActionTypes.ImBack, title: title, value: title }
};
constructor(conversationState, userState) {
this.conversationState = conversationState;
this.userState = userState;
this.dialogState = this.conversationState.createProperty(DIALOG_STATE_PROPERTY);
this.dialogs = new DialogSet(this.dialogState);
this.dialogs.add(new ChoicePrompt(SAMPLE_PROMPT));
}