Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
}
}
}));
});
// Add dialogs
dialogs.add('default', [
function (dc, args) {
return __awaiter(this, void 0, void 0, function* () {
const state = conversationState.get(dc.context);
yield dc.context.sendActivity(`Hi! I'm the Contoso Cafe reservation bot. Say something like make a reservation."`);
yield dc.end();
});
}
]);
dialogs.add('textPrompt', new botbuilder_dialogs_1.TextPrompt());
dialogs.add('dateTimePrompt', new botbuilder_dialogs_1.DatetimePrompt());
dialogs.add('reserveTable', [
function (dc, args, next) {
return __awaiter(this, void 0, void 0, function* () {
var typedresult = args;
// Call a helper function to save the entities in the LUIS result
// to dialog state
yield SaveEntities(dc, typedresult);
yield dc.context.sendActivity("Welcome to the reservation service.");
if (dc.activeDialog.state.dateTime) {
yield next();
}
else {
yield dc.prompt('dateTimePrompt', "Please provide a reservation date and time. We're open 4PM-8PM.");
}
});
if (!dialogId) throw new Error('Missing parameter. dialogId is required');
if (!userProfileAccessor) throw new Error('Missing parameter. userProfileAccessor is required');
// Add a water fall dialog with 4 steps.
// The order of step function registration is important
// as a water fall dialog executes steps registered in order
this.addDialog(new WaterfallDialog(PROFILE_DIALOG, [
this.initializeStateStep.bind(this),
this.promptForNameStep.bind(this),
this.promptForCityStep.bind(this),
this.displayGreetingStep.bind(this)
]));
// Add text prompts for name and city
this.addDialog(new TextPrompt(NAME_PROMPT, this.validateName));
this.addDialog(new TextPrompt(CITY_PROMPT, this.validateCity));
// Save off our state accessor for later use
this.userProfileAccessor = userProfileAccessor;
}
/**
// 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 }
};
}
yield dc.prompt('choicePrompt', `Select a demo to run:`, [
choice('choice', 'choiceDemo'),
choice('confirm', 'confirmDemo'),
// validate what was passed in
if (!userDataAccessor) throw new Error('Missing parameter. userDataAccessor is required');
// Add a water fall dialog with 4 steps.
// The order of step function registration is important
// as a water fall dialog executes steps registered in order.
this.addDialog(new WaterfallDialog(PROFILE_DIALOG, [
this.initializeStateStep.bind(this),
this.promptForNameStep.bind(this),
this.promptForCityStep.bind(this),
this.displayGreetingStep.bind(this)
]));
// Add text prompts for name and city
this.addDialog(new TextPrompt(NAME_PROMPT, this.validateName.bind(this)));
this.addDialog(new TextPrompt(CITY_PROMPT, this.validateCity.bind(this)));
// Save off our state accessor for later use
this.userDataAccessor = userDataAccessor;
}
// // Helper function for finding a specified entity. entityResults are the results from LuisRecognizer.get(context)
// function findEntities(entityName, entityResults) {
// let entities = []
// if (entityName in entityResults) {
// entityResults[entityName].forEach(entity => {
// entities.push(entity);
// });
// }
// return entities.length > 0 ? entities : undefined;
// }
// register some dialogs for usage with the intents detected by the LUIS app
const dialogs = new DialogSet();
dialogs.add('textPrompt', new TextPrompt());
dialogs.add('BalanceDialog', [
async function(dc){
let balance = Math.floor(Math.random() * Math.floor(100));
await dc.context.sendActivity(`Your balance is £${balance}.`);
await dc.continue();
},
async function(dc){
await dc.context.sendActivity(`OK, we're done here. What is next?`);
await dc.continue();
},
async function(dc){
await dc.end();
}
]);
if (!dialogId) { throw new Error('Missing parameter. dialogId is required'); }
if (!userProfileAccessor) { throw new Error('Missing parameter. userProfileAccessor is required'); }
// Add a water fall dialog with 4 steps.
// The order of step function registration is important
// as a water fall dialog executes steps registered in order
this.addDialog(new WaterfallDialog(PROFILE_DIALOG, [
this.initializeStateStep.bind(this),
this.promptForNameStep.bind(this),
this.promptForCityStep.bind(this),
this.displayGreetingStateStep.bind(this),
]));
// Add text prompts for name and city
this.addDialog(new TextPrompt(NAME_PROMPT, this.validateName));
this.addDialog(new TextPrompt(CITY_PROMPT, this.validateCity));
// Save off our state accessor for later use
this.userProfileAccessor = userProfileAccessor;
}
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, [
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, [
return __awaiter(this, void 0, void 0, function* () {
// Initialize the state
const state = dc.activeDialog.state;
state.options = options || {};
state.values = Object.assign({}, options);
// Add a prompt used for question turns
if (!this._prompt) {
this._prompt = this.id + '_default_prompt';
dc.dialogs.add(new botbuilder_dialogs_1.TextPrompt(this._prompt));
}
// Run the first step
return yield this.runStep(dc, 0, state.options.thread || 'default', botbuilder_dialogs_1.DialogReason.beginCalled);
});
}
constructor(id) {
super(id || 'bookingDialog');
this.addDialog(new TextPrompt(TEXT_PROMPT))
.addDialog(new ConfirmPrompt(CONFIRM_PROMPT))
.addDialog(new DateResolverDialog(DATE_RESOLVER_DIALOG))
.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.destinationStep.bind(this),
this.originStep.bind(this),
this.travelDateStep.bind(this),
this.confirmStep.bind(this),
this.finalStep.bind(this)
]));
this.initialDialogId = WATERFALL_DIALOG;
}