/// <summary> /// OnExtractHistoryFetchTaskAsync /// </summary> /// <param name="turnContext">turnContext</param> /// <param name="action">action</param> /// <param name="cancellationToken">cancellationToken</param> /// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns> public async Task <MessagingExtensionActionResponse> OnExtractHistoryFetchTaskAsync(ITurnContext <IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken) { var attachment = AdaptiveTextCard(Resources.Strings.UnsupportedConversation); if (turnContext.IsSupportedConversation()) { if (action.CommandId == CommandId) { // Auth checking. Login form will be opened if auth required var isAuthenticated = await IsAuthenticated(turnContext, cancellationToken); if (!isAuthenticated) { return(await Authenticate(turnContext, action, cancellationToken)); } else if (await turnContext.IsBotAddedToTheConversationAsync()) { attachment = ExtractHistoryMessagingExtensionCard.Generate(turnContext, configuration.ReportFormats); } else { attachment = ExtractHistoryMessagingExtensionCard.GenerateInstallCard(turnContext); } } } return(new MessagingExtensionActionResponse { Task = this.TaskModuleReportCardTask(turnContext, attachment), }); }
/// <summary> /// This is handler for MessagingExtensionSubmitAction event inside bot for current extension. /// Should be called inside bot OnTurnAsync method for MessagingExtensionSubmitAction event. /// This methods check a commandId parameter inside context and runs task module if commandId matches current extension commandId. /// Triggers report preparing after report settings card submit. /// </summary> /// <param name="turnContext">The turn context.</param> /// <param name="action">Action.</param> /// <param name="cancellationToken">The cancellation token.</param> public async Task <MessagingExtensionActionResponse> OnExtractHistorySubmitAction(ITurnContext <IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken) { var attachment = AdaptiveTextCard(Resources.Strings.UnsupportedConversation); // is this supported conversation if (turnContext.IsSupportedConversation()) { if (action.CommandId == CommandId) { if (IsBotJustInstalled(turnContext)) { attachment = ExtractHistoryMessagingExtensionCard.Generate(turnContext, configuration.ReportFormats); } else { var isignOutAction = turnContext.GetData()?["action"]?.Value <string>() == ExtractHistoryMessagingExtensionCard.SignOutAction; if (isignOutAction) { return(await SignOut(turnContext, cancellationToken)); } var reportParameters = await GetReportParametersAsync(turnContext); attachment = AdaptiveTextCard(Resources.Strings.MessageExtFilePreparingMessage); // run report preparing as background task because we need close task module for teams. this.queue.QueueBackgroundTask(async token => { using (var scope = this.serviceScopeFactory.CreateScope()) { try { var file = await HistoryReportService.PrepareReportInOneDrive(turnContext, reportParameters, cancellationToken); var fileIsReadyMessage = AdaptiveCardsHelper.GetPersonalFileCard(file, Resources.Strings.DialogReportReadyMessage); fileIsReadyMessage.AddMentionToText(turnContext.Activity.From); await privateChat.SendPersonalMessage(turnContext, fileIsReadyMessage, cancellationToken); var updMessage = MessageFactory.Text(MessageHelper.BuildUserExportedHistoryMessage(turnContext, reportParameters)); await turnContext.SendActivityAsync(updMessage, cancellationToken); } catch (Exception ex) { logger.LogError("Report generation error", ex); var message = MessageFactory.Text("Error happened during report genaration. Please, try again."); message.AddMentionToText(turnContext.Activity.From); await privateChat.SendPersonalMessage(turnContext, message, cancellationToken); } } }); } } } return(new MessagingExtensionActionResponse { Task = this.TaskModuleReportCardTask(turnContext, attachment), }); }