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); }
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 }); }
/// <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)); }