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

MainDialog and SkillRouter Fix #1110

Merged
merged 1 commit into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
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 @@ -96,6 +96,23 @@ public async Task DeserializeInvalidManifestFile()
}
}

[TestMethod()]
public async Task TestIsSkillHelper()
{
using (StreamReader sr = new StreamReader(@".\manifestTemplate.json"))
{
string manifestBody = await sr.ReadToEndAsync();
var skillManifest = JsonConvert.DeserializeObject<SkillManifest>(manifestBody);

List<SkillManifest> skillManifests = new List<SkillManifest>();
skillManifests.Add(skillManifest);

Assert.IsNotNull(SkillRouter.IsSkill(skillManifests, "calendarSkill/createEvent"));
Assert.IsNotNull(SkillRouter.IsSkill(skillManifests, "calendarSkill/updateEvent"));
Assert.IsNull(SkillRouter.IsSkill(skillManifests, "calendarSkill/MISSINGEVENT"));
}
}

/// <summary>
/// Test that a manifest is generated and the basic dynamic properties are changed.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,20 @@

namespace Microsoft.Bot.Builder.Skills
{
public class SkillRouter
/// <summary>
/// Skill Router class that helps Bots identify if a registered Skill matches the identified dispatch intent.
/// </summary>
public static class SkillRouter
{
private List<SkillManifest> _registeredSkills;

public SkillRouter(List<SkillManifest> registeredSkills)
/// <summary>
/// Helper method to go through a SkillManifeste and match the passed dispatch intent to a registered action.
/// </summary>
/// <param name="skillConfiguration">The Skill Configuration for the current Bot.</param>
/// <param name="dispatchIntent">The Dispatch intent to try and match to a skill.</param>
/// <returns>Whether the intent matches a Skill.</returns>
public static SkillManifest IsSkill(List<SkillManifest> skillConfiguration, string dispatchIntent)
{
// Retrieve any Skills that have been registered with the Bot
_registeredSkills = registeredSkills;
}

public SkillManifest IdentifyRegisteredSkill(string skillName)
{
SkillManifest matchedSkill = null;

// Did we find any skills?
if (_registeredSkills != null)
{
// Identify a skill by taking the LUIS model name identified by the dispatcher and matching to the skill luis model name
// Bug raised on dispatcher to move towards LuisModelId instead perhaps?
matchedSkill = _registeredSkills.FirstOrDefault(s => s.Name == skillName);
return matchedSkill;
}
else
{
return null;
}
return skillConfiguration.SingleOrDefault(s => s.Actions.Any(a => a.Id == dispatchIntent.ToString()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ protected override async Task<InterruptionAction> OnInterruptDialogAsync(DialogC
var dispatchResult = await cognitiveModels.DispatchService.RecognizeAsync<DispatchLuis>(dc.Context, CancellationToken.None);
var intent = dispatchResult.TopIntent().intent;

if (_settings.Skills.Any(s => s.Id == intent.ToString()))
{
var skill = _settings.Skills.Where(s => s.Id == intent.ToString()).First();
// Identify if the dispatch intent matches any Action within a Skill if so, we pass to the appropriate SkillDialog to hand-off
var identifiedSkill = SkillRouter.IsSkill(_settings.Skills, intent.ToString());

// Initialize the skill connection, the dispatch intent is the Action ID of the Skill enabling us to resolve the specific action and identify slots
await dc.BeginDialogAsync(skill.Id, intent);
if(identifiedSkill != null)
{
// We have identiifed a skill so initialize the skill connection with the target skill
// the dispatch intent is the Action ID of the Skill enabling us to resolve the specific action and identify slots
await dc.BeginDialogAsync(identifiedSkill.Id, intent);

// Pass the activity we have
var result = await dc.ContinueDialogAsync();
Expand Down