Skip to content
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

Add support for custom objects within the dialogContext #37947

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
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
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
Expand Down Expand Up @@ -109,7 +110,7 @@ private static StartDialogRequestInternal CreateStartDialogRequest(StartDialogOp
{
DialogOptionsInternal dialogOptionsInternal = new DialogOptionsInternal(
startDialogOptions.BotAppId,
startDialogOptions.DialogContext);
startDialogOptions.DialogContext.ToDictionary(entry => entry.Key, entry => (object)JsonSerializer.Serialize(entry.Value)));
StartDialogRequestInternal startDialogRequestInternal = new StartDialogRequestInternal(dialogOptionsInternal, startDialogOptions.DialogInputType)
{
OperationContext = startDialogOptions.OperationContext == default ? Guid.NewGuid().ToString() : startDialogOptions.OperationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,39 @@ namespace Azure.Communication.CallAutomation.Tests.CallDialogs
public class CallDialogTests : CallAutomationTestBase
{
private const string dialogId = "92e08834-b6ee-4ede-8956-9fefa27a691c";
private static readonly Dictionary<string, object> dialogContextWithObject = new Dictionary<string, object>()
{
{
"context",
new
{
contextName = "name",
secondProperty = 1
}
}
};
private static readonly Dictionary<string, object> dialogContextWithString = new Dictionary<string, object>()
{
{
"context",
"context"
}
};
private static readonly StartDialogOptions _startDialogOptions = new StartDialogOptions(DialogInputType.PowerVirtualAgents, "botAppId", new Dictionary<string, object>())
{
OperationContext = "context"
};

private static readonly StartDialogOptions _startDialogWithCustomObjectOptions = new StartDialogOptions(DialogInputType.PowerVirtualAgents, "botAppId", dialogContextWithObject)
{
OperationContext = "context"
};

private static readonly StartDialogOptions _startDialogWithStringOptions = new StartDialogOptions(DialogInputType.PowerVirtualAgents, "botAppId", dialogContextWithString)
{
OperationContext = "context"
};

private static readonly StartDialogOptions _startDialogWithIdOptions = new StartDialogOptions(dialogId, DialogInputType.PowerVirtualAgents, "botAppId", new Dictionary<string, object>())
{
OperationContext = "context"
Expand Down Expand Up @@ -101,6 +129,14 @@ public void StopDialog_Return204NoContent(Func<CallDialog, Response<DialogResult
callDialog => callDialog.StartDialogAsync(_startDialogOptions)
},
new Func<CallDialog, Task<Response<DialogResult>>>?[]
{
callDialog => callDialog.StartDialogAsync(_startDialogWithCustomObjectOptions)
},
new Func<CallDialog, Task<Response<DialogResult>>>?[]
{
callDialog => callDialog.StartDialogAsync(_startDialogWithStringOptions)
},
new Func<CallDialog, Task<Response<DialogResult>>>?[]
{
callDialog => callDialog.StartDialogAsync(_startDialogWithIdOptions)
},
Expand All @@ -116,6 +152,14 @@ public void StopDialog_Return204NoContent(Func<CallDialog, Response<DialogResult
callDialog => callDialog.StartDialog(_startDialogOptions)
},
new Func<CallDialog, Response<DialogResult>>?[]
{
callDialog => callDialog.StartDialog(_startDialogWithCustomObjectOptions)
},
new Func<CallDialog, Response<DialogResult>>?[]
{
callDialog => callDialog.StartDialog(_startDialogWithStringOptions)
},
new Func<CallDialog, Response<DialogResult>>?[]
{
callDialog => callDialog.StartDialog(_startDialogWithIdOptions)
},
Expand Down