Skip to content

Added ConversationAccountConverter #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Agents.Core.Models;
using System;
using System.Text.Json;

namespace Microsoft.Agents.Core.Serialization.Converters
{
internal class ConversationAccountConverter : ConnectorConverter<ConversationAccount>
{
protected override void ReadExtensionData(ref Utf8JsonReader reader, ConversationAccount value, string propertyName, JsonSerializerOptions options)
{
var extensionData = JsonSerializer.Deserialize<JsonElement>(ref reader, options);
value.Properties.Add(propertyName, extensionData);
}

protected override bool TryReadExtensionData(ref Utf8JsonReader reader, ConversationAccount value, string propertyName, JsonSerializerOptions options)
{
if (propertyName.Equals(nameof(value.Properties)))
{
var propertyValue = JsonSerializer.Deserialize<object>(ref reader, options);

foreach (var element in propertyValue.ToJsonElements())
{
value.Properties.Add(element.Key, element.Value);
}

return true;
}

return false;
}

protected override bool TryWriteExtensionData(Utf8JsonWriter writer, ConversationAccount value, string propertyName)
{
if (propertyName.Equals(nameof(value.Properties)))
{
foreach (var extensionData in value.Properties)
{
writer.WritePropertyName(extensionData.Key);
extensionData.Value.WriteTo(writer);
}

return true;
}

return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@ private static JsonSerializerOptions ApplyCoreOptions(this JsonSerializerOptions
options.Converters.Add(new AudioCardConverter());
options.Converters.Add(new CardActionConverter());
options.Converters.Add(new ChannelAccountConverter());
options.Converters.Add(new ConversationAccountConverter());
options.Converters.Add(new EntityConverter());
options.Converters.Add(new AIEntityConverter());
options.Converters.Add(new TokenExchangeInvokeResponseConverter());
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Agents.Core.Models;
using Microsoft.Agents.Core.Serialization;
using Xunit;

namespace Microsoft.Agents.Model.Tests
{
public class ConversationAccountTests
{
[Fact]
public void ConversationAccount_RoundTrip()
{
var jsonIn = "{\"isGroup\":true,\"conversationType\":\"convType\",\"tenantId\":\"tenant_id\",\"id\":\"id\",\"name\":\"convName\",\"aadObjectId\":\"aadObject_id\",\"role\":\"convRole\",\"custom1\":\"custom1Value\",\"custom2\":\"custom2Value\"}";

var conversationAccountIn = ProtocolJsonSerializer.ToObject<ConversationAccount>(jsonIn);

Assert.Equal(2, conversationAccountIn.Properties.Count);

var jsonOut = ProtocolJsonSerializer.ToJson(conversationAccountIn);
Assert.Equal(jsonIn, jsonOut);
}
}
}
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public void ConversationReferenceRoundTrip()
var outJson = ProtocolJsonSerializer.ToJson(outReference);

// Specifically, should include: "bot": {} and not "agent": {}
var outExpected = "{\"activityId\":\"id\",\"user\":{\"id\":\"user\"},\"bot\":{\"id\":\"agent\"},\"conversation\":{\"id\":\"conversation\",\"properties\":{}},\"channelId\":\"channelId\",\"serviceUrl\":\"serviceUrl\",\"locale\":\"locale\"}";
var outExpected = "{\"activityId\":\"id\",\"user\":{\"id\":\"user\"},\"bot\":{\"id\":\"agent\"},\"conversation\":{\"id\":\"conversation\"},\"channelId\":\"channelId\",\"serviceUrl\":\"serviceUrl\",\"locale\":\"locale\"}";

Assert.Equal(outExpected, outJson);

@@ -58,7 +58,7 @@ public void InActivityConversationReferenceSerialize()
};

var outJson = ProtocolJsonSerializer.ToJson(activity);
var outExpected = "{\"relatesTo\":{\"activityId\":\"id\",\"user\":{\"id\":\"user\"},\"bot\":{\"id\":\"agent\"},\"conversation\":{\"id\":\"conversation\",\"properties\":{}},\"channelId\":\"channelId\",\"serviceUrl\":\"serviceUrl\",\"locale\":\"locale\"}}";
var outExpected = "{\"relatesTo\":{\"activityId\":\"id\",\"user\":{\"id\":\"user\"},\"bot\":{\"id\":\"agent\"},\"conversation\":{\"id\":\"conversation\"},\"channelId\":\"channelId\",\"serviceUrl\":\"serviceUrl\",\"locale\":\"locale\"}}";
Assert.Equal(outExpected, outJson);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"event","id":"470d790f-dcfb-4e7e-9d38-fdae48fcdba0","timestamp":"2024-11-14T03:21:53.5114019\u002B00:00","channelId":"pva-published-engine-direct","from":{"id":"9c73e213-d1a5-edcd-9eee-2db79aadb10f/806d3d4a-5c95-ef11-8a6a-6045bd03ceab","name":"crd17_getsCurrentWeather","role":"bot"},"conversation":{"id":"fe5203d5-03ce-44f1-8fb7-d26bf06ee40f","properties":{}},"recipient":{"id":"94219457-c13e-44ca-b91c-24078a4997c6","aadObjectId":"94219457-c13e-44ca-b91c-24078a4997c6","role":"user"},"channelData":{"streamType":"final","streamId":"e5084817-2e0d-4fca-bb27-3eca80ae49f8"},"replyToId":"406ffa1e-67a7-4ec9-9eef-f90cfbe0e389","valueType":"DynamicPlanStepBindUpdate","value":{"taskDialogId":"crd17_getsCurrentWeather.topic.MSNWeatherGetcurrentweather","arguments":{"units":"I","Location":"New York"}},"name":"DynamicPlanStepBindUpdate"}
{"type":"event","id":"470d790f-dcfb-4e7e-9d38-fdae48fcdba0","timestamp":"2024-11-14T03:21:53.5114019\u002B00:00","channelId":"pva-published-engine-direct","from":{"id":"9c73e213-d1a5-edcd-9eee-2db79aadb10f/806d3d4a-5c95-ef11-8a6a-6045bd03ceab","name":"crd17_getsCurrentWeather","role":"bot"},"conversation":{"id":"fe5203d5-03ce-44f1-8fb7-d26bf06ee40f"},"recipient":{"id":"94219457-c13e-44ca-b91c-24078a4997c6","aadObjectId":"94219457-c13e-44ca-b91c-24078a4997c6","role":"user"},"channelData":{"streamType":"final","streamId":"e5084817-2e0d-4fca-bb27-3eca80ae49f8"},"replyToId":"406ffa1e-67a7-4ec9-9eef-f90cfbe0e389","valueType":"DynamicPlanStepBindUpdate","value":{"taskDialogId":"crd17_getsCurrentWeather.topic.MSNWeatherGetcurrentweather","arguments":{"units":"I","Location":"New York"}},"name":"DynamicPlanStepBindUpdate"}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"message","id":"8a82a3f3-cddf-444b-b607-58c79f3486b8","timestamp":"2024-11-14T03:18:57.5507994\u002B00:00","channelId":"pva-published-engine-direct","from":{"id":"9c73e213-d1a5-edcd-9eee-2db79aadb10f/806d3d4a-5c95-ef11-8a6a-6045bd03ceab","name":"crd17_getsCurrentWeather","role":"bot"},"conversation":{"id":"fe5203d5-03ce-44f1-8fb7-d26bf06ee40f","properties":{}},"recipient":{"id":"94219457-c13e-44ca-b91c-24078a4997c6","aadObjectId":"94219457-c13e-44ca-b91c-24078a4997c6","role":"user"},"textFormat":"markdown","text":"Hello, I\u0027m Gets Current weather, a virtual assistant. I can answer general questions about the current weather as well as forecasts for today and tomorrow. Just so you are aware, I sometimes use AI to answer your questions.\n\n_**Note**: You can now customize this copilot\u0027s topics and knowledge for your own needs. For more information about this template and how to modify it, visit the template [documentation.](https://go.microsoft.com/fwlink/?linkid=2271069)_","speak":"Thanks for calling, how can I help?","inputHint":"acceptingInput","suggestedActions":{"actions":[{"type":"imBack","title":"What can I ask?","text":"What can I ask?","value":"What can I ask?"}]},"channelData":{"streamType":"final","streamId":"8a82a3f3-cddf-444b-b607-58c79f3486b8"},"replyToId":"b7b28891-a1a4-460d-ad37-11326f46fead"}
{"type":"message","id":"8a82a3f3-cddf-444b-b607-58c79f3486b8","timestamp":"2024-11-14T03:18:57.5507994\u002B00:00","channelId":"pva-published-engine-direct","from":{"id":"9c73e213-d1a5-edcd-9eee-2db79aadb10f/806d3d4a-5c95-ef11-8a6a-6045bd03ceab","name":"crd17_getsCurrentWeather","role":"bot"},"conversation":{"id":"fe5203d5-03ce-44f1-8fb7-d26bf06ee40f"},"recipient":{"id":"94219457-c13e-44ca-b91c-24078a4997c6","aadObjectId":"94219457-c13e-44ca-b91c-24078a4997c6","role":"user"},"textFormat":"markdown","text":"Hello, I\u0027m Gets Current weather, a virtual assistant. I can answer general questions about the current weather as well as forecasts for today and tomorrow. Just so you are aware, I sometimes use AI to answer your questions.\n\n_**Note**: You can now customize this copilot\u0027s topics and knowledge for your own needs. For more information about this template and how to modify it, visit the template [documentation.](https://go.microsoft.com/fwlink/?linkid=2271069)_","speak":"Thanks for calling, how can I help?","inputHint":"acceptingInput","suggestedActions":{"actions":[{"type":"imBack","title":"What can I ask?","text":"What can I ask?","value":"What can I ask?"}]},"channelData":{"streamType":"final","streamId":"8a82a3f3-cddf-444b-b607-58c79f3486b8"},"replyToId":"b7b28891-a1a4-460d-ad37-11326f46fead"}
Original file line number Diff line number Diff line change
@@ -9,8 +9,7 @@
"role": "bot"
},
"conversation": {
"id": "fe5203d5-03ce-44f1-8fb7-d26bf06ee40f",
"properties": {}
"id": "fe5203d5-03ce-44f1-8fb7-d26bf06ee40f"
},
"recipient": {
"id": "94219457-c13e-44ca-b91c-24078a4997c6",
Loading
Oops, something went wrong.