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

populate state from skillcontext #1141

Merged
merged 1 commit into from
Apr 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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