microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.0.8

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/src/Microsoft.Teams.Apps/Schema/SuggestedAction.cs

147lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using System.Text.Json;
5using System.Text.Json.Nodes;
6using System.Text.Json.Serialization;
7
8namespace Microsoft.Teams.Apps.Schema;
9
10/// <summary>
11/// Represents a clickable action
12/// </summary>
13public class SuggestedAction
14{
15 /// <summary>
16 /// Default constructor for JSON deserialization.
17 /// </summary>
18 public SuggestedAction()
19 {
20 }
21
22 /// <summary>
23 /// Initializes a new instance of the <see cref="SuggestedAction"/> class with the specified type, title, and value.
24 /// </summary>
25 /// <param name="type">The type of action. See <see cref="ActionType"/> for common values.</param>
26 /// <param name="title">The text description displayed on the button.</param>
27 /// <param name="value">The value sent when the button is clicked. Accepts strings, anonymous objects, or <see cref="JsonNode"/> instances. Defaults to <paramref name="title"/> when not specified.</param>
28 public SuggestedAction(string type, string title, object? value = null)
29 {
30 Type = type;
31 Title = title;
32 Value = value switch
33 {
34 null => JsonValue.Create(title),
35 JsonNode n => n,
36 _ => JsonSerializer.SerializeToNode(value)
37 };
38 }
39
40 /// <summary>
41 /// Gets or sets the type of action implemented by this button.
42 /// See <see cref="ActionType"/> for common values.
43 /// </summary>
44 [JsonPropertyName("type")]
45 public string? Type { get; set; }
46
47 /// <summary>
48 /// Gets or sets the text description which appears on the button.
49 /// </summary>
50 [JsonPropertyName("title")]
51 public string? Title { get; set; }
52
53 /// <summary>
54 /// Gets or sets the image URL which will appear on the button, next to the text label.
55 /// </summary>
56 [JsonPropertyName("image")]
57 public string? Image { get; set; }
58
59 /// <summary>
60 /// Gets or sets the text for this action.
61 /// </summary>
62 [JsonPropertyName("text")]
63 public string? Text { get; set; }
64
65 /// <summary>
66 /// Gets or sets the text to display in the chat feed if the button is clicked.
67 /// </summary>
68 [JsonPropertyName("displayText")]
69 public string? DisplayText { get; set; }
70
71 /// <summary>
72 /// Gets or sets the supplementary parameter for the action.
73 /// The content of this property depends on the action type.
74 /// </summary>
75 [JsonPropertyName("value")]
76 public JsonNode? Value { get; set; }
77
78 /// <summary>
79 /// Gets or sets the channel-specific data associated with this action.
80 /// </summary>
81 [JsonPropertyName("channelData")]
82 public object? ChannelData { get; set; }
83
84 /// <summary>
85 /// Gets or sets the alternate image text to be used in place of the image.
86 /// </summary>
87 [JsonPropertyName("imageAltText")]
88 public string? ImageAltText { get; set; }
89}
90
91/// <summary>
92/// String constants for card action types.
93/// </summary>
94public static class ActionType
95{
96 /// <summary>
97 /// Opens the specified URL in the browser.
98 /// </summary>
99 public const string OpenUrl = "openUrl";
100
101 /// <summary>
102 /// Sends a message back to the bot as if the user typed it (visible to all conversation members).
103 /// </summary>
104 public const string IMBack = "imBack";
105
106 /// <summary>
107 /// Sends a message back to the bot privately (not visible to other conversation members).
108 /// </summary>
109 public const string PostBack = "postBack";
110
111 /// <summary>
112 /// Plays the specified audio content.
113 /// </summary>
114 public const string PlayAudio = "playAudio";
115
116 /// <summary>
117 /// Plays the specified video content.
118 /// </summary>
119 public const string PlayVideo = "playVideo";
120
121 /// <summary>
122 /// Displays the specified image.
123 /// </summary>
124 public const string ShowImage = "showImage";
125
126 /// <summary>
127 /// Downloads the specified file.
128 /// </summary>
129 public const string DownloadFile = "downloadFile";
130
131 /// <summary>
132 /// Initiates a sign-in flow.
133 /// </summary>
134 public const string SignIn = "signin";
135
136 /// <summary>
137 /// Initiates a phone call.
138 /// </summary>
139 public const string Call = "call";
140
141 /// <summary>
142 /// Suggested action of type Action.Submit. The action's Value is delivered to the bot
143 /// as a <c>suggestedActions/submit</c> invoke without sending a chat-visible message.
144 /// </summary>
145 [System.Diagnostics.CodeAnalysis.Experimental("ExperimentalTeamsSuggestedAction")]
146 public const string Submit = "Action.Submit";
147}
148