private async Task DigestActionInputAsync(DialogContext dc, ReplyEmailInfo replyEmailInfo, CancellationToken cancellationToken) { var state = await _stateAccessor.GetAsync(dc.Context, () => new EmailSkillState(), cancellationToken : cancellationToken); state.Content = replyEmailInfo.ReplyMessage; }
// Handles routing to additional dialogs logic. private async Task <DialogTurnResult> RouteStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var activity = stepContext.Context.Activity; var state = await _stateAccessor.GetAsync(stepContext.Context, () => new EmailSkillState(), cancellationToken : cancellationToken); state.IsAction = false; if (activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(activity.Text)) { var result = stepContext.Context.TurnState.Get <EmailLuis>(StateProperties.EmailLuisResult); var intent = result?.TopIntent().intent; var generalResult = stepContext.Context.TurnState.Get <General>(StateProperties.GeneralLuisResult); var generalIntent = generalResult?.TopIntent().intent; var skillOptions = new EmailSkillDialogOptions { SubFlowMode = false }; switch (intent) { case EmailLuis.Intent.SendEmail: { return(await stepContext.BeginDialogAsync(nameof(SendEmailDialog), skillOptions, cancellationToken)); } case EmailLuis.Intent.Forward: { return(await stepContext.BeginDialogAsync(nameof(ForwardEmailDialog), skillOptions, cancellationToken)); } case EmailLuis.Intent.Reply: { return(await stepContext.BeginDialogAsync(nameof(ReplyEmailDialog), skillOptions, cancellationToken)); } case EmailLuis.Intent.SearchMessages: case EmailLuis.Intent.CheckMessages: case EmailLuis.Intent.ReadAloud: case EmailLuis.Intent.QueryLastText: { return(await stepContext.BeginDialogAsync(nameof(ShowEmailDialog), skillOptions, cancellationToken)); } case EmailLuis.Intent.Delete: { return(await stepContext.BeginDialogAsync(nameof(DeleteEmailDialog), skillOptions, cancellationToken)); } case EmailLuis.Intent.ShowNext: case EmailLuis.Intent.ShowPrevious: case EmailLuis.Intent.None: { if (intent == EmailLuis.Intent.ShowNext || intent == EmailLuis.Intent.ShowPrevious || generalIntent == General.Intent.ShowNext || generalIntent == General.Intent.ShowPrevious) { return(await stepContext.BeginDialogAsync(nameof(ShowEmailDialog), skillOptions, cancellationToken)); } else { await stepContext.Context.SendActivityAsync(_templateManager.GenerateActivityForLocale(EmailSharedResponses.DidntUnderstandMessage), cancellationToken); } break; } default: { await stepContext.Context.SendActivityAsync(_templateManager.GenerateActivityForLocale(EmailMainResponses.FeatureNotAvailable), cancellationToken); break; } } } else if (activity.Type == ActivityTypes.Event) { // Handle skill actions here var eventActivity = activity.AsEventActivity(); if (!string.IsNullOrEmpty(eventActivity.Name)) { switch (eventActivity.Name) { // Each Action in the Manifest will have an associated Name which will be on incoming Event activities case "SendEmail": { EmailInfo actionData = null; var eventValue = activity.Value as JObject; if (eventValue != null) { actionData = eventValue.ToObject <EmailInfo>(); await DigestActionInputAsync(stepContext, actionData, cancellationToken); } state.IsAction = true; return(await stepContext.BeginDialogAsync(nameof(SendEmailDialog), new EmailSkillDialogOptions(), cancellationToken)); } case "DeleteEmail": { state.IsAction = true; return(await stepContext.BeginDialogAsync(nameof(DeleteEmailDialog), new EmailSkillDialogOptions(), cancellationToken)); } case "ReplyEmail": { ReplyEmailInfo actionData = null; var eventValue = activity.Value as JObject; if (eventValue != null) { actionData = eventValue.ToObject <ReplyEmailInfo>(); await DigestActionInputAsync(stepContext, actionData, cancellationToken); } state.IsAction = true; return(await stepContext.BeginDialogAsync(nameof(ReplyEmailDialog), new EmailSkillDialogOptions(), cancellationToken)); } case "ForwardEmail": { ForwardEmailInfo actionData = null; var eventValue = activity.Value as JObject; if (eventValue != null) { actionData = eventValue.ToObject <ForwardEmailInfo>(); await DigestActionInputAsync(stepContext, actionData, cancellationToken); } state.IsAction = true; return(await stepContext.BeginDialogAsync(nameof(ForwardEmailDialog), new EmailSkillDialogOptions(), cancellationToken)); } case "EmailSummary": { state.IsAction = true; return(await stepContext.BeginDialogAsync(nameof(ShowEmailDialog), new EmailSkillDialogOptions(), cancellationToken)); } default: // todo: move the response to lg await stepContext.Context.SendActivityAsync(new Activity(type : ActivityTypes.Trace, text : $"Unknown Event '{eventActivity.Name ?? "undefined"}' was received but not processed."), cancellationToken); break; } } } // If activity was unhandled, flow should continue to next step return(await stepContext.NextAsync(cancellationToken : cancellationToken)); }