在 Microsoft Virtual Assistant 和 Skills 之间传递数据
Passing data between Microsoft Virtual Assistant and Skills
我已将 CalendarSkill 连接到我的虚拟助手,并且运行良好。我没有使用身份验证提示,而是在我的虚拟助手中生成图形令牌,并希望将其传递给技能。我如何将数据传递给 skillContext 或使用插槽(不确定如何使用这些插槽检索或发送数据)。
我曾尝试使用 DialogOptions 传递数据,但如何使用技巧检索该数据。
假设您试图在其中检索选项的对话框是 WaterfallDialog
您可以使用 Options
property, as you have already mentioned you pass the options in using the options
参数检索选项。
看起来是这样的:
// Call the dialog and pass through options
await dc.BeginDialogAsync(nameof(MyDialog), new { MyProperty1 = "MyProperty1Value", MyProperty2 = "MyProperty2Value" });
// Retrieve the options
public async Task<DialogTurnResult> MyWaterfallStepAsync(WaterfallStepContext waterfallStepContext, CancellationToken cancellationToken)
{
var passedInOptions = waterfallStepContext.Options;
...
}
我建议使用强类型 class 来传递和检索选项,这样您就可以创建如下所示的内容:
// Concrete class definition
public class MyOptions
{
public string MyOptionOne { get; set; }
public string MyOptionTwo { get; set; }
}
// Passing options to Dialog
await dc.BeginDialogAsync(nameof(MyDialog), new MyOptions{ MyOptionOne = "MyOptionOneValue", MyOptionTwo = "MyOptionTwo" });
// Retrieving options in child Dialog
using Newtonsoft.Json;
public async Task<DialogTurnResult> MyWaterfallStepAsync(WaterfallStepContext waterfallStepContext, CancellationToken cancellationToken)
{
var passedInOptions = waterfallStepContext.Options;
// Get passed in options, need to serialise the object before we deserialise because calling .ToString on the object is unreliable
MyOptions passedInMyOptions = JsonConvert.DeserializeObject<MyOptions>(JsonConvert.SerializeObject(waterfallStepContext.Options));
...
// Use retrieved options like passedInOptions.MyOptionOne etc
}
我已将 CalendarSkill 连接到我的虚拟助手,并且运行良好。我没有使用身份验证提示,而是在我的虚拟助手中生成图形令牌,并希望将其传递给技能。我如何将数据传递给 skillContext 或使用插槽(不确定如何使用这些插槽检索或发送数据)。
我曾尝试使用 DialogOptions 传递数据,但如何使用技巧检索该数据。
假设您试图在其中检索选项的对话框是 WaterfallDialog
您可以使用 Options
property, as you have already mentioned you pass the options in using the options
参数检索选项。
看起来是这样的:
// Call the dialog and pass through options
await dc.BeginDialogAsync(nameof(MyDialog), new { MyProperty1 = "MyProperty1Value", MyProperty2 = "MyProperty2Value" });
// Retrieve the options
public async Task<DialogTurnResult> MyWaterfallStepAsync(WaterfallStepContext waterfallStepContext, CancellationToken cancellationToken)
{
var passedInOptions = waterfallStepContext.Options;
...
}
我建议使用强类型 class 来传递和检索选项,这样您就可以创建如下所示的内容:
// Concrete class definition
public class MyOptions
{
public string MyOptionOne { get; set; }
public string MyOptionTwo { get; set; }
}
// Passing options to Dialog
await dc.BeginDialogAsync(nameof(MyDialog), new MyOptions{ MyOptionOne = "MyOptionOneValue", MyOptionTwo = "MyOptionTwo" });
// Retrieving options in child Dialog
using Newtonsoft.Json;
public async Task<DialogTurnResult> MyWaterfallStepAsync(WaterfallStepContext waterfallStepContext, CancellationToken cancellationToken)
{
var passedInOptions = waterfallStepContext.Options;
// Get passed in options, need to serialise the object before we deserialise because calling .ToString on the object is unreliable
MyOptions passedInMyOptions = JsonConvert.DeserializeObject<MyOptions>(JsonConvert.SerializeObject(waterfallStepContext.Options));
...
// Use retrieved options like passedInOptions.MyOptionOne etc
}