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

loosen checks on SkillDialog BeginDialog logic #1101

Merged
merged 1 commit into from
Apr 13, 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 @@ -44,11 +44,12 @@ public class SkillDialog : ComponentDialog
/// <param name="proactiveState">Proactive State.</param>
/// <param name="endpointService">Endpoint Service.</param>
/// <param name="telemetryClient">Telemetry Client.</param>
/// <param name="backgroundTaskQueue">Background Task Queue.</param>
/// <param name="useCachedTokens">Use Cached Tokens.</param>
/// <param name="userState">UserState.</param>
/// <param name="authDialog">Auth Dialog.</param>
public SkillDialog(SkillManifest skillManifest, ResponseManager responseManager, MicrosoftAppCredentialsEx microsoftAppCredentialsEx, IBotTelemetryClient telemetryClient, UserState userState, MultiProviderAuthDialog authDialog = null)
: base(skillManifest.Id)
{

_skillManifest = skillManifest;
_microsoftAppCredentialsEx = microsoftAppCredentialsEx;
_telemetryClient = telemetryClient;
Expand All @@ -70,42 +71,41 @@ public SkillDialog(SkillManifest skillManifest, ResponseManager responseManager,
/// <returns>dialog turn result.</returns>
protected override async Task<DialogTurnResult> OnBeginDialogAsync(DialogContext innerDc, object options, CancellationToken cancellationToken = default(CancellationToken))
{
Dictionary<string, object> slotsToPass = new Dictionary<string, object>();

// Retrieve the SkillContext state object to identify slots (parameters) that can be used to slot-fill when invoking the skill
var accessor = _userState.CreateProperty<SkillContext>(nameof(SkillContext));
var skillContext = await accessor.GetAsync(innerDc.Context, () => new SkillContext());

var actionName = options as string;
if (actionName == null)
{
throw new ArgumentException("SkillDialog requires an Action in order to be able to identify which Action within a skill to invoke.");
}
else
{
// Find the Action within the selected Skill for slot filling evaluation
_action = _skillManifest.Actions.Single(a => a.Id == actionName);
if (_action == null)
if (_action != null)
{
throw new ArgumentException($"Passed Action ({actionName}) could not be found within the {_skillManifest.Id} skill manifest action definition.");
}
}

// Retrieve the SkillContext state object to identify slots (parameters) that can be used
// to slot-fill when invoking the skill
var accessor = _userState.CreateProperty<SkillContext>(nameof(SkillContext));
var skillContext = await accessor.GetAsync(innerDc.Context, () => new SkillContext());

Dictionary<string, object> slotsToPass = new Dictionary<string, object>();

// If we don't have any state then we skip Slot filling
if (skillContext != null && skillContext.Count > 0)
{
// Do we have slots?
if (_action != null && _action.Definition.Slots != null)
{
// For each slot we check to see if there is an exact match, if so we pass this slot across to the skill
foreach (Slot slot in _action.Definition.Slots)
// If the action doesn't define any Slots or SkillContext is empty then we skip slot evaluation
if (_action.Definition.Slots != null && skillContext.Count > 0)
{
if (skillContext.TryGetValue(slot.Name, out object slotValue))
foreach (Slot slot in _action.Definition.Slots)
{
slotsToPass.Add(slot.Name, slotValue);
// For each slot we check to see if there is an exact match, if so we pass this slot across to the skill
if (skillContext.TryGetValue(slot.Name, out object slotValue))
{
slotsToPass.Add(slot.Name, slotValue);
}
}
}
}
else
{
// Loosening checks for current Dispatch evaluation, TODO - Review
//throw new ArgumentException($"Passed Action ({actionName}) could not be found within the {_skillManifest.Id} skill manifest action definition.");
}
}

var activity = innerDc.Context.Activity;
Expand Down