|
1 | 1 | using Newtonsoft.Json; |
2 | 2 | using Newtonsoft.Json.Converters; |
| 3 | +using Newtonsoft.Json.Linq; |
3 | 4 | using Newtonsoft.Json.Serialization; |
4 | 5 |
|
5 | 6 | namespace Microsoft.Teams.AI.Application |
@@ -37,15 +38,49 @@ public class StreamingChannelData |
37 | 38 |
|
38 | 39 | /// <summary> |
39 | 40 | /// Sets the Feedback Loop in Teams that allows a user to |
40 | | - /// give thumbs up or down to a response. |
| 41 | + /// give thumbs up or down to a response. Should not be set if setting feedbackLoopType. |
41 | 42 | /// </summary> |
42 | 43 | [JsonProperty(PropertyName = "feedbackLoopEnabled")] |
43 | 44 | public bool? feedbackLoopEnabled { get; set; } |
44 | 45 |
|
45 | 46 | /// <summary> |
46 | | - /// Represents the type of feedback loop. Set to "default" by default. It can be set to one of "default" or "custom". |
| 47 | + /// Represents the type of feedback loop. It can be set to one of "default" or "custom". |
47 | 48 | /// </summary> |
48 | | - [JsonProperty(PropertyName = "feedbackLoopType")] |
| 49 | + [JsonConverter(typeof(FeedbackLoopTypeConverter))] |
| 50 | + [JsonProperty(PropertyName = "feedbackLoop")] |
49 | 51 | public string? feedbackLoopType { get; set; } |
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// Converts feedbackLoopType string to/from the type property of a feedbackLoop object expected within a channelData JSON object. |
| 55 | + /// </summary> |
| 56 | + private class FeedbackLoopTypeConverter : JsonConverter<string?> |
| 57 | + { |
| 58 | + public override void WriteJson(JsonWriter writer, string? value, JsonSerializer serializer) |
| 59 | + { |
| 60 | + if (value is not null) |
| 61 | + { |
| 62 | + JObject obj = new JObject { { "type", value } }; |
| 63 | + obj.WriteTo(writer); |
| 64 | + } |
| 65 | + else |
| 66 | + { |
| 67 | + writer.WriteNull(); // Ensure null values are handled properly |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + public override string? ReadJson(JsonReader reader, Type objectType, string? existingValue, bool hasExistingValue, JsonSerializer serializer) |
| 72 | + { |
| 73 | + if (reader.TokenType == JsonToken.Null) |
| 74 | + return null; |
| 75 | + |
| 76 | + JObject obj = JObject.Load(reader); |
| 77 | + JToken? token = obj?["type"]; |
| 78 | + return token?.ToString(); |
| 79 | + } |
| 80 | + } |
50 | 81 | } |
51 | 82 | } |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
0 commit comments