microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/samples/McpServer/Cards.cs
91lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using System.Text.Json; |
| 5 | using System.Text.Json.Serialization; |
| 6 | using Microsoft.Teams.Cards; |
| 7 | using Microsoft.Teams.Common; |
| 8 | |
| 9 | namespace McpServer; |
| 10 | |
| 11 | public static class Cards |
| 12 | { |
| 13 | private static readonly JsonSerializerOptions SerializerOptions = new() |
| 14 | { |
| 15 | DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull |
| 16 | }; |
| 17 | |
| 18 | public static JsonElement AskCard(string requestId, string question) |
| 19 | { |
| 20 | AdaptiveCard card = new( |
| 21 | new TextBlock(question) { Weight = TextWeight.Bolder, Size = TextSize.Medium, Wrap = true }, |
| 22 | new TextInput |
| 23 | { |
| 24 | Id = "reply", |
| 25 | Placeholder = "Type your reply...", |
| 26 | IsMultiline = true, |
| 27 | IsRequired = true, |
| 28 | ErrorMessage = "Please enter a reply." |
| 29 | }) |
| 30 | { |
| 31 | Version = Microsoft.Teams.Cards.Version.Version1_4, |
| 32 | Actions = new List<Microsoft.Teams.Cards.Action> |
| 33 | { |
| 34 | new ExecuteAction |
| 35 | { |
| 36 | Title = "Send", |
| 37 | Verb = "ask_reply", |
| 38 | AssociatedInputs = AssociatedInputs.Auto, |
| 39 | Data = new Union<string, SubmitActionData>(new SubmitActionData |
| 40 | { |
| 41 | NonSchemaProperties = new Dictionary<string, object?> |
| 42 | { |
| 43 | ["request_id"] = requestId |
| 44 | } |
| 45 | }) |
| 46 | } |
| 47 | } |
| 48 | }; |
| 49 | return JsonSerializer.SerializeToElement(card, SerializerOptions); |
| 50 | } |
| 51 | |
| 52 | public static JsonElement ApprovalCard(string approvalId, string title, string description) |
| 53 | { |
| 54 | AdaptiveCard card = new( |
| 55 | new TextBlock(title) { Weight = TextWeight.Bolder, Size = TextSize.Large, Wrap = true }, |
| 56 | new TextBlock(description) { Wrap = true }) |
| 57 | { |
| 58 | Version = Microsoft.Teams.Cards.Version.Version1_4, |
| 59 | Actions = new List<Microsoft.Teams.Cards.Action> |
| 60 | { |
| 61 | new ExecuteAction |
| 62 | { |
| 63 | Title = "Approve", |
| 64 | Verb = "approval_response", |
| 65 | Data = new Union<string, SubmitActionData>(new SubmitActionData |
| 66 | { |
| 67 | NonSchemaProperties = new Dictionary<string, object?> |
| 68 | { |
| 69 | ["approval_id"] = approvalId, |
| 70 | ["decision"] = ApprovalStatus.Approved |
| 71 | } |
| 72 | }) |
| 73 | }, |
| 74 | new ExecuteAction |
| 75 | { |
| 76 | Title = "Reject", |
| 77 | Verb = "approval_response", |
| 78 | Data = new Union<string, SubmitActionData>(new SubmitActionData |
| 79 | { |
| 80 | NonSchemaProperties = new Dictionary<string, object?> |
| 81 | { |
| 82 | ["approval_id"] = approvalId, |
| 83 | ["decision"] = ApprovalStatus.Rejected |
| 84 | } |
| 85 | }) |
| 86 | } |
| 87 | } |
| 88 | }; |
| 89 | return JsonSerializer.SerializeToElement(card, SerializerOptions); |
| 90 | } |
| 91 | } |
| 92 | |