/// <summary> /// Invoked when members other than this bot (like a user) are removed from the conversation. /// </summary> /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param> /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> /// <returns>A task that represents the work queued to execute.</returns> protected override async Task OnConversationUpdateActivityAsync(ITurnContext <IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) { try { turnContext = turnContext ?? throw new ArgumentNullException(nameof(turnContext)); this.RecordEvent(nameof(this.OnConversationUpdateActivityAsync), turnContext); var activity = turnContext.Activity; this.logger.LogInformation($"conversationType: {activity.Conversation.ConversationType}, membersAdded: {activity.MembersAdded?.Count}, membersRemoved: {activity.MembersRemoved?.Count}"); if (activity.Conversation.ConversationType == ConversationTypes.Personal) { if (activity.MembersAdded != null && activity.MembersAdded.Any(member => member.Id == activity.Recipient.Id)) { await this.SendWelcomeCardInPersonalScopeAsync(turnContext); } } else if (activity.Conversation.ConversationType == ConversationTypes.Channel) { if (activity.MembersAdded != null && activity.MembersAdded.Any(member => member.Id == activity.Recipient.Id)) { // If bot added to team, add team tab configuration with service URL. await this.SendWelcomeCardInChannelAsync(turnContext); var teamsDetails = activity.TeamsGetTeamInfo(); if (teamsDetails != null) { var teamTagConfiguration = new TeamTagEntity { CreatedDate = DateTime.UtcNow, ServiceUrl = activity.ServiceUrl, Tags = string.Empty, TeamId = teamsDetails.Id, CreatedByName = activity.From.Name, UserAadId = activity.From.AadObjectId, }; await this.teamTagStorageProvider.UpsertTeamTagAsync(teamTagConfiguration); } } else if (activity.MembersRemoved != null && activity.MembersRemoved.Any(member => member.Id == activity.Recipient.Id)) { // If bot removed from team, delete configured tags and digest preference settings. var teamsDetails = activity.TeamsGetTeamInfo(); if (teamsDetails != null) { await this.teamTagStorageProvider.DeleteTeamTagAsync(teamsDetails.Id); await this.teamPreferenceStorageProvider.DeleteTeamPreferenceAsync(teamsDetails.Id); } } } } catch (Exception ex) { this.logger.LogError(ex, "Exception occurred while bot conversation update event."); throw; } }
/// <summary> /// Stores or update team tags data. /// </summary> /// <param name="teamTagEntity">Represents team tag entity object.</param> /// <returns>A task that represents team tags entity data is saved or updated.</returns> private async Task <TableResult> StoreOrUpdateTeamTagAsync(TeamTagEntity teamTagEntity) { await this.EnsureInitializedAsync(); TableOperation addOrUpdateOperation = TableOperation.InsertOrReplace(teamTagEntity); return(await this.GoodReadsCloudTable.ExecuteAsync(addOrUpdateOperation)); }
public async Task <IActionResult> PostAsync([FromBody] TeamTagEntity teamTagEntity) { this.logger.LogInformation("Call to add team tag details."); try { #pragma warning disable CA1062 // tags configuration details are validated by model validations for null check and is responded with bad request status var currentTeamTagConfiguration = await this.teamTagStorageProvider.GetTeamTagAsync(teamTagEntity.TeamId); #pragma warning restore CA1062 // tags configuration details are validated by model validations for null check and is responded with bad request status TeamTagEntity teamTagConfiguration; // If there is no record in database for team, add new entry else update existing. if (currentTeamTagConfiguration == null) { this.logger.LogError($"Tags configuration details were not found for team {teamTagEntity.TeamId}"); return(this.BadRequest("Tags configuration details were not found for team")); } else { currentTeamTagConfiguration.Tags = teamTagEntity.Tags; teamTagConfiguration = currentTeamTagConfiguration; } var upsertResult = await this.teamTagStorageProvider.UpsertTeamTagAsync(teamTagConfiguration); if (upsertResult) { this.RecordEvent("Team tags - HTTP Post call succeeded"); return(this.Ok(upsertResult)); } else { this.RecordEvent("Team tags - HTTP Post call failed"); return(this.GetErrorResponse(StatusCodes.Status500InternalServerError, "Unable to save tags for team.")); } } catch (Exception ex) { this.logger.LogError(ex, "Error while saving tags for team."); throw; } }
/// <summary> /// Stores or update team tags data. /// </summary> /// <param name="teamTagEntity">Represents team tag entity object.</param> /// <returns>A boolean that represents team tags entity is successfully saved/updated or not.</returns> public async Task <bool> UpsertTeamTagAsync(TeamTagEntity teamTagEntity) { var result = await this.StoreOrUpdateTeamTagAsync(teamTagEntity); return(result.HttpStatusCode == (int)HttpStatusCode.NoContent); }