microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/src/Microsoft.Teams.Bot.Compat/CompatTeamsInfo.Models.cs
172lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Bot.Schema; |
| 5 | using Microsoft.Bot.Schema.Teams; |
| 6 | |
| 7 | namespace Microsoft.Teams.Bot.Compat; |
| 8 | |
| 9 | internal static class CompatTeamsInfoModels |
| 10 | { |
| 11 | /// <summary> |
| 12 | /// Gets the TeamsMeetingInfo object from the current activity. |
| 13 | /// </summary> |
| 14 | /// <param name="activity">The activity.</param> |
| 15 | /// <returns>The current activity's meeting information, or null.</returns> |
| 16 | public static TeamsMeetingInfo? TeamsGetMeetingInfo(this IActivity activity) |
| 17 | { |
| 18 | ArgumentNullException.ThrowIfNull(activity); |
| 19 | TeamsChannelData channelData = activity.GetChannelData<Microsoft.Bot.Schema.Teams.TeamsChannelData>(); |
| 20 | return channelData?.Meeting; |
| 21 | } |
| 22 | |
| 23 | /// <summary> |
| 24 | /// Converts a Core BatchOperationState to a Bot Framework BatchOperationState. |
| 25 | /// </summary> |
| 26 | /// <param name="state">The source state.</param> |
| 27 | /// <returns>The converted Bot Framework BatchOperationState.</returns> |
| 28 | public static Microsoft.Bot.Schema.Teams.BatchOperationState ToCompatBatchOperationState(this Microsoft.Teams.Bot.Apps.BatchOperationState state) |
| 29 | { |
| 30 | ArgumentNullException.ThrowIfNull(state); |
| 31 | |
| 32 | BatchOperationState result = new() |
| 33 | { |
| 34 | State = state.State, |
| 35 | RetryAfter = state.RetryAfter?.DateTime, |
| 36 | TotalEntriesCount = state.TotalEntriesCount ?? 0 |
| 37 | }; |
| 38 | |
| 39 | // StatusMap in Bot Framework SDK is IDictionary<int, int> (read-only property) |
| 40 | // Map from BatchOperationStatusMap to the dictionary format |
| 41 | if (state.StatusMap != null) |
| 42 | { |
| 43 | if (state.StatusMap.Success.HasValue) |
| 44 | { |
| 45 | result.StatusMap[0] = state.StatusMap.Success.Value; |
| 46 | } |
| 47 | |
| 48 | if (state.StatusMap.Failed.HasValue) |
| 49 | { |
| 50 | result.StatusMap[1] = state.StatusMap.Failed.Value; |
| 51 | } |
| 52 | |
| 53 | if (state.StatusMap.Throttled.HasValue) |
| 54 | { |
| 55 | result.StatusMap[2] = state.StatusMap.Throttled.Value; |
| 56 | } |
| 57 | |
| 58 | if (state.StatusMap.Pending.HasValue) |
| 59 | { |
| 60 | result.StatusMap[3] = state.StatusMap.Pending.Value; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return result; |
| 65 | } |
| 66 | |
| 67 | /// <summary> |
| 68 | /// Converts a Core BatchFailedEntriesResponse to a Bot Framework BatchFailedEntriesResponse. |
| 69 | /// </summary> |
| 70 | /// <param name="response">The source response.</param> |
| 71 | /// <returns>The converted Bot Framework BatchFailedEntriesResponse.</returns> |
| 72 | public static Microsoft.Bot.Schema.Teams.BatchFailedEntriesResponse ToCompatBatchFailedEntriesResponse(this Microsoft.Teams.Bot.Apps.BatchFailedEntriesResponse response) |
| 73 | { |
| 74 | ArgumentNullException.ThrowIfNull(response); |
| 75 | |
| 76 | BatchFailedEntriesResponse result = new() |
| 77 | { |
| 78 | ContinuationToken = response.ContinuationToken |
| 79 | }; |
| 80 | |
| 81 | // FailedEntries is a read-only property with private setter, populate via the collection |
| 82 | if (response.FailedEntries != null) |
| 83 | { |
| 84 | foreach (Apps.BatchFailedEntry entry in response.FailedEntries) |
| 85 | { |
| 86 | result.FailedEntries.Add(entry.ToCompatBatchFailedEntry()); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | return result; |
| 91 | } |
| 92 | |
| 93 | /// <summary> |
| 94 | /// Converts a Core BatchFailedEntry to a Bot Framework BatchFailedEntry. |
| 95 | /// </summary> |
| 96 | /// <param name="entry">The source entry.</param> |
| 97 | /// <returns>The converted Bot Framework BatchFailedEntry.</returns> |
| 98 | public static Microsoft.Bot.Schema.Teams.BatchFailedEntry ToCompatBatchFailedEntry(this Microsoft.Teams.Bot.Apps.BatchFailedEntry entry) |
| 99 | { |
| 100 | ArgumentNullException.ThrowIfNull(entry); |
| 101 | |
| 102 | return new Microsoft.Bot.Schema.Teams.BatchFailedEntry |
| 103 | { |
| 104 | EntryId = entry.Id, |
| 105 | Error = entry.Error |
| 106 | }; |
| 107 | } |
| 108 | |
| 109 | /// <summary> |
| 110 | /// Converts a Core TeamDetails to a Bot Framework TeamDetails. |
| 111 | /// </summary> |
| 112 | /// <param name="teamDetails">The source team details.</param> |
| 113 | /// <returns>The converted Bot Framework TeamDetails.</returns> |
| 114 | public static Microsoft.Bot.Schema.Teams.TeamDetails ToCompatTeamDetails(this Microsoft.Teams.Bot.Apps.TeamDetails teamDetails) |
| 115 | { |
| 116 | ArgumentNullException.ThrowIfNull(teamDetails); |
| 117 | |
| 118 | return new Microsoft.Bot.Schema.Teams.TeamDetails |
| 119 | { |
| 120 | Id = teamDetails.Id, |
| 121 | Name = teamDetails.Name, |
| 122 | AadGroupId = teamDetails.AadGroupId, |
| 123 | ChannelCount = teamDetails.ChannelCount ?? 0, |
| 124 | MemberCount = teamDetails.MemberCount ?? 0, |
| 125 | Type = teamDetails.Type |
| 126 | }; |
| 127 | } |
| 128 | |
| 129 | /// <summary> |
| 130 | /// Converts a Core MeetingNotificationResponse to a Bot Framework MeetingNotificationResponse. |
| 131 | /// </summary> |
| 132 | /// <param name="response">The source response.</param> |
| 133 | /// <returns>The converted Bot Framework MeetingNotificationResponse.</returns> |
| 134 | public static Microsoft.Bot.Schema.Teams.MeetingNotificationResponse ToCompatMeetingNotificationResponse(this Microsoft.Teams.Bot.Apps.MeetingNotificationResponse response) |
| 135 | { |
| 136 | ArgumentNullException.ThrowIfNull(response); |
| 137 | |
| 138 | return new Microsoft.Bot.Schema.Teams.MeetingNotificationResponse |
| 139 | { |
| 140 | RecipientsFailureInfo = response.RecipientsFailureInfo?.Select(r => r.ToCompatMeetingNotificationRecipientFailureInfo()).ToList() |
| 141 | }; |
| 142 | } |
| 143 | |
| 144 | /// <summary> |
| 145 | /// Converts a Core MeetingNotificationRecipientFailureInfo to a Bot Framework MeetingNotificationRecipientFailureInfo. |
| 146 | /// </summary> |
| 147 | /// <param name="info">The source failure info.</param> |
| 148 | /// <returns>The converted Bot Framework MeetingNotificationRecipientFailureInfo.</returns> |
| 149 | public static Microsoft.Bot.Schema.Teams.MeetingNotificationRecipientFailureInfo ToCompatMeetingNotificationRecipientFailureInfo(this Microsoft.Teams.Bot.Apps.MeetingNotificationRecipientFailureInfo info) |
| 150 | { |
| 151 | ArgumentNullException.ThrowIfNull(info); |
| 152 | |
| 153 | return new Microsoft.Bot.Schema.Teams.MeetingNotificationRecipientFailureInfo |
| 154 | { |
| 155 | RecipientMri = info.RecipientMri, |
| 156 | ErrorCode = info.ErrorCode, |
| 157 | FailureReason = info.FailureReason |
| 158 | }; |
| 159 | } |
| 160 | |
| 161 | /// <summary> |
| 162 | /// Converts a Bot Framework TeamMember to a Core TeamMember. |
| 163 | /// </summary> |
| 164 | /// <param name="teamMember">The source team member.</param> |
| 165 | /// <returns>The converted Core TeamMember.</returns> |
| 166 | public static Microsoft.Teams.Bot.Apps.TeamMember FromCompatTeamMember(this Microsoft.Bot.Schema.Teams.TeamMember teamMember) |
| 167 | { |
| 168 | ArgumentNullException.ThrowIfNull(teamMember); |
| 169 | |
| 170 | return new Microsoft.Teams.Bot.Apps.TeamMember(teamMember.Id); |
| 171 | } |
| 172 | } |
| 173 | |