in SDKV4-Samples/js/DialogPromptBot/bot.js [49:97]
async onTurn(turnContext) {
switch (turnContext.activity.type) {
case ActivityTypes.Message:
// Get the current reservation info from state.
const reservation = await this.reservationAccessor.get(turnContext, null);
// Generate a dialog context for our dialog set.
const dc = await this.dialogSet.createContext(turnContext);
if (!dc.activeDialog) {
// If there is no active dialog, check whether we have a reservation yet.
if (!reservation) {
// If not, start the dialog.
await dc.beginDialog(RESERVATION_DIALOG);
}
else {
// Otherwise, send a status message.
await turnContext.sendActivity(
`We'll see you on ${reservation.date}.`);
}
}
else {
// Continue the dialog.
const dialogTurnResult = await dc.continueDialog();
// If the dialog completed this turn, record the reservation info.
if (dialogTurnResult.status === DialogTurnStatus.complete) {
await this.reservationAccessor.set(
turnContext,
dialogTurnResult.result);
// Send a confirmation message to the user.
await turnContext.sendActivity(
`Your party of ${dialogTurnResult.result.size} is ` +
`confirmed for ${dialogTurnResult.result.date} in ` +
`${dialogTurnResult.result.location}.`);
}
}
// Save the updated dialog state into the conversation state.
await this.conversationState.saveChanges(turnContext, false);
break;
case ActivityTypes.EndOfConversation:
case ActivityTypes.DeleteUserData:
break;
default:
break;
}
}