in SDKV4-Samples/js/complexDialogBot/bot.js [72:108]
async onTurn(turnContext) {
if (turnContext.activity.type === ActivityTypes.Message) {
// Run the DialogSet - let the framework identify the current state of the dialog from
// the dialog stack and figure out what (if any) is the active dialog.
const dialogContext = await this.dialogs.createContext(turnContext);
const results = await dialogContext.continueDialog();
switch (results.status) {
case DialogTurnStatus.cancelled:
case DialogTurnStatus.empty:
// If there is no active dialog, we should clear the user info and start a new dialog.
await this.userProfileAccessor.set(turnContext, {});
await this.userState.saveChanges(turnContext);
await dialogContext.beginDialog(TOP_LEVEL_DIALOG);
break;
case DialogTurnStatus.complete:
// If we just finished the dialog, capture and display the results.
const userInfo = results.result;
const status = 'You are signed up to review '
+ (userInfo.companiesToReview.length === 0 ? 'no companies' : userInfo.companiesToReview.join(' and '))
+ '.';
await turnContext.sendActivity(status);
await this.userProfileAccessor.set(turnContext, userInfo);
await this.userState.saveChanges(turnContext);
break;
case DialogTurnStatus.waiting:
// If there is an active dialog, we don't need to do anything here.
break;
}
await this.conversationState.saveChanges(turnContext);
} else if (turnContext.activity.type === ActivityTypes.ConversationUpdate) {
if (turnContext.activity.membersAdded && turnContext.activity.membersAdded.length > 0) {
await this.sendWelcomeMessage(turnContext);
}
} else {
await turnContext.sendActivity(`[${turnContext.activity.type} event detected]`);
}
}