/// <summary> /// Remove reflection id based in messageid /// </summary> /// <param name="reflectionMessageId">reflectionMessageId</param> /// <returns>messageid.</returns> public async Task <string> RemoveReflectionId(string reflectionMessageId) { string messageId = null; try { _telemetry.TrackEvent("RemoveMessageId"); ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); var reflection = await reflectionDataRepository.GetReflectionData(reflectionMessageId); messageId = reflection.MessageID; var feedbackCount = await feedbackDataRepository.GetFeedbackonRefId(reflection.ReflectionID); await feedbackDataRepository.DeleteAsync(feedbackCount); await reflectionDataRepository.DeleteAsync(reflection); } catch (Exception ex) { _telemetry.TrackException(ex); } return(messageId); }
/// <summary> /// Initializes a new instance of the <see cref="DIConnectBot"/> class. /// </summary> /// <param name="logger">Instance to send logs to the Application Insights service.</param> /// <param name="teamsDataCapture">Teams data capture service.</param> /// <param name="employeeResourceGroupRepository">Instance of employee resource group repository.</param> /// <param name="teamsFileUpload">Teams file upload service.</param> /// <param name="teamNotification">Send team notification service.</param> /// <param name="knowledgeBaseResponse">Knowledge base response instance.</param> /// <param name="feedbackDataRepository">Feedback data repository instance.</param> /// <param name="notificationCardHelper">Notification card helper instance.</param> /// <param name="botOptions">A set of key/value application bot configuration properties.</param> /// <param name="localizer">Localization service.</param> /// <param name="cardHelper">Instance of class that handles adaptive card helper methods.</param> /// <param name="teamUserPairUpMappingRepository">Instance of team pair-up repository to access user pair-up matches.</param> /// <param name="userTeamMappingsHelper">Instance of helper for user mappings for a Team.</param> public DIConnectBot( ILogger <DIConnectBot> logger, TeamsDataCapture teamsDataCapture, EmployeeResourceGroupRepository employeeResourceGroupRepository, TeamsFileUpload teamsFileUpload, KnowledgeBaseResponse knowledgeBaseResponse, FeedbackDataRepository feedbackDataRepository, NotificationCardHelper notificationCardHelper, IOptions <BotOptions> botOptions, IStringLocalizer <Strings> localizer, AdminTeamNotifier teamNotification, TeamUserPairUpMappingRepository teamUserPairUpMappingRepository, CardHelper cardHelper, UserTeamMappingsHelper userTeamMappingsHelper) { this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.teamsDataCapture = teamsDataCapture ?? throw new ArgumentNullException(nameof(teamsDataCapture)); this.employeeResourceGroupRepository = employeeResourceGroupRepository ?? throw new ArgumentNullException(nameof(employeeResourceGroupRepository)); this.teamsFileUpload = teamsFileUpload ?? throw new ArgumentNullException(nameof(teamsFileUpload)); this.knowledgeBaseResponse = knowledgeBaseResponse ?? throw new ArgumentNullException(nameof(knowledgeBaseResponse)); this.feedbackDataRepository = feedbackDataRepository ?? throw new ArgumentNullException(nameof(feedbackDataRepository)); this.notificationCardHelper = notificationCardHelper ?? throw new ArgumentNullException(nameof(notificationCardHelper)); this.botOptions = botOptions ?? throw new ArgumentNullException(nameof(botOptions)); this.teamNotification = teamNotification ?? throw new ArgumentNullException(nameof(teamNotification)); this.localizer = localizer ?? throw new ArgumentNullException(nameof(localizer)); this.botOptions = botOptions ?? throw new ArgumentNullException(nameof(botOptions)); this.teamUserPairUpMappingRepository = teamUserPairUpMappingRepository ?? throw new ArgumentNullException(nameof(teamUserPairUpMappingRepository)); this.cardHelper = cardHelper ?? throw new ArgumentNullException(nameof(cardHelper)); this.userTeamMappingsHelper = userTeamMappingsHelper ?? throw new ArgumentNullException(nameof(userTeamMappingsHelper)); }
/// <summary> /// Add Reflection data in Table Storage. /// </summary> /// <param name="taskInfo">taskInfo.</param> /// <returns>A task that represents the work queued to execute.</returns> public async Task SaveReflectionFeedbackDataAsync(UserfeedbackInfo taskInfo) { _telemetry.TrackEvent("DeleteReflections"); try { FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); if (taskInfo != null) { var feedbackID = Guid.NewGuid(); var rowKey = Guid.NewGuid(); FeedbackDataEntity feedbackDataEntity = new FeedbackDataEntity { PartitionKey = PartitionKeyNames.FeedbackDataTable.FeedbackDataPartition, RowKey = rowKey.ToString(), FeedbackID = feedbackID, FullName = taskInfo.userName, ReflectionID = taskInfo.reflectionId, FeedbackGivenBy = taskInfo.emailId, Feedback = Convert.ToInt32(taskInfo.feedbackId) }; await feedbackDataRepository.InsertOrMergeAsync(feedbackDataEntity); } } catch (Exception ex) { _telemetry.TrackException(ex); } }
/// <summary> /// Gets view reflections data. /// </summary> /// <param name="reflectionId">reflectionId.</param> /// <returns>A task that represents the work queued to execute.</returns> public async Task <ViewReflectionsEntity> GetViewReflectionsData(Guid reflectionId) { _telemetry.TrackEvent("GetViewReflectionsData"); try { ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); ViewReflectionsEntity viewReflectionsEntity = new ViewReflectionsEntity(); QuestionsDataRepository questionsDataRepository = new QuestionsDataRepository(_configuration, _telemetry); // Get reflection data ReflectionDataEntity refData = await reflectionDataRepository.GetReflectionData(reflectionId) ?? null; Dictionary <int, List <FeedbackDataEntity> > feedbackData = await feedbackDataRepository.GetReflectionFeedback(reflectionId) ?? null; List <QuestionsDataEntity> questions = await questionsDataRepository.GetQuestionsByQID(refData.QuestionID) ?? null; viewReflectionsEntity.ReflectionData = refData; viewReflectionsEntity.FeedbackData = feedbackData; viewReflectionsEntity.Question = questions.Find(x => x.QuestionID == refData.QuestionID); return(viewReflectionsEntity); } catch (Exception ex) { _telemetry.TrackException(ex); return(null); } }
public async Task <string> SaveUserFeedback([FromBody] UserfeedbackInfo data) { try { _telemetry.TrackEvent("SaveUserFeedback"); FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); // Check if this is user's second feedback FeedbackDataEntity feebackData = await feedbackDataRepository.GetReflectionFeedback(data.reflectionId, data.emailId); if (data.feedbackId == 0) { await feedbackDataRepository.DeleteFeedback(feebackData); } else { if (feebackData != null && data.emailId == feebackData.FeedbackGivenBy) { feebackData.Feedback = data.feedbackId; await feedbackDataRepository.CreateOrUpdateAsync(feebackData); } else { await _dbHelper.SaveReflectionFeedbackDataAsync(data); } } return("true"); } catch (Exception e) { _telemetry.TrackEvent("SaveUserFeedback Exception " + e); return("false"); } }
/// <summary> /// On Teams Task Module Submit Async. /// </summary> /// <param name="turnContext">turnContext.</param> /// <param name="taskModuleRequest">taskModuleRequest.</param> /// <param name="cancellationToken">cancellationToken.</param> /// <returns>.</returns> protected override async Task <TaskModuleResponse> OnTeamsTaskModuleSubmitAsync(ITurnContext <IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken) { ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); QuestionsDataRepository questiondatarepository = new QuestionsDataRepository(_configuration, _telemetry); FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); try { TaskInfo taskInfo = JsonConvert.DeserializeObject <TaskInfo>(taskModuleRequest.Data.ToString()); var reply = Activity.CreateMessageActivity(); // Check if message id is present in reflect data ReflectionDataEntity reflectData = await reflectionDataRepository.GetReflectionData(taskInfo.reflectionID); QuestionsDataEntity question = await questiondatarepository.GetQuestionData(reflectData.QuestionID); Dictionary <int, List <FeedbackDataEntity> > feedbacks = await feedbackDataRepository.GetReflectionFeedback(taskInfo.reflectionID); var adaptiveCard = _cardHelper.FeedBackCard(feedbacks, taskInfo.reflectionID, question.Question); Attachment attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = adaptiveCard }; reply.Attachments.Add(attachment); if (reflectData.MessageID == null) { var result = turnContext.SendActivityAsync(reply, cancellationToken); reflectData.MessageID = result.Result.Id; // update messageid in reflection table await reflectionDataRepository.InsertOrMergeAsync(reflectData); } else { reply.Id = reflectData.MessageID; await turnContext.UpdateActivityAsync(reply); } return(null); } catch (System.Exception e) { _telemetry.TrackException(e); Console.WriteLine(e.Message.ToString()); return(null); } }
public async Task <int?> GetUserFeedback([FromBody] UserfeedbackInfo data) { try { _telemetry.TrackEvent("GetUserFeedback"); FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); // Check if this is user's second feedback FeedbackDataEntity feebackData = await feedbackDataRepository.GetReflectionFeedback(data.reflectionId, data.emailId); if (feebackData != null && data.emailId == feebackData.FeedbackGivenBy) { return(feebackData.Feedback); } else { return(0); } } catch (Exception e) { _telemetry.TrackEvent("GetUserFeedback Exception " + e); return(null); } }
/// <summary> /// On message activity sync. /// </summary> /// <param name="turnContext">turnContext.</param> /// <param name="cancellationToken">cancellationToken.</param> /// <returns>.</returns> protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { _telemetry.TrackEvent("OnMessageActivityAsync"); try { FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); RecurssionDataRepository recurssionDataRepository = new RecurssionDataRepository(_configuration, _telemetry); QuestionsDataRepository questiondatarepository = new QuestionsDataRepository(_configuration, _telemetry); if (turnContext.Activity.Value != null) { var response = JsonConvert.DeserializeObject <UserfeedbackInfo>(turnContext.Activity.Value.ToString()); var reply = Activity.CreateMessageActivity(); if (response.type == ReflectConstants.SaveFeedBack) { var name = (turnContext.Activity.From.Name).Split(); response.userName = name[0] + ' ' + name[1]; response.emailId = await _dbHelper.GetUserEmailId(turnContext); // Check if this is user's second feedback FeedbackDataEntity feebackData = await feedbackDataRepository.GetReflectionFeedback(response.reflectionId, response.emailId); if (feebackData != null && response.emailId == feebackData.FeedbackGivenBy) { feebackData.Feedback = response.feedbackId; await feedbackDataRepository.CreateOrUpdateAsync(feebackData); } else { await _dbHelper.SaveReflectionFeedbackDataAsync(response); } try { // Check if message id is present in reflect data ReflectionDataEntity reflectData = await reflectionDataRepository.GetReflectionData(response.reflectionId); QuestionsDataEntity question = await questiondatarepository.GetQuestionData(reflectData.QuestionID); Dictionary <int, List <FeedbackDataEntity> > feedbacks = await feedbackDataRepository.GetReflectionFeedback(response.reflectionId); var adaptiveCard = _cardHelper.FeedBackCard(feedbacks, response.reflectionId, question.Question); TaskInfo taskInfo = new TaskInfo(); taskInfo.question = question.Question; taskInfo.postCreateBy = reflectData.CreatedBy; taskInfo.privacy = reflectData.Privacy; taskInfo.reflectionID = reflectData.ReflectionID; Attachment attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = adaptiveCard }; reply.Attachments.Add(attachment); if (reflectData.MessageID == null) { var result = turnContext.SendActivityAsync(reply, cancellationToken); reflectData.MessageID = result.Result.Id; // update message-id in reflection table await reflectionDataRepository.InsertOrMergeAsync(reflectData); } else { reply.Id = reflectData.MessageID; await turnContext.UpdateActivityAsync(reply); } } catch (System.Exception e) { _telemetry.TrackException(e); Console.WriteLine(e.Message.ToString()); } } } else { await turnContext.SendActivityAsync(MessageFactory.Text($"Hello from Olga."), cancellationToken); } } catch (Exception ex) { _telemetry.TrackException(ex); } }
/// <summary> /// On Teams Task Module Fetch Async. /// </summary> /// <param name="turnContext">turnContext.</param> /// <param name="taskModuleRequest">taskModuleRequest.</param> /// <param name="cancellationToken">cancellationToken.</param> /// <returns>.</returns> protected override async Task <TaskModuleResponse> OnTeamsTaskModuleFetchAsync(ITurnContext <IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken) { _telemetry.TrackEvent("OnTeamsTaskModuleFetchAsync"); try { ReflctionData reldata = JsonConvert.DeserializeObject <ReflctionData>(taskModuleRequest.Data.ToString()); FeedbackDataRepository feedbackDataRepository = new FeedbackDataRepository(_configuration, _telemetry); ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry); RecurssionDataRepository recurssionDataRepository = new RecurssionDataRepository(_configuration, _telemetry); QuestionsDataRepository questiondatarepository = new QuestionsDataRepository(_configuration, _telemetry); var response = new UserfeedbackInfo(); var name = (turnContext.Activity.From.Name).Split(); response.userName = name[0] + ' ' + name[1]; response.emailId = await _dbHelper.GetUserEmailId(turnContext); var reflectionid = reldata.datajson.ReflectionId; var feedbackId = reldata.datajson.FeedbackId; response.reflectionId = reflectionid; response.feedbackId = feedbackId; // Check if this is user's second feedback FeedbackDataEntity feebackData = await feedbackDataRepository.GetReflectionFeedback(response.reflectionId, response.emailId); TaskInfo taskInfo = new TaskInfo(); if (response.feedbackId != 0) { if (feebackData != null && response.emailId == feebackData.FeedbackGivenBy) { feebackData.Feedback = response.feedbackId; await feedbackDataRepository.CreateOrUpdateAsync(feebackData); } else { await _dbHelper.SaveReflectionFeedbackDataAsync(response); } try { // Check if message id is present in reflect data ReflectionDataEntity reflectData = await reflectionDataRepository.GetReflectionData(response.reflectionId); QuestionsDataEntity question = await questiondatarepository.GetQuestionData(reflectData.QuestionID); Dictionary <int, List <FeedbackDataEntity> > feedbacks = await feedbackDataRepository.GetReflectionFeedback(response.reflectionId); var adaptiveCard = _cardHelper.FeedBackCard(feedbacks, response.reflectionId, question.Question); taskInfo.question = question.Question; taskInfo.postCreateBy = reflectData.CreatedBy; taskInfo.privacy = reflectData.Privacy; taskInfo.reflectionID = reflectData.ReflectionID; Attachment attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = adaptiveCard, }; var reply = Activity.CreateMessageActivity(); reply.Attachments.Add(attachment); if (reflectData.MessageID == null) { var result = turnContext.SendActivityAsync(reply, cancellationToken); reflectData.MessageID = result.Result.Id; // update messageid in reflection table await reflectionDataRepository.InsertOrMergeAsync(reflectData); } else { reply.Id = reflectData.MessageID; await turnContext.UpdateActivityAsync(reply); } } catch (System.Exception e) { _telemetry.TrackException(e); Console.WriteLine(e.Message.ToString()); } } return(new TaskModuleResponse { Task = new TaskModuleContinueResponse { Value = new TaskModuleTaskInfo() { Height = 600, Width = 600, Title = "Track how you're feeling every day.", Url = reldata.data.URL + reflectionid + '/' + feedbackId + '/' + response.userName, }, }, }); } catch (Exception ex) { _telemetry.TrackException(ex); return(null); } }