microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/src/Microsoft.Teams.Bot.Apps/Handlers/MessageExtension/MessageExtensionAction.cs
347lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using System.Text.Json.Serialization; |
| 5 | using Microsoft.Teams.Bot.Apps.Schema; |
| 6 | using Microsoft.Teams.Bot.Apps.Schema.Entities; |
| 7 | |
| 8 | namespace Microsoft.Teams.Bot.Apps.Handlers.MessageExtension; |
| 9 | |
| 10 | /// <summary> |
| 11 | /// Message extension command context values. |
| 12 | /// </summary> |
| 13 | public static class MessageExtensionCommandContext |
| 14 | { |
| 15 | /// <summary> |
| 16 | /// Command invoked from a message (message action). |
| 17 | /// </summary> |
| 18 | public const string Message = "message"; |
| 19 | |
| 20 | /// <summary> |
| 21 | /// Command invoked from the compose box. |
| 22 | /// </summary> |
| 23 | public const string Compose = "compose"; |
| 24 | |
| 25 | /// <summary> |
| 26 | /// Command invoked from the command box. |
| 27 | /// </summary> |
| 28 | public const string CommandBox = "commandbox"; |
| 29 | } |
| 30 | |
| 31 | /// <summary> |
| 32 | /// Bot message preview action values. |
| 33 | /// </summary> |
| 34 | public static class BotMessagePreviewAction |
| 35 | { |
| 36 | /// <summary> |
| 37 | /// User clicked edit on the preview. |
| 38 | /// </summary> |
| 39 | public const string Edit = "edit"; |
| 40 | |
| 41 | /// <summary> |
| 42 | /// User clicked send on the preview. |
| 43 | /// </summary> |
| 44 | public const string Send = "send"; |
| 45 | } |
| 46 | |
| 47 | /// <summary> |
| 48 | /// Context information for message extension actions. |
| 49 | /// </summary> |
| 50 | public class MessageExtensionContext |
| 51 | { |
| 52 | /// <summary> |
| 53 | /// The theme of the Teams client. Common values: "default", "dark", "contrast". |
| 54 | /// </summary> |
| 55 | [JsonPropertyName("theme")] |
| 56 | public string? Theme { get; set; } |
| 57 | } |
| 58 | |
| 59 | /// <summary> |
| 60 | /// Message extension action payload for submit action and fetch task activities. |
| 61 | /// </summary> |
| 62 | public class MessageExtensionAction |
| 63 | { |
| 64 | /// <summary> |
| 65 | /// Id of the command assigned by the bot. |
| 66 | /// </summary> |
| 67 | [JsonPropertyName("commandId")] |
| 68 | public required string CommandId { get; set; } |
| 69 | |
| 70 | /// <summary> |
| 71 | /// The context from which the command originates. |
| 72 | /// See <see cref="MessageExtensionCommandContext"/> for common values. |
| 73 | /// </summary> |
| 74 | [JsonPropertyName("commandContext")] |
| 75 | public required string CommandContext { get; set; } |
| 76 | |
| 77 | /// <summary> |
| 78 | /// Bot message preview action taken by user. |
| 79 | /// See <see cref="BotMessagePreviewAction"/> for common values. |
| 80 | /// </summary> |
| 81 | [JsonPropertyName("botMessagePreviewAction")] |
| 82 | public string? BotMessagePreviewAction { get; set; } |
| 83 | |
| 84 | /// <summary> |
| 85 | /// The activity preview that was originally sent to Teams when showing the bot message preview. |
| 86 | /// This is sent back by Teams when the user clicks 'edit' or 'send' on the preview. |
| 87 | /// </summary> |
| 88 | // TODO : this needs to be activity type or something else - format is type, attachments[] |
| 89 | [JsonPropertyName("botActivityPreview")] |
| 90 | public IList<TeamsActivity>? BotActivityPreview { get; set; } |
| 91 | |
| 92 | /// <summary> |
| 93 | /// Data included with the submit action. |
| 94 | /// </summary> |
| 95 | [JsonPropertyName("data")] |
| 96 | public object? Data { get; set; } |
| 97 | |
| 98 | /// <summary> |
| 99 | /// Message content sent as part of the command request when the command is invoked from a message. |
| 100 | /// </summary> |
| 101 | [JsonPropertyName("messagePayload")] |
| 102 | public MessagePayload? MessagePayload { get; set; } |
| 103 | |
| 104 | /// <summary> |
| 105 | /// Context information for the action. |
| 106 | /// </summary> |
| 107 | [JsonPropertyName("context")] |
| 108 | public MessageExtensionContext? Context { get; set; } |
| 109 | } |
| 110 | |
| 111 | /// <summary> |
| 112 | /// Represents the individual message within a chat or channel where a message |
| 113 | /// action is taken. |
| 114 | /// </summary> |
| 115 | public class MessagePayload |
| 116 | { |
| 117 | /// <summary> |
| 118 | /// Unique id of the message. |
| 119 | /// </summary> |
| 120 | [JsonPropertyName("id")] |
| 121 | public required string Id { get; set; } |
| 122 | |
| 123 | /// <summary> |
| 124 | /// Timestamp of when the message was created. |
| 125 | /// </summary> |
| 126 | [JsonPropertyName("createdDateTime")] |
| 127 | public string? CreatedDateTime { get; set; } |
| 128 | |
| 129 | /// <summary> |
| 130 | /// Indicates whether a message has been soft deleted. |
| 131 | /// </summary> |
| 132 | [JsonPropertyName("deleted")] |
| 133 | public bool? Deleted { get; set; } |
| 134 | |
| 135 | /// <summary> |
| 136 | /// Subject line of the message. |
| 137 | /// </summary> |
| 138 | [JsonPropertyName("subject")] |
| 139 | public string? Subject { get; set; } |
| 140 | |
| 141 | /// <summary> |
| 142 | /// The importance of the message. |
| 143 | /// </summary> |
| 144 | /// <remarks> |
| 145 | /// See <see cref="MessagePayloadImportance"/> for common values. |
| 146 | /// </remarks> |
| 147 | [JsonPropertyName("importance")] |
| 148 | public string? Importance { get; set; } |
| 149 | |
| 150 | /// <summary> |
| 151 | /// Locale of the message set by the client. |
| 152 | /// </summary> |
| 153 | [JsonPropertyName("locale")] |
| 154 | public string? Locale { get; set; } |
| 155 | |
| 156 | /// <summary> |
| 157 | /// Link back to the message. |
| 158 | /// </summary> |
| 159 | [JsonPropertyName("linkToMessage")] |
| 160 | public string? LinkToMessage { get; set; } |
| 161 | |
| 162 | /// <summary> |
| 163 | /// Sender of the message. |
| 164 | /// </summary> |
| 165 | [JsonPropertyName("from")] |
| 166 | public MessageFrom? From { get; set; } |
| 167 | |
| 168 | /// <summary> |
| 169 | /// Plaintext/HTML representation of the content of the message. |
| 170 | /// </summary> |
| 171 | [JsonPropertyName("body")] |
| 172 | public MessagePayloadBody? Body { get; set; } |
| 173 | |
| 174 | /// <summary> |
| 175 | /// How the attachment(s) are displayed in the message. |
| 176 | /// </summary> |
| 177 | [JsonPropertyName("attachmentLayout")] |
| 178 | public string? AttachmentLayout { get; set; } |
| 179 | |
| 180 | /// <summary> |
| 181 | /// Attachments in the message - card, image, file, etc. |
| 182 | /// </summary> |
| 183 | [JsonPropertyName("attachments")] |
| 184 | public IList<MessagePayloadAttachment>? Attachments { get; set; } |
| 185 | |
| 186 | /// <summary> |
| 187 | /// List of entities mentioned in the message. |
| 188 | /// </summary> |
| 189 | [JsonPropertyName("mentions")] |
| 190 | public IList<MentionEntity>? Mentions { get; set; } |
| 191 | |
| 192 | /// <summary> |
| 193 | /// Reactions for the message. |
| 194 | /// </summary> |
| 195 | [JsonPropertyName("reactions")] |
| 196 | public IList<MessageReaction>? Reactions { get; set; } |
| 197 | } |
| 198 | |
| 199 | /// <summary> |
| 200 | /// Sender of the message. |
| 201 | /// </summary> |
| 202 | public class MessageFrom |
| 203 | { |
| 204 | /// <summary> |
| 205 | /// User information of the sender. |
| 206 | /// </summary> |
| 207 | [JsonPropertyName("user")] |
| 208 | public User? User { get; set; } |
| 209 | } |
| 210 | |
| 211 | /// <summary> |
| 212 | /// String constants for message importance levels. |
| 213 | /// </summary> |
| 214 | public static class MessagePayloadImportance |
| 215 | { |
| 216 | /// <summary> |
| 217 | /// Normal importance. |
| 218 | /// </summary> |
| 219 | public const string Normal = "normal"; |
| 220 | |
| 221 | /// <summary> |
| 222 | /// High importance. |
| 223 | /// </summary> |
| 224 | public const string High = "high"; |
| 225 | |
| 226 | /// <summary> |
| 227 | /// Urgent importance. |
| 228 | /// </summary> |
| 229 | public const string Urgent = "urgent"; |
| 230 | } |
| 231 | |
| 232 | /// <summary> |
| 233 | /// Message body content. |
| 234 | /// </summary> |
| 235 | public class MessagePayloadBody |
| 236 | { |
| 237 | /// <summary> |
| 238 | /// Type of content. Common values: "text", "html". |
| 239 | /// </summary> |
| 240 | [JsonPropertyName("contentType")] |
| 241 | public string? ContentType { get; set; } |
| 242 | |
| 243 | /// <summary> |
| 244 | /// The content of the message. |
| 245 | /// </summary> |
| 246 | [JsonPropertyName("content")] |
| 247 | public string? Content { get; set; } |
| 248 | } |
| 249 | |
| 250 | /// <summary> |
| 251 | /// Attachment in a message payload. |
| 252 | /// </summary> |
| 253 | public class MessagePayloadAttachment |
| 254 | { |
| 255 | /// <summary> |
| 256 | /// Unique identifier for the attachment. |
| 257 | /// </summary> |
| 258 | [JsonPropertyName("id")] |
| 259 | public string? Id { get; set; } |
| 260 | |
| 261 | /// <summary> |
| 262 | /// Type of attachment content. See <see cref="AttachmentContentType"/> for common values. |
| 263 | /// </summary> |
| 264 | [JsonPropertyName("contentType")] |
| 265 | public string? ContentType { get; set; } |
| 266 | |
| 267 | /// <summary> |
| 268 | /// The attachment content. |
| 269 | /// </summary> |
| 270 | [JsonPropertyName("content")] |
| 271 | public object? Content { get; set; } |
| 272 | } |
| 273 | |
| 274 | /// <summary> |
| 275 | /// Reaction to a message. |
| 276 | /// </summary> |
| 277 | public class MessagePayloadReaction |
| 278 | { |
| 279 | /// <summary> |
| 280 | /// Type of reaction |
| 281 | /// See <see cref="ReactionTypes"/> for common values. |
| 282 | /// </summary> |
| 283 | [JsonPropertyName("reactionType")] |
| 284 | public string? ReactionType { get; set; } |
| 285 | |
| 286 | /// <summary> |
| 287 | /// Timestamp when the reaction was created. |
| 288 | /// </summary> |
| 289 | [JsonPropertyName("createdDateTime")] |
| 290 | public string? CreatedDateTime { get; set; } |
| 291 | |
| 292 | /// <summary> |
| 293 | /// User who reacted. |
| 294 | /// </summary> |
| 295 | [JsonPropertyName("user")] |
| 296 | public User? User { get; set; } |
| 297 | } |
| 298 | |
| 299 | /// <summary> |
| 300 | /// Represents a user who created a reaction. |
| 301 | /// </summary> |
| 302 | public class User |
| 303 | { |
| 304 | /// <summary> |
| 305 | /// Gets or sets the user identifier. |
| 306 | /// </summary> |
| 307 | [JsonPropertyName("id")] |
| 308 | public string? Id { get; set; } |
| 309 | |
| 310 | /// <summary> |
| 311 | /// Gets or sets the user identity type. |
| 312 | /// </summary> |
| 313 | [JsonPropertyName("userIdentityType")] |
| 314 | public string? UserIdentityType { get; set; } |
| 315 | |
| 316 | /// <summary> |
| 317 | /// Gets or sets the display name of the user. |
| 318 | /// </summary> |
| 319 | [JsonPropertyName("displayName")] |
| 320 | public string? DisplayName { get; set; } |
| 321 | } |
| 322 | |
| 323 | /// <summary> |
| 324 | /// String constants for user identity types. |
| 325 | /// </summary> |
| 326 | public static class UserIdentityTypes |
| 327 | { |
| 328 | /// <summary> |
| 329 | /// Azure Active Directory user. |
| 330 | /// </summary> |
| 331 | public const string AadUser = "aadUser"; |
| 332 | |
| 333 | /// <summary> |
| 334 | /// On-premise Azure Active Directory user. |
| 335 | /// </summary> |
| 336 | public const string OnPremiseAadUser = "onPremiseAadUser"; |
| 337 | |
| 338 | /// <summary> |
| 339 | /// Anonymous guest user. |
| 340 | /// </summary> |
| 341 | public const string AnonymousGuest = "anonymousGuest"; |
| 342 | |
| 343 | /// <summary> |
| 344 | /// Federated user. |
| 345 | /// </summary> |
| 346 | public const string FederatedUser = "federatedUser"; |
| 347 | } |
| 348 | |