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.");
}
});
},
// Confirm to user
yield dc.context.sendActivity(`Your alarm named "${alarm.title}" is set for "${moment(alarm.time).format("ddd, MMM Do, h:mm a")}".`);
yield dc.endDialog();
});
}
]);
this.dialogs.add('titlePrompt', new botbuilder_dialogs_1.TextPrompt((context, value) => __awaiter(this, void 0, void 0, function* () {
if (!value || value.length < 3) {
yield context.sendActivity(`Title should be at least 3 characters long.`);
return undefined;
}
else {
return value.trim();
}
})));
this.dialogs.add('timePrompt', new botbuilder_dialogs_1.DatetimePrompt((context, values) => __awaiter(this, void 0, void 0, function* () {
try {
if (!Array.isArray(values) || values.length < 0) {
throw new Error('missing time');
}
if (values[0].type !== 'datetime') {
throw new Error('unsupported type');
}
const value = new Date(values[0].value);
if (value.getTime() < new Date().getTime()) {
throw new Error('in the past');
}
return value;
}
catch (err) {
yield context.sendActivity(`Please enter a valid time in the future like "tomorrow at 9am" or say "cancel".`);
return undefined;
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,
action: { type: ActionTypes.ImBack, title: title, value: title }
};
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 }
};
}
yield dc.prompt('choicePrompt', `Select a demo to run:`, [
// Confirm to user
await dc.context.sendActivity(`Your alarm named "${alarm.title}" is set for "${moment(alarm.time).format("ddd, MMM Do, h:mm a")}".`);
await dc.end();
})
]));
this.dialogs.add('titlePrompt', new TextPrompt(async (context, value) => {
if (!value || value.length < 3) {
await context.sendActivity(`Title should be at least 3 characters long.`);
return undefined;
} else {
return value.trim();
}
}));
this.dialogs.add('timePrompt', new DatetimePrompt(async (context, values) => {
try {
if (!Array.isArray(values) || values.length < 0) { throw new Error('missing time') }
if (values[0].type !== 'datetime') { throw new Error('unsupported type') }
const value = new Date(values[0].value);
if (value.getTime() < new Date().getTime()) { throw new Error('in the past') }
return value;
} catch (err) {
await context.sendActivity(`Please enter a valid time in the future like "tomorrow at 9am" or say "cancel".`);
return undefined;
}
}));
}
}
});
});
// Add dialogs
dialogs.add('default', [
async function (dc, args) {
const state = conversationState.get(dc.context);
await dc.context.sendActivity(`Hi! I'm the Contoso Cafe reservation bot. Say something like make a reservation."`);
await dc.end();
}
]);
dialogs.add('textPrompt', new TextPrompt());
dialogs.add('dateTimePrompt', new DatetimePrompt());
dialogs.add('reserveTable', [
async function(dc, args, next){
var typedresult = args as CafeLUISModel;
// Call a helper function to save the entities in the LUIS result
// to dialog state
await SaveEntities(dc, typedresult);
await dc.context.sendActivity("Welcome to the reservation service.");
if (dc.activeDialog.state.dateTime) {
await next();
}
else {
await dc.prompt('dateTimePrompt', "Please provide a reservation date and time. We're open 4PM-8PM.");
}
dialogs.add(
'titlePrompt',
new TextPrompt(async (dc, value) => {
if (!value || value.length < 3) {
await dc.context.sendActivity(`Title should be at least 3 characters long.`);
return undefined;
} else {
return value.trim();
}
})
);
dialogs.add(
'timePrompt',
new DatetimePrompt(async (dc, values) => {
try {
if (!Array.isArray(values) || values.length < 0) {
throw new Error('missing time');
}
const value = moment(values[0].value, 'hh:mm a');
if (value.toDate().getTime() < new Date().getTime()) {
throw new Error('in the past');
}
return value;
} catch (err) {
await dc.context.sendActivity(`Please enter a valid time in the future like "tomorrow at 9am" or say "cancel".`);
return undefined;
}
})
);