microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Api/AdaptiveCards/ActionResponse.cs
142lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using System.Text.Json.Serialization; |
| 5 | |
| 6 | namespace Microsoft.Teams.Api.AdaptiveCards; |
| 7 | |
| 8 | /// <summary> |
| 9 | /// Defines the structure that is returned as the result of an Invoke activity with |
| 10 | /// Name of 'adaptiveCard/action'. |
| 11 | /// </summary> |
| 12 | public class ActionResponse(ContentType contentType) |
| 13 | { |
| 14 | /// <summary> |
| 15 | /// The Card Action response status code. |
| 16 | /// </summary> |
| 17 | [JsonPropertyName("statusCode")] |
| 18 | [JsonPropertyOrder(0)] |
| 19 | public required int StatusCode { get; set; } |
| 20 | |
| 21 | /// <summary> |
| 22 | /// The type of this response. |
| 23 | /// </summary> |
| 24 | [JsonPropertyName("type")] |
| 25 | [JsonPropertyOrder(1)] |
| 26 | public ContentType Type { get; set; } = contentType; |
| 27 | |
| 28 | /// <summary> |
| 29 | /// the response value |
| 30 | /// </summary> |
| 31 | [JsonPropertyName("value")] |
| 32 | [JsonPropertyOrder(2)] |
| 33 | public object? Value { get; set; } |
| 34 | |
| 35 | /// <summary> |
| 36 | /// The request was successfully processed, and the response includes |
| 37 | /// an Adaptive Card that the client should display in place of the current one |
| 38 | /// </summary> |
| 39 | public class Card : ActionResponse |
| 40 | { |
| 41 | /// <summary> |
| 42 | /// The card response object. |
| 43 | /// </summary> |
| 44 | [JsonPropertyName("value")] |
| 45 | [JsonPropertyOrder(2)] |
| 46 | public new Cards.Card Value { get; set; } |
| 47 | |
| 48 | public Card(Cards.Card value) : base(ContentType.AdaptiveCard) |
| 49 | { |
| 50 | Value = value; |
| 51 | StatusCode = 200; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /// <summary> |
| 56 | /// The request was successfully processed, and the response includes a message that the client should display |
| 57 | /// </summary> |
| 58 | public class Message : ActionResponse |
| 59 | { |
| 60 | /// <summary> |
| 61 | /// the response message. |
| 62 | /// </summary> |
| 63 | [JsonPropertyName("value")] |
| 64 | [JsonPropertyOrder(2)] |
| 65 | public new string Value { get; set; } |
| 66 | |
| 67 | public Message(string value) : base(ContentType.Message) |
| 68 | { |
| 69 | Value = value; |
| 70 | StatusCode = 200; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /// <summary> |
| 75 | /// `400`: The incoming request was invalid |
| 76 | /// `500`: An unexpected error occurred |
| 77 | /// </summary> |
| 78 | public class Error : ActionResponse |
| 79 | { |
| 80 | /// <summary> |
| 81 | /// The error response object. |
| 82 | /// </summary> |
| 83 | [JsonPropertyName("value")] |
| 84 | [JsonPropertyOrder(2)] |
| 85 | public new Error Value { get; set; } |
| 86 | |
| 87 | public Error(Error value, int statusCode = 400) : base(ContentType.Message) |
| 88 | { |
| 89 | Value = value; |
| 90 | StatusCode = statusCode; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /// <summary> |
| 95 | /// The client needs to prompt the user to authenticate |
| 96 | /// </summary> |
| 97 | public class Login : ActionResponse |
| 98 | { |
| 99 | /// <summary> |
| 100 | /// The auth response object. |
| 101 | /// </summary> |
| 102 | [JsonPropertyName("value")] |
| 103 | [JsonPropertyOrder(2)] |
| 104 | public new Cards.OAuthCard Value { get; set; } |
| 105 | |
| 106 | public Login(Cards.OAuthCard value) : base(ContentType.LoginRequest) |
| 107 | { |
| 108 | Value = value; |
| 109 | StatusCode = 401; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /// <summary> |
| 114 | /// The authentication state passed by the client was incorrect and authentication failed |
| 115 | /// </summary> |
| 116 | public class IncorrectAuthCode : ActionResponse |
| 117 | { |
| 118 | public IncorrectAuthCode() : base(ContentType.IncorrectAuthCode) |
| 119 | { |
| 120 | StatusCode = 401; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /// <summary> |
| 125 | /// The SSO authentication flow failed |
| 126 | /// </summary> |
| 127 | public class PreConditionFailed : ActionResponse |
| 128 | { |
| 129 | /// <summary> |
| 130 | /// The auth response object. |
| 131 | /// </summary> |
| 132 | [JsonPropertyName("value")] |
| 133 | [JsonPropertyOrder(2)] |
| 134 | public new Error Value { get; set; } |
| 135 | |
| 136 | public PreConditionFailed(Error value) : base(ContentType.PreConditionFailed) |
| 137 | { |
| 138 | Value = value; |
| 139 | StatusCode = 412; |
| 140 | } |
| 141 | } |
| 142 | } |