Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
populate state from skillcontext (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenj authored Apr 23, 2019
1 parent d399aab commit 6933968
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using SkillSample.Responses.Main;
using SkillSample.Services;
using SkillSample.Responses.Shared;
using Microsoft.Bot.Builder.Skills;

namespace SkillSample.Dialogs
{
Expand Down Expand Up @@ -63,6 +64,9 @@ public MainDialog(
var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
var localeConfig = _services.CognitiveModelSets[locale];

// Populate state from SkillContext slots as required
await PopulateStateFromSkillContext(dc.Context);

// Get skill LUIS model from configuration
localeConfig.LuisServices.TryGetValue("skill", out var luisService);

Expand Down Expand Up @@ -243,6 +247,24 @@ private async Task<InterruptionAction> OnLogout(DialogContext dc)
return InterruptionAction.StartedDialog;
}

private async Task PopulateStateFromSkillContext(ITurnContext context)
{
// If we have a SkillContext object populated from the SkillMiddleware we can retrieve requests slot (parameter) data
// and make available in local state as appropriate.
var contextAccessor = _userState.CreateProperty<SkillContext>(nameof(SkillContext));
var skillContext = await contextAccessor.GetAsync(context, () => new SkillContext());
if (skillContext != null)
{
// Example of populating local state with data passed through Skill Context
//if (skillContext.ContainsKey("Location"))
//{
// // Add to your local state
// var state = await _stateAccessor.GetAsync(context, () => new SkillState());
// state.Location = skillContext["Location"];
//}
}
}

private void RegisterDialogs()
{
AddDialog(new SampleDialog(_settings, _services, _responseManager, _stateAccessor, TelemetryClient));
Expand Down

0 comments on commit 6933968

Please sign in to comment.