/// <summary> /// Add a new suggestion in company response entity in Microsoft Azure Table storage. /// </summary> /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param> /// <param name="userRequestDetails">User response new request details object used to send new request data.</param> /// <param name="customAPIAuthenticationToken">Generate JWT token used by client application to authenticate HTTP calls with API.</param> /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> /// <returns>A task that represents the work queued to execute.</returns> private async Task <MessagingExtensionActionResponse> AddNewSuggestionResultAsync( ITurnContext <IInvokeActivity> turnContext, AddUserResponseRequestDetail userRequestDetails, string customAPIAuthenticationToken, CancellationToken cancellationToken) { var activity = turnContext.Activity; var companyResponseEntity = await this.companyStorageHelper.AddNewSuggestionAsync(activity, userRequestDetails); // Parse team channel deep link URL and get team id. var teamId = AdaptiveCardHelper.ParseTeamIdFromDeepLink(this.botSetting.Value.TeamIdDeepLink); if (string.IsNullOrEmpty(teamId)) { throw new NullReferenceException("Provided team details seems to incorrect, please reach out to the Admin."); } var isAddSuggestionSuccess = await this.companyResponseStorageProvider.UpsertConverationStateAsync(companyResponseEntity); if (isAddSuggestionSuccess) { // Tracking for company response suggested request. this.RecordEvent(RecordSuggestCompanyResponse, turnContext); var attachment = AdminCard.GetNewResponseRequestCard(companyResponseEntity, localizer: this.localizer); var resourceResponse = await this.SendCardToTeamAsync(turnContext, attachment, teamId, cancellationToken); companyResponseEntity.ActivityId = resourceResponse.ActivityId; await this.companyResponseStorageProvider.UpsertConverationStateAsync(companyResponseEntity); return(new MessagingExtensionActionResponse { Task = new TaskModuleContinueResponse { Value = new TaskModuleTaskInfo { Url = $"{this.options.Value.AppBaseUri}/response-message?token={customAPIAuthenticationToken}&status=addSuccess&isCompanyResponse=true&message={this.localizer.GetString("AddNewSuggestionSuccessMessage")}&telemetry=${this.telemetrySettings.Value.InstrumentationKey}&theme=" + "{theme}&locale=" + "{locale}", Height = TaskModuleHeight, Width = TaskModuleWidth, Title = this.localizer.GetString("ManageYourResponsesTitleText"), }, }, }); } else { return(new MessagingExtensionActionResponse { Task = new TaskModuleContinueResponse { Value = new TaskModuleTaskInfo { Url = $"{this.options.Value.AppBaseUri}/response-message?token={customAPIAuthenticationToken}&status=editFailed&isCompanyResponse=true&message={this.localizer.GetString("AddNewSuggestionFailedMessage")}&theme=" + "{theme}&locale=" + "{locale}", Height = TaskModuleHeight, Width = TaskModuleWidth, Title = this.localizer.GetString("ManageYourResponsesTitleText"), }, }, }); } }
/// <summary> /// Store user request details to Microsoft Azure Table storage. /// </summary> /// <param name="aadObjectId">Represents Azure active directory object id of user for current turn of bot.</param> /// <param name="userRequestDetails">User new request detail.</param> /// <returns>Represent a task queued for operation.</returns> public async Task <bool> AddNewUserRequestDetailsAsync(string aadObjectId, AddUserResponseRequestDetail userRequestDetails) { if (userRequestDetails != null) { var userResponse = new UserResponseEntity() { QuestionLabel = userRequestDetails.Label, QuestionText = userRequestDetails.Question, ResponseText = userRequestDetails.Response, ResponseId = Guid.NewGuid().ToString(), UserId = aadObjectId, LastUpdatedDate = DateTime.UtcNow, }; return(await this.userResponseStorageProvider.UpsertUserResponseAsync(userResponse)); } return(false); }
/// <summary> /// Edit a response in user response entity in Microsoft Azure Table storage. /// </summary> /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param> /// <param name="userRequestDetails">User response new request details object used to send new request data.</param> /// <param name="customAPIAuthenticationToken">Generate JWT token used by client app to authenticate HTTP calls with API.</param> /// <returns>A task that represents the work queued to execute.</returns> private async Task <MessagingExtensionActionResponse> EditUserResponseResultAsync( ITurnContext <IInvokeActivity> turnContext, AddUserResponseRequestDetail userRequestDetails, string customAPIAuthenticationToken) { var isEditRequestSuccess = await this.userStorageHelper.UpdateUserRequestDetailsAsync(turnContext.Activity, userRequestDetails); if (isEditRequestSuccess) { // Tracking for your response edit. this.RecordEvent(RecordEditUserResponse, turnContext); return(new MessagingExtensionActionResponse { Task = new TaskModuleContinueResponse { Value = new TaskModuleTaskInfo { Url = $"{this.options.Value.AppBaseUri}/response-message?token={customAPIAuthenticationToken}&status=editSuccess&message={this.localizer.GetString("EditUserResponseSuccessMessage")}&telemetry=${this.telemetrySettings.Value.InstrumentationKey}&theme=" + "{theme}&locale=" + "{locale}", Height = TaskModuleHeight, Width = TaskModuleWidth, Title = this.localizer.GetString("ManageYourResponsesTitleText"), }, }, }); } else { return(new MessagingExtensionActionResponse { Task = new TaskModuleContinueResponse { Value = new TaskModuleTaskInfo { Url = $"{this.options.Value.AppBaseUri}/response-message?token={customAPIAuthenticationToken}&status=editFailed&message={this.localizer.GetString("EditUserResponseFailedMessage")}&theme=" + "{theme}&locale=" + "{locale}", Height = TaskModuleHeight, Width = TaskModuleWidth, Title = this.localizer.GetString("ManageYourResponsesTitleText"), }, }, }); } }
/// <summary> /// Store user suggestion to Microsoft Azure Table storage. /// </summary> /// <param name="activity">Represents activity for current turn of bot.</param> /// <param name="userSuggestionDetails">New suggestion detail.</param> /// <returns>Represent a task queued for operation.</returns> public async Task <CompanyResponseEntity> AddNewSuggestionAsync(IInvokeActivity activity, AddUserResponseRequestDetail userSuggestionDetails) { userSuggestionDetails = userSuggestionDetails ?? throw new ArgumentNullException(nameof(userSuggestionDetails)); activity = activity ?? throw new ArgumentNullException(nameof(activity)); var userResponse = new CompanyResponseEntity() { QuestionLabel = userSuggestionDetails.Label, QuestionText = userSuggestionDetails.Question, ResponseText = userSuggestionDetails.Response, ResponseId = Guid.NewGuid().ToString(), UserId = activity.From.AadObjectId, LastUpdatedDate = DateTime.UtcNow, CreatedDate = DateTime.UtcNow, ApprovalStatus = PendingRequestStatus, CreatedBy = activity.From.Name, ApprovedOrRejectedDate = DateTime.UtcNow, UserPrincipalName = userSuggestionDetails.UPN, }; await this.companyResponseStorageProvider.UpsertConverationStateAsync(userResponse); return(userResponse); }
/// <summary> /// Update user request details to Microsoft Azure Table storage. /// </summary> /// <param name="activity">Represents activity for current turn of bot.</param> /// <param name="userRequestDetails">User new request detail.</param> /// <returns>Represent a task queued for operation.</returns> public async Task <bool> UpdateUserRequestDetailsAsync(IInvokeActivity activity, AddUserResponseRequestDetail userRequestDetails) { if (userRequestDetails != null && activity != null) { var userResponse = new UserResponseEntity() { QuestionLabel = userRequestDetails.Label, QuestionText = userRequestDetails.Question, ResponseText = userRequestDetails.Response, UserId = activity.From.AadObjectId, LastUpdatedDate = DateTime.UtcNow, ResponseId = userRequestDetails.ResponseId, }; return(await this.userResponseStorageProvider.UpsertUserResponseAsync(userResponse)); } return(false); }