microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/move-activity-classes-to-core-again

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/src/Microsoft.Bot.Core/Activities/Activity.cs

325lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4namespace Microsoft.Bot.Core.Activities;
5
6/// <summary>
7/// Base class for bot activities.
8/// </summary>
9#pragma warning disable CA1056 // URI properties should not be strings
10public class Activity
11#pragma warning restore CA1056 // URI properties should not be strings
12{
13 /// <summary>
14 /// Gets or sets the unique identifier for the activity.
15 /// </summary>
16 [JsonPropertyName("id")]
17 public string? Id { get; set; }
18
19 /// <summary>
20 /// Gets or sets the type of the activity.
21 /// </summary>
22 [JsonPropertyName("type")]
23 public string? Type { get; set; }
24
25 /// <summary>
26 /// Gets or sets the ID of the activity to which this activity is a reply.
27 /// </summary>
28 [JsonPropertyName("replyToId")]
29 public string? ReplyToId { get; set; }
30
31 /// <summary>
32 /// Gets or sets the channel identifier.
33 /// </summary>
34 [JsonPropertyName("channelId")]
35 public string? ChannelId { get; set; }
36
37 /// <summary>
38 /// Gets or sets the account that sent this activity.
39 /// </summary>
40 [JsonPropertyName("from")]
41 public Account? From { get; set; }
42
43 /// <summary>
44 /// Gets or sets the account that should receive this activity.
45 /// </summary>
46 [JsonPropertyName("recipient")]
47 public Account? Recipient { get; set; }
48
49 /// <summary>
50 /// Gets or sets the conversation in which this activity is taking place.
51 /// </summary>
52 [JsonPropertyName("conversation")]
53 public Conversation? Conversation { get; set; }
54
55 /// <summary>
56 /// Gets or sets a reference to another conversation or activity.
57 /// </summary>
58 [JsonPropertyName("relatesTo")]
59 public ConversationReference? RelatesTo { get; set; }
60
61 /// <summary>
62 /// Gets or sets the URL of the service endpoint.
63 /// </summary>
64 [JsonPropertyName("serviceUrl")]
65 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:URI properties should not be strings", Justification = "Activity schema uses string for ServiceUrl")]
66 public string? ServiceUrl { get; set; }
67
68 /// <summary>
69 /// Gets or sets the locale of the activity.
70 /// </summary>
71 [JsonPropertyName("locale")]
72 public string? Locale { get; set; }
73
74 /// <summary>
75 /// Gets or sets the timestamp of when the activity was sent.
76 /// </summary>
77 [JsonPropertyName("timestamp")]
78 public DateTime? Timestamp { get; set; }
79
80 /// <summary>
81 /// Gets or sets the local timestamp of when the activity was sent.
82 /// </summary>
83 [JsonPropertyName("localTimestamp")]
84 public DateTime? LocalTimestamp { get; set; }
85
86 /// <summary>
87 /// Gets the collection of entities included in the activity.
88 /// </summary>
89 [JsonPropertyName("entities")]
90 public IList<Entity>? Entities { get; init; }
91
92 /// <summary>
93 /// Gets or sets channel-specific data associated with this activity.
94 /// </summary>
95 [JsonPropertyName("channelData")]
96 public ChannelData? ChannelData { get; set; }
97
98 /// <summary>
99 /// Gets or sets extension data for additional properties.
100 /// </summary>
101 [JsonExtensionData]
102 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "JsonExtensionData requires a setter")]
103 public IDictionary<string, object?>? Properties { get; set; }
104
105 /// <summary>
106 /// Initializes a new instance of the <see cref="Activity"/> class.
107 /// </summary>
108 public Activity()
109 {
110 }
111
112 /// <summary>
113 /// Initializes a new instance of the <see cref="Activity"/> class with the specified type.
114 /// </summary>
115 /// <param name="type">The activity type.</param>
116 public Activity(string type)
117 {
118 Type = type;
119 }
120}
121
122/// <summary>
123/// Represents an account.
124/// </summary>
125#pragma warning disable CA1724 // Type names should not match namespaces
126public class Account
127#pragma warning restore CA1724 // Type names should not match namespaces
128{
129 /// <summary>
130 /// Gets or sets the unique identifier for the account.
131 /// </summary>
132 [JsonPropertyName("id")]
133 public string? Id { get; set; }
134
135 /// <summary>
136 /// Gets or sets the Azure Active Directory object ID.
137 /// </summary>
138 [JsonPropertyName("aadObjectId")]
139 public string? AadObjectId { get; set; }
140
141 /// <summary>
142 /// Gets or sets the role of the account. See <see cref="Roles"/> for common values.
143 /// </summary>
144 [JsonPropertyName("role")]
145 public string? Role { get; set; }
146
147 /// <summary>
148 /// Gets or sets the name of the account.
149 /// </summary>
150 [JsonPropertyName("name")]
151 public string? Name { get; set; }
152
153 /// <summary>
154 /// Gets or sets additional properties.
155 /// </summary>
156 [JsonPropertyName("properties")]
157#pragma warning disable CA2227 // Collection properties should be read only
158 public Dictionary<string, object>? Properties { get; set; }
159#pragma warning restore CA2227 // Collection properties should be read only
160}
161
162/// <summary>
163/// String constants for account roles.
164/// </summary>
165public static class Roles
166{
167 /// <summary>
168 /// Indicates the account is a bot.
169 /// </summary>
170 public const string Bot = "bot";
171
172 /// <summary>
173 /// Indicates the account is a user.
174 /// </summary>
175 public const string User = "user";
176}
177
178/// <summary>
179/// Represents a conversation.
180/// </summary>
181public class Conversation
182{
183 /// <summary>
184 /// Gets or sets the unique identifier for the conversation.
185 /// </summary>
186 [JsonPropertyName("id")]
187 public string? Id { get; set; }
188
189 /// <summary>
190 /// Gets or sets the name of the conversation.
191 /// </summary>
192 [JsonPropertyName("name")]
193 public string? Name { get; set; }
194
195 /// <summary>
196 /// Gets or sets additional properties.
197 /// </summary>
198 [JsonPropertyName("properties")]
199#pragma warning disable CA2227 // Collection properties should be read only
200 public Dictionary<string, object>? Properties { get; set; }
201#pragma warning restore CA2227 // Collection properties should be read only
202}
203
204/// <summary>
205/// Represents a reference to another conversation or activity.
206/// </summary>
207#pragma warning disable CA1056 // URI properties should not be strings
208public class ConversationReference
209#pragma warning restore CA1056 // URI properties should not be strings
210{
211 /// <summary>
212 /// Gets or sets the activity ID.
213 /// </summary>
214 [JsonPropertyName("activityId")]
215 public string? ActivityId { get; set; }
216
217 /// <summary>
218 /// Gets or sets the user account.
219 /// </summary>
220 [JsonPropertyName("user")]
221 public Account? User { get; set; }
222
223 /// <summary>
224 /// Gets or sets the bot account.
225 /// </summary>
226 [JsonPropertyName("bot")]
227 public Account? Bot { get; set; }
228
229 /// <summary>
230 /// Gets or sets the conversation.
231 /// </summary>
232 [JsonPropertyName("conversation")]
233 public Conversation? Conversation { get; set; }
234
235 /// <summary>
236 /// Gets or sets the channel ID.
237 /// </summary>
238 [JsonPropertyName("channelId")]
239 public string? ChannelId { get; set; }
240
241 /// <summary>
242 /// Gets or sets the service URL.
243 /// </summary>
244 [JsonPropertyName("serviceUrl")]
245 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:URI properties should not be strings", Justification = "Activity schema uses string for ServiceUrl")]
246 public string? ServiceUrl { get; set; }
247}
248
249/// <summary>
250/// Represents channel-specific data.
251/// </summary>
252public class ChannelData
253{
254 /// <summary>
255 /// Gets or sets extension data for additional properties.
256 /// </summary>
257 [JsonExtensionData]
258#pragma warning disable CA2227 // Collection properties should be read only
259 public IDictionary<string, object?>? Properties { get; set; }
260#pragma warning restore CA2227 // Collection properties should be read only
261}
262
263/// <summary>
264/// Represents an entity.
265/// </summary>
266public class Entity
267{
268 /// <summary>
269 /// Gets or sets the type of the entity.
270 /// </summary>
271 [JsonPropertyName("type")]
272 public string? Type { get; set; }
273
274 /// <summary>
275 /// Gets or sets extension data for additional properties.
276 /// </summary>
277 [JsonExtensionData]
278#pragma warning disable CA2227 // Collection properties should be read only
279 public IDictionary<string, object?>? Properties { get; set; }
280#pragma warning restore CA2227 // Collection properties should be read only
281}
282
283/// <summary>
284/// Represents an error.
285/// </summary>
286#pragma warning disable CA1716 // Identifiers should not match keywords
287public class Error
288#pragma warning restore CA1716 // Identifiers should not match keywords
289{
290 /// <summary>
291 /// Gets or sets the error code.
292 /// </summary>
293 [JsonPropertyName("code")]
294 public string? Code { get; set; }
295
296 /// <summary>
297 /// Gets or sets the error message.
298 /// </summary>
299 [JsonPropertyName("message")]
300 public string? Message { get; set; }
301
302 /// <summary>
303 /// Gets or sets inner HTTP error details.
304 /// </summary>
305 [JsonPropertyName("innerHttpError")]
306 public InnerHttpError? InnerHttpError { get; set; }
307}
308
309/// <summary>
310/// Represents inner HTTP error details.
311/// </summary>
312public class InnerHttpError
313{
314 /// <summary>
315 /// Gets or sets the HTTP status code.
316 /// </summary>
317 [JsonPropertyName("statusCode")]
318 public int? StatusCode { get; set; }
319
320 /// <summary>
321 /// Gets or sets the response body.
322 /// </summary>
323 [JsonPropertyName("body")]
324 public object? Body { get; set; }
325}
326