microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Plugins/Microsoft.Teams.Plugins.AspNetCore.DevTools/Events/ActivityEvent.cs
60lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using System.Text.Json.Serialization; |
| 5 | |
| 6 | using Microsoft.Teams.Api; |
| 7 | using Microsoft.Teams.Api.Activities; |
| 8 | |
| 9 | namespace Microsoft.Teams.Plugins.AspNetCore.DevTools.Events; |
| 10 | |
| 11 | public class ActivityEvent : IEvent |
| 12 | { |
| 13 | [JsonPropertyName("id")] |
| 14 | [JsonPropertyOrder(0)] |
| 15 | public Guid Id { get; } |
| 16 | |
| 17 | [JsonPropertyName("type")] |
| 18 | [JsonPropertyOrder(1)] |
| 19 | public string Type { get; } |
| 20 | |
| 21 | [JsonPropertyName("body")] |
| 22 | [JsonPropertyOrder(2)] |
| 23 | public object? Body { get; } |
| 24 | |
| 25 | [JsonPropertyName("chat")] |
| 26 | [JsonPropertyOrder(3)] |
| 27 | public Conversation Chat { get; set; } |
| 28 | |
| 29 | [JsonPropertyName("error")] |
| 30 | [JsonPropertyOrder(4)] |
| 31 | public object? Error { get; set; } |
| 32 | |
| 33 | [JsonPropertyName("sentAt")] |
| 34 | [JsonPropertyOrder(5)] |
| 35 | public DateTime SentAt { get; } |
| 36 | |
| 37 | public ActivityEvent(string type, IActivity body, Conversation chat) |
| 38 | { |
| 39 | Id = Guid.NewGuid(); |
| 40 | Type = $"activity.{type}"; |
| 41 | Body = body; |
| 42 | Chat = chat; |
| 43 | SentAt = DateTime.Now; |
| 44 | } |
| 45 | |
| 46 | public static ActivityEvent Received(IActivity body, Conversation chat) |
| 47 | { |
| 48 | return new("received", body, chat); |
| 49 | } |
| 50 | |
| 51 | public static ActivityEvent Sent(IActivity body, Conversation chat) |
| 52 | { |
| 53 | return new("sent", body, chat); |
| 54 | } |
| 55 | |
| 56 | public static ActivityEvent Err(IActivity body, Conversation chat, object error) |
| 57 | { |
| 58 | return new("error", body, chat) { Error = error }; |
| 59 | } |
| 60 | } |