Skip to content

Commit

Permalink
Refactor to reuse code
Browse files Browse the repository at this point in the history
  • Loading branch information
JhontSouth authored Jul 24, 2023
1 parent c70cd2b commit 2ee6b5c
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 1,178 deletions.
44 changes: 31 additions & 13 deletions libraries/Microsoft.Bot.Builder/Teams/TeamsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public static async Task<MeetingNotificationResponse> SendMeetingNotificationAsy
/// <param name="teamsMembers"> The list of members. </param>
/// <param name="tenantId"> The tenant ID. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns>The operation Id.</returns>
/// <returns> The operation Id. </returns>
public static async Task<string> SendMessageToListOfUsersAsync(ITurnContext turnContext, IActivity activity, List<object> teamsMembers, string tenantId, CancellationToken cancellationToken = default)
{
activity = activity ?? throw new InvalidOperationException($"{nameof(activity)} is required.");
Expand All @@ -362,11 +362,11 @@ public static async Task<string> SendMessageToListOfUsersAsync(ITurnContext turn
/// <summary>
/// Sends a message to all the users in a tenant.
/// </summary>
/// <param name="turnContext"> Turn context. </param>
/// <param name="turnContext"> The turn context. </param>
/// <param name="activity"> The activity to send to the tenant. </param>
/// <param name="tenantId"> The tenant ID. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns>The operation Id.</returns>
/// <returns> The operation Id. </returns>
public static async Task<string> SendMessageToAllUsersInTenantAsync(ITurnContext turnContext, IActivity activity, string tenantId, CancellationToken cancellationToken = default)
{
activity = activity ?? throw new InvalidOperationException($"{nameof(activity)} is required.");
Expand All @@ -381,7 +381,7 @@ public static async Task<string> SendMessageToAllUsersInTenantAsync(ITurnContext
/// <summary>
/// Sends a message to all the users in a team.
/// </summary>
/// <param name="turnContext"> Turn context. </param>
/// <param name="turnContext"> The turn context. </param>
/// <param name="activity"> The activity to send to the users in the team. </param>
/// <param name="teamId"> The team ID. </param>
/// <param name="tenantId"> The tenant ID. </param>
Expand All @@ -402,12 +402,12 @@ public static async Task<string> SendMessageToAllUsersInTeamAsync(ITurnContext t
/// <summary>
/// Sends a message to the provided list of Teams channels.
/// </summary>
/// <param name="turnContext"> Turn context. </param>
/// <param name="turnContext"> The turn context. </param>
/// <param name="activity"> The activity to send. </param>
/// <param name="channelsMembers"> The list of channels. </param>
/// <param name="tenantId"> The tenant ID. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns>The operation Id.</returns>
/// <returns> The operation Id. </returns>
public static async Task<string> SendMessageToListOfChannelsAsync(ITurnContext turnContext, IActivity activity, List<object> channelsMembers, string tenantId, CancellationToken cancellationToken = default)
{
activity = activity ?? throw new InvalidOperationException($"{nameof(activity)} is required.");
Expand All @@ -426,7 +426,7 @@ public static async Task<string> SendMessageToListOfChannelsAsync(ITurnContext t
/// <param name="turnContext"> Turn context. </param>
/// <param name="operationId"> The operationId to get the state of. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns>The state and responses of the operation.</returns>
/// <returns> The state and responses of the operation. </returns>
public static async Task<BatchOperationState> GetOperationStateAsync(ITurnContext turnContext, string operationId, CancellationToken cancellationToken = default)
{
operationId = operationId ?? throw new InvalidOperationException($"{nameof(operationId)} is required.");
Expand All @@ -440,17 +440,35 @@ public static async Task<BatchOperationState> GetOperationStateAsync(ITurnContex
/// <summary>
/// Gets the failed entries of a batch operation.
/// </summary>
/// <param name="turnContext">The turn context.</param>
/// <param name="operationId">The operationId to get the failed entries of.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The list of failed entries of the operation.</returns>
public static async Task<BatchFailedEntriesResponse> GetPagedFailedEntriesAsync(ITurnContext turnContext, string operationId, CancellationToken cancellationToken = default)
/// <param name="turnContext"> The turn context. </param>
/// <param name="operationId"> The operationId to get the failed entries of. </param>
/// <param name="continuationToken"> The continuation token. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> The list of failed entries of the operation. </returns>
public static async Task<BatchFailedEntriesResponse> GetPagedFailedEntriesAsync(ITurnContext turnContext, string operationId, string continuationToken = null, CancellationToken cancellationToken = default)
{
operationId = operationId ?? throw new InvalidOperationException($"{nameof(operationId)} is required.");

using (var teamsClient = GetTeamsConnectorClient(turnContext))
{
return await teamsClient.Teams.GetPagedFailedEntriesAsync(operationId, continuationToken, cancellationToken).ConfigureAwait(false);
}
}

/// <summary>
/// Cancels a batch operation by its id.
/// </summary>
/// <param name="turnContext"> The turn context. </param>
/// <param name="operationId"> The id of the operation to cancel. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> A <see cref="Task"/> representing the asynchronous operation. </returns>
public static async Task CancelOperationAsync(ITurnContext turnContext, string operationId, CancellationToken cancellationToken = default)
{
operationId = operationId ?? throw new InvalidOperationException($"{nameof(operationId)} is required.");

using (var teamsClient = GetTeamsConnectorClient(turnContext))
{
return await teamsClient.Teams.GetPagedFailedEntriesAsync(operationId, cancellationToken).ConfigureAwait(false);
await teamsClient.Teams.CancelOperationAsync(operationId, cancellationToken).ConfigureAwait(false);
}
}

Expand Down
Loading

0 comments on commit 2ee6b5c

Please sign in to comment.