microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/samples/AllInvokesBot/Cards.cs
140lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using System.Text.Json.Nodes; |
| 5 | |
| 6 | namespace AllInvokesBot; |
| 7 | |
| 8 | public static class Cards |
| 9 | { |
| 10 | public static JsonObject CreateWelcomeCard() |
| 11 | { |
| 12 | return new JsonObject |
| 13 | { |
| 14 | ["type"] = "AdaptiveCard", |
| 15 | ["version"] = "1.4", |
| 16 | ["body"] = new JsonArray |
| 17 | { |
| 18 | new JsonObject |
| 19 | { |
| 20 | ["type"] = "TextBlock", |
| 21 | ["text"] = "Welcome to InvokesBot!", |
| 22 | ["size"] = "Large", |
| 23 | ["weight"] = "Bolder" |
| 24 | }, |
| 25 | new JsonObject |
| 26 | { |
| 27 | ["type"] = "TextBlock", |
| 28 | ["text"] = "Click the buttons below to test different invoke handlers:" |
| 29 | } |
| 30 | }, |
| 31 | ["actions"] = new JsonArray |
| 32 | { |
| 33 | new JsonObject |
| 34 | { |
| 35 | ["type"] = "Action.Execute", |
| 36 | ["id"] = "1234", |
| 37 | ["title"] = "Test Adaptive Card Action", |
| 38 | ["verb"] = "testAction", |
| 39 | ["data"] = new JsonObject |
| 40 | { |
| 41 | ["message"] = "Button clicked!" |
| 42 | } |
| 43 | }, |
| 44 | new JsonObject |
| 45 | { |
| 46 | ["type"] = "Action.Submit", |
| 47 | ["title"] = "Open Task Module", |
| 48 | ["data"] = new JsonObject |
| 49 | { |
| 50 | ["msteams"] = new JsonObject |
| 51 | { |
| 52 | ["type"] = "task/fetch" |
| 53 | } |
| 54 | } |
| 55 | }, |
| 56 | new JsonObject |
| 57 | { |
| 58 | ["type"] = "Action.Execute", |
| 59 | ["title"] = "Request File Upload", |
| 60 | ["verb"] = "requestFileUpload" |
| 61 | } |
| 62 | } |
| 63 | }; |
| 64 | } |
| 65 | |
| 66 | public static JsonObject CreateFileConsentCard() |
| 67 | { |
| 68 | return new JsonObject |
| 69 | { |
| 70 | ["description"] = "This is a sample file to demonstrate file consent", |
| 71 | ["sizeInBytes"] = 1024, |
| 72 | ["acceptContext"] = new JsonObject |
| 73 | { |
| 74 | ["fileId"] = "123456" |
| 75 | }, |
| 76 | ["declineContext"] = new JsonObject |
| 77 | { |
| 78 | ["fileId"] = "123456" |
| 79 | } |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | public static JsonObject CreateAdaptiveActionResponseCard(string? verb, string? message) |
| 84 | { |
| 85 | return new JsonObject |
| 86 | { |
| 87 | ["type"] = "AdaptiveCard", |
| 88 | ["version"] = "1.4", |
| 89 | ["body"] = new JsonArray |
| 90 | { |
| 91 | new JsonObject |
| 92 | { |
| 93 | ["type"] = "TextBlock", |
| 94 | ["text"] = $"Action '{verb}' executed", |
| 95 | ["weight"] = "Bolder" |
| 96 | }, |
| 97 | new JsonObject |
| 98 | { |
| 99 | ["type"] = "TextBlock", |
| 100 | ["text"] = $"Message: {message}", |
| 101 | ["wrap"] = true |
| 102 | } |
| 103 | } |
| 104 | }; |
| 105 | } |
| 106 | |
| 107 | public static JsonObject CreateTaskModuleCard() |
| 108 | { |
| 109 | return new JsonObject |
| 110 | { |
| 111 | ["type"] = "AdaptiveCard", |
| 112 | ["version"] = "1.4", |
| 113 | ["body"] = new JsonArray |
| 114 | { |
| 115 | new JsonObject |
| 116 | { |
| 117 | ["type"] = "TextBlock", |
| 118 | ["text"] = "Task Module" |
| 119 | } |
| 120 | }, |
| 121 | ["actions"] = new JsonArray |
| 122 | { |
| 123 | new JsonObject |
| 124 | { |
| 125 | ["type"] = "Action.Submit", |
| 126 | ["title"] = "Submit" |
| 127 | } |
| 128 | } |
| 129 | }; |
| 130 | } |
| 131 | |
| 132 | public static JsonObject CreateFileInfoCard(string? uniqueId, string? fileType) |
| 133 | { |
| 134 | return new JsonObject |
| 135 | { |
| 136 | ["uniqueId"] = uniqueId, |
| 137 | ["fileType"] = fileType |
| 138 | }; |
| 139 | } |
| 140 | } |