microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fix/msal-agentic-cache

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/samples/McpServer/Cards.cs

91lines · 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.Cards;
7using Microsoft.Teams.Common;
8
9namespace McpServer;
10
11public 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