I have CalendarSkill connected with my Virtual Assistant and its working fine. Instead of using Authentication Prompt I am generating Graph token in my Virtual Assistant and want to pass the same to the Skill. How can I pass the data to skillContext or maybe use slots (not sure how to retrieve or sent data using these slots).
I have tried passing data using DialogOptions but how to retrieve that data in skill.
Assuming that the dialog you are trying to retrieve the options in is a WaterfallDialog
you can retrieve the options using the Options
property, as you have already mentioned you pass the options in using the options
parameter.
How this looks is:
// 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;
...
}
I would recommend using a strongly typed class for passing in and retrieving the options, so you could create something which looks like the following:
// 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
}