5

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

39fredy
  • 1,923
  • 2
  • 21
  • 40

1 Answers1

1

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.

Mohit Verma
  • 5,140
  • 2
  • 12
  • 27
  • It's a router dialog ( Main Dialog), I have DialogContext. I can't seem to find the passed Options in the DialogContext ( inside ActiveDialog, Context, Dialogs, Parent, Stack, etc) – 39fredy Aug 07 '19 at 13:35
  • To clarify, I am going from the Virtual Assistant to a dedicated Skill. The dedicated skill has a main dialog that then routes to a waterfall dialog similar to the out of the [box examples](https://github.com/microsoft/botframework-solutions/tree/master/skills/src/csharp/emailskill/emailskill/Dialogs). Virtual Assistant (MainDialog) -> Dedicated Skill (MainDialog) -> (Waterfall Dialog) – 39fredy Aug 07 '19 at 14:31