private async Task <DialogTurnResult> ReportAuthCheckingStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var state = await reportStateAccessor.GetAsync(stepContext.Context, () => null); if (state == null) { return(await EndDialogAsync(stepContext, cancellationToken)); } var previousStepResult = CardSubmitResult <string> .Get(stepContext); if (previousStepResult != null) { if (ReportFileFormatConverter.TryParse(previousStepResult.Result, out ReportFormatType format)) { state.Format = format; } else { return(await EndDialogAsync(stepContext, cancellationToken, Resources.Strings.DialogReportFormatErrorMessage)); } } else { return(await CancelCurrentAndBeginNew(stepContext, cancellationToken)); } return(await stepContext.BeginDialogAsync(nameof(OAuthPrompt), null, cancellationToken)); }
/// <summary> /// Initializes the authentication checking step asynchronous. /// </summary> /// <param name="stepContext">The step context.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task <DialogTurnResult> ReportAuthCheckingStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // load dialog state var state = await this.reportStateAccessor.GetAsync(stepContext.Context, () => null); // check dialog state if (state == null) { return(await EndDialogAsync(stepContext, cancellationToken)); } if (stepContext.Result is FoundChoice choice && ReportFileFormatConverter.TryParse(choice.Value, out ReportFormatType format)) { state.Format = format; }
private async Task <DialogTurnResult> ReportFileFormatStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var state = await reportStateAccessor.GetAsync(stepContext.Context, () => null); if (state == null) { return(await EndDialogAsync(stepContext, cancellationToken)); } var previousStepResult = CardSubmitResult <string> .Get(stepContext); if (state.ReportType == ReportSourceType.Conversation) { state.ReportPeriod = ReportPeriodType.AllTime; } else { if (previousStepResult != null) { if (ReportPeriodConverter.TryParse(previousStepResult.Result, out ReportPeriodType period)) { state.ReportPeriod = period; } else { return(await EndDialogAsync(stepContext, cancellationToken, Resources.Strings.DialogTimePeriodErrorMessage)); } } else { return(await CancelCurrentAndBeginNew(stepContext, cancellationToken)); } } var formats = configuration.ReportFormats.Select(x => ReportFileFormatConverter.GetReportFormat(x)).ToList(); var message = AdaptiveCardsHelper.GetChoicesPrompt(Resources.Strings.DialogFileTypeReportMessage, formats); message.Id = state.MessageId; await stepContext.Context.UpdateActivityAsync(message, cancellationToken); await reportStateAccessor.SetAsync(stepContext.Context, state); return(new DialogTurnResult(DialogTurnStatus.Waiting) { ParentEnded = false }); }
private async Task <ReportParameters> GetReportParametersAsync(ITurnContext <IInvokeActivity> turnContext) { var settings = ((JObject)turnContext.Activity.Value)["data"].Value <JObject>(); var reportParams = new ReportParameters(); if (turnContext.Activity.Conversation.ConversationType == Constants.ChannelConversationType) { var reportType = settings[ExtractHistoryMessagingExtensionCard.ChannelScopeInputId]?.Value <string>() ?? string.Empty; if (reportType.Equals(Resources.Strings.ChannelHistoryOptionConversation)) { reportParams.ReportType = ReportSourceType.Conversation; } else if (reportType.Equals(Resources.Strings.ChannelHistoryOptionAll)) { reportParams.ReportType = ReportSourceType.Channel; } } else { reportParams.ReportType = ReportSourceType.Chat; } await reportParams.FillRestDetailsFromActivity(turnContext); var timeRange = settings[ExtractHistoryMessagingExtensionCard.TimeRangeInputId]?.Value <string>(); if (ReportPeriodConverter.TryParse(timeRange, out ReportPeriodType period)) { reportParams.ReportPeriod = period; } else { SendUnsupportedMessage(turnContext).Wait(); } var formatType = settings[ExtractHistoryMessagingExtensionCard.ReportTypeInputId]?.Value <string>(); if (ReportFileFormatConverter.TryParse(formatType, out ReportFormatType type)) { reportParams.Format = type; } else { SendUnsupportedMessage(turnContext).Wait(); } return(reportParams); }
/// <summary> /// Initializes the history time range selection step asynchronous. /// </summary> /// <param name="stepContext">The step context.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task <DialogTurnResult> ReportFileFormatStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // load dialog state var state = await this.reportStateAccessor.GetAsync(stepContext.Context, () => null); // check dialog state if (state == null) { return(await EndDialogAsync(stepContext, cancellationToken)); } // process ChoicePrompt (time range) result from previous step if (stepContext.Result is FoundChoice choice) { if (ReportPeriodConverter.TryParse(choice.Value, out ReportPeriodType period)) { state.ReportPeriod = period; } else { return(await EndDialogAsync(stepContext, cancellationToken, Resources.Strings.DialogTimePeriodErrorMessage)); } } // if result is not from ChoicePrompt then check report type else if (state.ReportType == ReportSourceType.Conversation) { state.ReportPeriod = ReportPeriodType.AllTime; } else { return(await EndDialogAsync(stepContext, cancellationToken, Resources.Strings.DialogTimePeriodErrorMessage, true)); } var formats = configuration.ReportFormats.Select(x => ReportFileFormatConverter.GetReportFormat(x)).ToList(); var prompt = new PromptOptions { Prompt = MessageFactory.Text(Resources.Strings.DialogFileTypeReportMessage), Choices = ChoiceFactory.ToChoices(formats), Style = ListStyle.HeroCard, }; await this.reportStateAccessor.SetAsync(stepContext.Context, state); return(await stepContext.PromptAsync(nameof(ChoicePrompt), prompt, cancellationToken)); }
public static Attachment Generate(ITurnContext turnContext, List <ReportFormatType> reportFormats) { AdaptiveCard adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0)); // Scope choice set for channel/ message for group chat var scopeContainer = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; var conversationType = turnContext.Activity.Conversation.ConversationType; if (conversationType == Constants.ChannelConversationType) { scopeContainer.Items.Add(new AdaptiveTextBlock(Resources.Strings.MessageExtChannelScopeMessage) { Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Default, Wrap = true, }); var choiceSet = new AdaptiveChoiceSetInput() { Id = ChannelScopeInputId, Style = AdaptiveChoiceInputStyle.Expanded, Choices = new List <AdaptiveChoice>() { new AdaptiveChoice() { Value = Resources.Strings.ChannelHistoryOptionAll, Title = Resources.Strings.ChannelHistoryOptionAll, }, new AdaptiveChoice() { Value = Resources.Strings.ChannelHistoryOptionConversation, Title = Resources.Strings.ChannelHistoryOptionConversation, }, }, Value = Resources.Strings.ChannelHistoryOptionAll, }; scopeContainer.Items.Add(choiceSet); } adaptiveCard.Body.Add(scopeContainer); // Timer range choice set var timeRangeContainer = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; timeRangeContainer.Items.Add(new AdaptiveTextBlock(Resources.Strings.MessageExtTimeRangeReportMessage) { Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Default, Wrap = true, }); var timeSet = new AdaptiveChoiceSetInput() { Id = TimeRangeInputId, Style = AdaptiveChoiceInputStyle.Expanded, Choices = new List <AdaptiveChoice>() { new AdaptiveChoice() { Value = Resources.Strings.TimePeriodOptionAllTime, Title = Resources.Strings.TimePeriodOptionAllTime, }, new AdaptiveChoice() { Value = Resources.Strings.TimePeriodOptionLast7Days, Title = Resources.Strings.TimePeriodOptionLast7Days, }, new AdaptiveChoice() { Value = Resources.Strings.TimePeriodOptionLastDay, Title = Resources.Strings.TimePeriodOptionLastDay, }, }, Value = Resources.Strings.TimePeriodOptionAllTime, }; timeRangeContainer.Items.Add(timeSet); adaptiveCard.Body.Add(timeRangeContainer); // File format choice set var fileFormatContainer = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; fileFormatContainer.Items.Add(new AdaptiveTextBlock(Resources.Strings.MessageExtFileTypeReportMessage) { Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Default, Wrap = true, }); var reportFormatChoices = reportFormats.Select(x => new AdaptiveChoice() { Value = ReportFileFormatConverter.GetReportFormat(x), Title = ReportFileFormatConverter.GetReportFormat(x), }).ToList(); var formatSet = new AdaptiveChoiceSetInput() { Id = ReportTypeInputId, Style = AdaptiveChoiceInputStyle.Expanded, Choices = reportFormatChoices, Value = reportFormatChoices.First().Value, }; fileFormatContainer.Items.Add(formatSet); adaptiveCard.Body.Add(fileFormatContainer); adaptiveCard.Actions.Add(new AdaptiveSubmitAction() { Title = Resources.Strings.SignOutButtonText, Data = new Dictionary <string, string> { ["action"] = SignOutAction }, }); adaptiveCard.Actions.Add(new AdaptiveSubmitAction() { Title = Resources.Strings.MessageExtExtractButton, Id = GenerateBtnId, Data = new Dictionary <string, string> { ["action"] = GenerateReportAction }, }); return(adaptiveCard.ToAttachment()); }