I’m using the Microsoft Bot framework ( 4.x) and we have the virtual assistant set up along with a few skills. We are currently trying to have a user interrupt their current dialog in a particular skill and jump to a new one. We want to add functionality that would then enable us to jump back to where the user left off the in previous exited skill.
The question I have is if it’s possible to pass information from skill to Virtual assistant that is persistent throughout the whole conversation ? The information would be a list of strings or something of that nature
If the dialog you are trying to retrieve the options in is a WaterfallDialog you can retrieve the options using the Options property, pass the options in using the options parameter.
Something like below:
// 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;
...
}
Use 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 OptionA{ get; set; }
public string OptionB{ get; set; }
}
// Passing options to Dialog
await dc.BeginDialogAsync(nameof(MyDialog), new MyOptions{ OptionA= "MyOptionOneValue", OptionB= "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.OptionA etc
}
Read more about EndDialogAsync
https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.dialogs.dialogcontext.enddialogasync?view=botbuilder-dotnet-stable#Microsoft_Bot_Builder_Dialogs_DialogContext_EndDialogAsync_System_Object_System_Threading_CancellationToken_
See if it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With