microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Api/Cards/Action.cs
111lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using System.Diagnostics.CodeAnalysis; |
| 5 | using System.Text.Json.Serialization; |
| 6 | |
| 7 | using Microsoft.Teams.Common; |
| 8 | |
| 9 | namespace Microsoft.Teams.Api.Cards; |
| 10 | |
| 11 | [JsonConverter(typeof(JsonConverter<ActionType>))] |
| 12 | public class ActionType(string value) : StringEnum(value) |
| 13 | { |
| 14 | public static readonly ActionType OpenUrl = new("openUrl"); |
| 15 | public bool IsOpenUrl => OpenUrl.Equals(Value); |
| 16 | |
| 17 | public static readonly ActionType IMBack = new("imBack"); |
| 18 | public bool IsIMBack => IMBack.Equals(Value); |
| 19 | |
| 20 | public static readonly ActionType PostBack = new("postBack"); |
| 21 | public bool IsPostBack => PostBack.Equals(Value); |
| 22 | |
| 23 | public static readonly ActionType PlayAudio = new("playAudio"); |
| 24 | public bool IsPlayAudio => PlayAudio.Equals(Value); |
| 25 | |
| 26 | public static readonly ActionType PlayVideo = new("playVideo"); |
| 27 | public bool IsPlayVideo => PlayVideo.Equals(Value); |
| 28 | |
| 29 | public static readonly ActionType ShowImage = new("showImage"); |
| 30 | public bool IsShowImage => ShowImage.Equals(Value); |
| 31 | |
| 32 | public static readonly ActionType DownloadFile = new("downloadFile"); |
| 33 | public bool IsDownloadFile => DownloadFile.Equals(Value); |
| 34 | |
| 35 | public static readonly ActionType SignIn = new("signin"); |
| 36 | public bool IsSignIn => SignIn.Equals(Value); |
| 37 | |
| 38 | public static readonly ActionType Call = new("call"); |
| 39 | public bool IsCall => Call.Equals(Value); |
| 40 | |
| 41 | /// <summary> |
| 42 | /// Suggested action of type Action.Submit. The action's Value is delivered to the bot |
| 43 | /// as a <c>suggestedActions/submit</c> invoke without sending a chat-visible message. |
| 44 | /// </summary> |
| 45 | [Experimental("ExperimentalTeamsSuggestedAction")] |
| 46 | public static readonly ActionType Submit = new("Action.Submit"); |
| 47 | |
| 48 | [Experimental("ExperimentalTeamsSuggestedAction")] |
| 49 | public bool IsSubmit => Submit.Equals(Value); |
| 50 | } |
| 51 | |
| 52 | public class Action(ActionType type) |
| 53 | { |
| 54 | /// <summary> |
| 55 | /// The type of action implemented by this button. Possible values include: 'openUrl', 'imBack', |
| 56 | /// 'postBack', 'playAudio', 'playVideo', 'showImage', 'downloadFile', 'signin', 'call', |
| 57 | /// 'messageBack', 'Action.Submit' |
| 58 | /// </summary> |
| 59 | [JsonPropertyName("type")] |
| 60 | [JsonPropertyOrder(0)] |
| 61 | public ActionType Type { get; set; } = type; |
| 62 | |
| 63 | /// <summary> |
| 64 | /// Text description which appears on the button |
| 65 | /// </summary> |
| 66 | [JsonPropertyName("title")] |
| 67 | [JsonPropertyOrder(1)] |
| 68 | public required string Title { get; set; } |
| 69 | |
| 70 | /// <summary> |
| 71 | /// Image URL which will appear on the button, next to text label |
| 72 | /// </summary> |
| 73 | [JsonPropertyName("image")] |
| 74 | [JsonPropertyOrder(2)] |
| 75 | public string? Image { get; set; } |
| 76 | |
| 77 | /// <summary> |
| 78 | /// Text for this action |
| 79 | /// </summary> |
| 80 | [JsonPropertyName("text")] |
| 81 | [JsonPropertyOrder(3)] |
| 82 | public string? Text { get; set; } |
| 83 | |
| 84 | /// <summary> |
| 85 | /// (Optional) text to display in the chat feed if the button is clicked |
| 86 | /// </summary> |
| 87 | [JsonPropertyName("displayText")] |
| 88 | [JsonPropertyOrder(4)] |
| 89 | public string? DisplayText { get; set; } |
| 90 | |
| 91 | /// <summary> |
| 92 | /// Supplementary parameter for action. Content of this property depends on the ActionType |
| 93 | /// </summary> |
| 94 | [JsonPropertyName("value")] |
| 95 | [JsonPropertyOrder(5)] |
| 96 | public object? Value { get; set; } |
| 97 | |
| 98 | /// <summary> |
| 99 | /// Channel-specific data associated with this action |
| 100 | /// </summary> |
| 101 | [JsonPropertyName("channelData")] |
| 102 | [JsonPropertyOrder(6)] |
| 103 | public object? ChannelData { get; set; } |
| 104 | |
| 105 | /// <summary> |
| 106 | /// Alternate image text to be used in place of the `image` field |
| 107 | /// </summary> |
| 108 | [JsonPropertyName("imageAltText")] |
| 109 | [JsonPropertyOrder(7)] |
| 110 | public string? ImageAltText { get; set; } |
| 111 | } |