microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next/oauth-card-null-ref-bug

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/src/Microsoft.Teams.Bot.Apps/Schema/MessageActivity.cs

278lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using System.Text.Json;
5using System.Text.Json.Serialization;
6using Microsoft.Teams.Bot.Core.Schema;
7
8namespace Microsoft.Teams.Bot.Apps.Schema;
9
10/// <summary>
11/// Represents a message activity.
12/// </summary>
13public class MessageActivity : TeamsActivity
14{
15
16 /// <summary>
17 /// Convenience method to create a MessageActivity from a CoreActivity.
18 /// </summary>
19 /// <param name="activity">The CoreActivity to convert.</param>
20 /// <returns>A MessageActivity instance.</returns>
21 public static new MessageActivity FromActivity(CoreActivity activity)
22 {
23 ArgumentNullException.ThrowIfNull(activity);
24 return new MessageActivity(activity);
25 }
26
27 /// <summary>
28 /// Default constructor.
29 /// </summary>
30 [JsonConstructor]
31 public MessageActivity() : base(TeamsActivityType.Message)
32 {
33 }
34
35 /// <summary>
36 /// Initializes a new instance of the <see cref="MessageActivity"/> class with the specified text.
37 /// </summary>
38 /// <param name="text">The text content of the message.</param>
39 public MessageActivity(string text) : base(TeamsActivityType.Message)
40 {
41 Text = text;
42 }
43
44
45 /// <summary>
46 /// Initializes a new instance of the <see cref="MessageActivity"/> class with the specified text.
47 /// </summary>
48 /// <param name="attachments">The list of attachments for the message.</param>
49 public MessageActivity(IList<TeamsAttachment> attachments) : base(TeamsActivityType.Message)
50 {
51 Attachments = attachments;
52 }
53
54 /// <summary>
55 /// Internal constructor to create MessageActivity from CoreActivity.
56 /// </summary>
57 /// <param name="activity">The CoreActivity to convert.</param>
58 protected MessageActivity(CoreActivity activity) : base(activity)
59 {
60 if (activity.Properties.TryGetValue("text", out object? text))
61 {
62 Text = text?.ToString();
63 activity.Properties.Remove("text");
64 }
65 if (activity.Properties.TryGetValue("textFormat", out object? textFormat))
66 {
67 TextFormat = textFormat?.ToString();
68 activity.Properties.Remove("textFormat");
69 }
70 if (activity.Properties.TryGetValue("attachmentLayout", out object? attachmentLayout))
71 {
72 AttachmentLayout = attachmentLayout?.ToString();
73 activity.Properties.Remove("attachmentLayout");
74 }
75 if (activity.Properties.TryGetValue("suggestedActions", out object? suggestedActions) && suggestedActions != null)
76 {
77 if (suggestedActions is JsonElement je)
78 {
79 SuggestedActions = JsonSerializer.Deserialize<SuggestedActions>(je.GetRawText());
80 }
81 else
82 {
83 SuggestedActions = suggestedActions as SuggestedActions;
84 }
85 activity.Properties.Remove("suggestedActions");
86 }
87 /*
88 if (activity.Properties.TryGetValue("speak", out var speak))
89 {
90 Speak = speak?.ToString();
91 activity.Properties.Remove("speak");
92 }
93 if (activity.Properties.TryGetValue("inputHint", out var inputHint))
94 {
95 InputHint = inputHint?.ToString();
96 activity.Properties.Remove("inputHint");
97 }
98 if (activity.Properties.TryGetValue("summary", out var summary))
99 {
100 Summary = summary?.ToString();
101 activity.Properties.Remove("summary");
102 }
103 if (activity.Properties.TryGetValue("importance", out var importance))
104 {
105 Importance = importance?.ToString();
106 activity.Properties.Remove("importance");
107 }
108 if (activity.Properties.TryGetValue("deliveryMode", out var deliveryMode))
109 {
110 DeliveryMode = deliveryMode?.ToString();
111 activity.Properties.Remove("deliveryMode");
112 }
113 if (activity.Properties.TryGetValue("expiration", out var expiration))
114 {
115 Expiration = expiration?.ToString();
116 activity.Properties.Remove("expiration");
117 }
118 */
119 }
120
121 /// <summary>
122 /// Gets or sets the text content of the message.
123 /// </summary>
124 [JsonPropertyName("text")]
125 public string? Text { get; set; }
126 /// <summary>
127 /// Gets or sets the text format. See <see cref="TextFormats"/> for common values.
128 /// </summary>
129 [JsonPropertyName("textFormat")]
130 public string? TextFormat { get; set; }
131
132 /// <summary>
133 /// Gets or sets the attachment layout.
134 /// </summary>
135 [JsonPropertyName("attachmentLayout")]
136 public string? AttachmentLayout { get; set; }
137
138
139
140 //TODO : Review properties
141 /*
142 /// <summary>
143 /// Gets or sets the SSML speak content of the message.
144 /// </summary>
145 [JsonPropertyName("speak")]
146 public string? Speak { get; set; }
147
148 /// <summary>
149 /// Gets or sets the input hint. See <see cref="InputHints"/> for common values.
150 /// </summary>
151 [JsonPropertyName("inputHint")]
152 public string? InputHint { get; set; }
153
154 /// <summary>
155 /// Gets or sets the summary of the message.
156 /// </summary>
157 [JsonPropertyName("summary")]
158 public string? Summary { get; set; }
159
160 /// <summary>
161 /// Gets or sets the importance. See <see cref="ImportanceLevels"/> for common values.
162 /// </summary>
163 [JsonPropertyName("importance")]
164 public string? Importance { get; set; }
165
166 /// <summary>
167 /// Gets or sets the delivery mode. See <see cref="DeliveryModes"/> for common values.
168 /// </summary>
169 [JsonPropertyName("deliveryMode")]
170 public string? DeliveryMode { get; set; }
171
172 /// <summary>
173 /// Gets or sets the expiration time of the message.
174 /// </summary>
175 [JsonPropertyName("expiration")]
176 public string? Expiration { get; set; }
177 */
178
179}
180
181/// <summary>
182/// String constants for text formats.
183/// </summary>
184public static class TextFormats
185{
186 /// <summary>
187 /// Plain text format.
188 /// </summary>
189 public const string Plain = "plain";
190
191 /// <summary>
192 /// Markdown text format.
193 /// </summary>
194 public const string Markdown = "markdown";
195
196 /// <summary>
197 /// XML text format.
198 /// </summary>
199 public const string Xml = "xml";
200}
201
202
203/*
204/// <summary>
205/// String constants for input hints.
206/// </summary>
207public static class InputHints
208{
209 /// <summary>
210 /// Accepting input hint.
211 /// </summary>
212 public const string AcceptingInput = "acceptingInput";
213
214 /// <summary>
215 /// Ignoring input hint.
216 /// </summary>
217 public const string IgnoringInput = "ignoringInput";
218
219 /// <summary>
220 /// Expecting input hint.
221 /// </summary>
222 public const string ExpectingInput = "expectingInput";
223}
224
225/// <summary>
226/// String constants for importance levels.
227/// </summary>
228public static class ImportanceLevels
229{
230 /// <summary>
231 /// Low importance.
232 /// </summary>
233 public const string Low = "low";
234
235 /// <summary>
236 /// Normal importance.
237 /// </summary>
238 public const string Normal = "normal";
239
240 /// <summary>
241 /// High importance.
242 /// </summary>
243 public const string High = "high";
244
245 /// <summary>
246 /// Urgent importance.
247 /// </summary>
248 public const string Urgent = "urgent";
249}
250
251/// <summary>
252/// String constants for delivery modes.
253/// </summary>
254public static class DeliveryModes
255{
256 /// <summary>
257 /// Normal delivery mode.
258 /// </summary>
259 public const string Normal = "normal";
260
261 /// <summary>
262 /// Notification delivery mode.
263 /// </summary>
264 public const string Notification = "notification";
265
266 /// <summary>
267 /// Ephemeral delivery mode.
268 /// </summary>
269 public const string Ephemeral = "ephemeral";
270
271 /// <summary>
272 /// Expected replies delivery mode.
273 /// </summary>
274 public const string ExpectedReplies = "expectReplies";
275}
276
277
278*/
279