Skip to content

Commit

Permalink
Create TeamMember model and apply small feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ceciliaavila committed Aug 10, 2023
1 parent f0ebe7d commit 94ad1d1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 31 deletions.
4 changes: 2 additions & 2 deletions libraries/Microsoft.Bot.Builder/Teams/TeamsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public static async Task<MeetingNotificationResponse> SendMeetingNotificationAsy
/// <param name="tenantId"> The tenant ID. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> The operation Id. </returns>
public static async Task<string> SendMessageToListOfUsersAsync(ITurnContext turnContext, IActivity activity, List<object> teamsMembers, string tenantId, CancellationToken cancellationToken = default)
public static async Task<string> SendMessageToListOfUsersAsync(ITurnContext turnContext, IActivity activity, List<TeamMember> teamsMembers, string tenantId, CancellationToken cancellationToken = default)
{
activity = activity ?? throw new InvalidOperationException($"{nameof(activity)} is required.");
teamsMembers = teamsMembers ?? throw new InvalidOperationException($"{nameof(teamsMembers)} is required.");
Expand Down Expand Up @@ -408,7 +408,7 @@ public static async Task<string> SendMessageToAllUsersInTeamAsync(ITurnContext t
/// <param name="tenantId"> The tenant ID. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <returns> The operation Id. </returns>
public static async Task<string> SendMessageToListOfChannelsAsync(ITurnContext turnContext, IActivity activity, List<object> channelsMembers, string tenantId, CancellationToken cancellationToken = default)
public static async Task<string> SendMessageToListOfChannelsAsync(ITurnContext turnContext, IActivity activity, List<TeamMember> channelsMembers, string tenantId, CancellationToken cancellationToken = default)
{
activity = activity ?? throw new InvalidOperationException($"{nameof(activity)} is required.");
channelsMembers = channelsMembers ?? throw new InvalidOperationException($"{nameof(channelsMembers)} is required.");
Expand Down
4 changes: 2 additions & 2 deletions libraries/Microsoft.Bot.Connector/Teams/TeamsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public TeamsOperations(TeamsConnectorClient client)
/// <returns>
/// A response object containing the operation id.
/// </returns>
public async Task<HttpOperationResponse<string>> SendMessageToListOfUsersAsync(IActivity activity, List<object> teamsMembers, string tenantId, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
public async Task<HttpOperationResponse<string>> SendMessageToListOfUsersAsync(IActivity activity, List<TeamMember> teamsMembers, string tenantId, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (activity == null)
{
Expand Down Expand Up @@ -468,7 +468,7 @@ public TeamsOperations(TeamsConnectorClient client)
/// <returns>
/// A response object containing the operation id.
/// </returns>
public async Task<HttpOperationResponse<string>> SendMessageToListOfChannelsAsync(IActivity activity, List<object> channelsMembers, string tenantId, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
public async Task<HttpOperationResponse<string>> SendMessageToListOfChannelsAsync(IActivity activity, List<TeamMember> channelsMembers, string tenantId, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (activity == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static partial class TeamsOperationsExtensions
/// <returns>The channel list for a given team.</returns>
public static async Task<ConversationList> FetchChannelListAsync(this ITeamsOperations operations, string teamId, CancellationToken cancellationToken = default(CancellationToken))
{
using (var result = await operations.FetchChannelListWithHttpMessagesAsync(teamId, null, cancellationToken).ConfigureAwait(false))
using (var result = await operations.FetchChannelListWithHttpMessagesAsync(teamId, cancellationToken: cancellationToken).ConfigureAwait(false))
{
return result.Body;
}
Expand All @@ -51,7 +51,7 @@ public static partial class TeamsOperationsExtensions
/// <returns>The details related to a team.</returns>
public static async Task<TeamDetails> FetchTeamDetailsAsync(this ITeamsOperations operations, string teamId, CancellationToken cancellationToken = default(CancellationToken))
{
using (var result = await operations.FetchTeamDetailsWithHttpMessagesAsync(teamId, null, cancellationToken).ConfigureAwait(false))
using (var result = await operations.FetchTeamDetailsWithHttpMessagesAsync(teamId, cancellationToken: cancellationToken).ConfigureAwait(false))
{
return result.Body;
}
Expand All @@ -74,7 +74,7 @@ public static partial class TeamsOperationsExtensions
{
if (operations is TeamsOperations teamsOperations)
{
using var result = await teamsOperations.FetchMeetingInfoWithHttpMessagesAsync(meetingId, null, cancellationToken).ConfigureAwait(false);
using var result = await teamsOperations.FetchMeetingInfoWithHttpMessagesAsync(meetingId, cancellationToken: cancellationToken).ConfigureAwait(false);
return result.Body;
}

Expand Down Expand Up @@ -104,7 +104,7 @@ public static partial class TeamsOperationsExtensions
{
if (operations is TeamsOperations teamsOperations)
{
using (var result = await teamsOperations.FetchParticipantWithHttpMessagesAsync(meetingId, participantId, tenantId, null, cancellationToken).ConfigureAwait(false))
using (var result = await teamsOperations.FetchParticipantWithHttpMessagesAsync(meetingId, participantId, tenantId, cancellationToken: cancellationToken).ConfigureAwait(false))
{
return result.Body;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public static partial class TeamsOperationsExtensions
{
if (operations is TeamsOperations teamsOperations)
{
using (var result = await teamsOperations.SendMeetingNotificationMessageAsync(meetingId, notification, null, cancellationToken).ConfigureAwait(false))
using (var result = await teamsOperations.SendMeetingNotificationMessageAsync(meetingId, notification, cancellationToken: cancellationToken).ConfigureAwait(false))
{
return result.Body;
}
Expand Down Expand Up @@ -165,11 +165,11 @@ public static partial class TeamsOperationsExtensions
/// The cancellation token.
/// </param>
/// <returns>The operation Id.</returns>
public static async Task<string> SendMessageToListOfUsersAsync(this ITeamsOperations operations, IActivity activity, List<object> teamsMembers, string tenantId, CancellationToken cancellationToken = default(CancellationToken))
public static async Task<string> SendMessageToListOfUsersAsync(this ITeamsOperations operations, IActivity activity, List<TeamMember> teamsMembers, string tenantId, CancellationToken cancellationToken = default(CancellationToken))
{
if (operations is TeamsOperations teamsOperations)
{
using (var result = await teamsOperations.SendMessageToListOfUsersAsync(activity, teamsMembers, tenantId, null, cancellationToken).ConfigureAwait(false))
using (var result = await teamsOperations.SendMessageToListOfUsersAsync(activity, teamsMembers, tenantId, cancellationToken: cancellationToken).ConfigureAwait(false))
{
return result.Body;
}
Expand Down Expand Up @@ -200,7 +200,7 @@ public static partial class TeamsOperationsExtensions
{
if (operations is TeamsOperations teamsOperations)
{
using (var result = await teamsOperations.SendMessageToAllUsersInTenantAsync(activity, tenantId, null, cancellationToken).ConfigureAwait(false))
using (var result = await teamsOperations.SendMessageToAllUsersInTenantAsync(activity, tenantId, cancellationToken: cancellationToken).ConfigureAwait(false))
{
return result.Body;
}
Expand Down Expand Up @@ -234,7 +234,7 @@ public static partial class TeamsOperationsExtensions
{
if (operations is TeamsOperations teamsOperations)
{
using (var result = await teamsOperations.SendMessageToAllUsersInTeamAsync(activity, teamId, tenantId, null, cancellationToken).ConfigureAwait(false))
using (var result = await teamsOperations.SendMessageToAllUsersInTeamAsync(activity, teamId, tenantId, cancellationToken: cancellationToken).ConfigureAwait(false))
{
return result.Body;
}
Expand Down Expand Up @@ -264,11 +264,11 @@ public static partial class TeamsOperationsExtensions
/// The cancellation token.
/// </param>
/// <returns>The operation Id.</returns>
public static async Task<string> SendMessageToListOfChannelsAsync(this ITeamsOperations operations, IActivity activity, List<object> channelsMembers, string tenantId, CancellationToken cancellationToken = default(CancellationToken))
public static async Task<string> SendMessageToListOfChannelsAsync(this ITeamsOperations operations, IActivity activity, List<TeamMember> channelsMembers, string tenantId, CancellationToken cancellationToken = default(CancellationToken))
{
if (operations is TeamsOperations teamsOperations)
{
using (var result = await teamsOperations.SendMessageToListOfChannelsAsync(activity, channelsMembers, tenantId, null, cancellationToken).ConfigureAwait(false))
using (var result = await teamsOperations.SendMessageToListOfChannelsAsync(activity, channelsMembers, tenantId, cancellationToken: cancellationToken).ConfigureAwait(false))
{
return result.Body;
}
Expand Down Expand Up @@ -296,7 +296,7 @@ public static partial class TeamsOperationsExtensions
{
if (operations is TeamsOperations teamsOperations)
{
using (var result = await teamsOperations.GetOperationStateAsync(operationId, null, cancellationToken).ConfigureAwait(false))
using (var result = await teamsOperations.GetOperationStateAsync(operationId, cancellationToken: cancellationToken).ConfigureAwait(false))
{
return result.Body;
}
Expand All @@ -319,7 +319,7 @@ public static async Task<BatchFailedEntriesResponse> GetPagedFailedEntriesAsync(
{
if (operations is TeamsOperations teamsOperations)
{
using (var result = await teamsOperations.GetPagedFailedEntriesAsync(operationId, null, continuationToken, cancellationToken).ConfigureAwait(false))
using (var result = await teamsOperations.GetPagedFailedEntriesAsync(operationId, continuationToken: continuationToken, cancellationToken: cancellationToken).ConfigureAwait(false))
{
return result.Body;
}
Expand Down Expand Up @@ -347,7 +347,7 @@ public static async Task<BatchFailedEntriesResponse> GetPagedFailedEntriesAsync(
{
if (operations is TeamsOperations teamsOperations)
{
await teamsOperations.CancelOperationAsync(operationId, null, cancellationToken).ConfigureAwait(false);
await teamsOperations.CancelOperationAsync(operationId, cancellationToken: cancellationToken).ConfigureAwait(false);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions libraries/Microsoft.Bot.Schema/Teams/BatchFailedEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public BatchFailedEntry()
/// Gets or sets the id of the failed entry.
/// </summary>
/// <value>The id of the failed entry.</value>
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "entryId")]
public string EntryId { get; set; }

/// <summary>
/// Gets or sets the error of the failed entry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BatchOperationState
/// The status map for processed users.
/// </value>
[JsonProperty(PropertyName = "statusMap")]
public IDictionary<string, int> StatusMap { get; } = new Dictionary<string, int>();
public IDictionary<int, int> StatusMap { get; } = new Dictionary<int, int>();

/// <summary>
/// Gets or sets the datetime value to retry the operation.
Expand Down
43 changes: 43 additions & 0 deletions libraries/Microsoft.Bot.Schema/Teams/TeamMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Bot.Schema.Teams
{
using Newtonsoft.Json;

/// <summary>
/// Describes a member.
/// </summary>
public partial class TeamMember
{
/// <summary>
/// Initializes a new instance of the <see cref="TeamMember"/> class.
/// </summary>
public TeamMember()
{
CustomInit();
}

/// <summary>
/// Initializes a new instance of the <see cref="TeamMember"/> class.
/// </summary>
/// <param name="id">Unique identifier representing a member (user or channel).</param>
public TeamMember(string id = default)
{
Id = id;
CustomInit();
}

/// <summary>
/// Gets or sets unique identifier representing a member (user or channel).
/// </summary>
/// <value>The member ID.</value>
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }

/// <summary>
/// An initialization method that performs custom operations like setting defaults.
/// </summary>
partial void CustomInit();
}
}
20 changes: 10 additions & 10 deletions tests/Microsoft.Bot.Builder.Tests/Teams/TeamsInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -944,11 +944,11 @@ private async Task CallGetChannelsAsync(ITurnContext turnContext)
private async Task CallSendMessageToListOfUsersAsync(ITurnContext turnContext)
{
var from = turnContext.Activity.From;
var members = new List<object>()
var members = new List<TeamMember>()
{
new { Id = "member-1" },
new { Id = "member-2" },
new { Id = "member-3" },
new TeamMember("member-1"),
new TeamMember("member-2"),
new TeamMember("member-3"),
};
var tenantId = "tenant-id";

Expand Down Expand Up @@ -1098,11 +1098,11 @@ private async Task CallSendMessageToAllUsersInTeamAsync(ITurnContext turnContext
private async Task CallSendMessageToListOfChannelsAsync(ITurnContext turnContext)
{
var from = turnContext.Activity.From;
var members = new List<object>()
var members = new List<TeamMember>()
{
new { Id = "channel-1" },
new { Id = "channel-2" },
new { Id = "channel-3" },
new TeamMember("channel-1"),
new TeamMember("channel-2"),
new TeamMember("channel-3"),
};
var tenantId = "tenant-id";

Expand Down Expand Up @@ -1157,7 +1157,7 @@ private async Task CallGetOperationStateAsync(ITurnContext turnContext)
State = "state-1",
TotalEntriesCount = 1
};
response.StatusMap.Add("statusMap-1", 1);
response.StatusMap.Add(400, 1);

try
{
Expand Down Expand Up @@ -1206,7 +1206,7 @@ private async Task CallGetPagedFailedEntriesAsync(ITurnContext turnContext)
response.FailedEntries.Add(
new BatchFailedEntry
{
Id = "entry-1",
EntryId = "entry-1",
Error = "400 User not found"
});

Expand Down

0 comments on commit 94ad1d1

Please sign in to comment.