From 58d002984b52f3086452d97f38bcd07c4822f2e3 Mon Sep 17 00:00:00 2001 From: lauren-mills Date: Mon, 29 Apr 2019 16:35:17 -0700 Subject: [PATCH] support dispatch with skill intents (#1187) --- .../SkillDialog.cs | 4 +- .../SkillRouter.cs | 9 ++- .../Deployment/Scripts/add_remote_skill.ps1 | 56 +++++++++++++++++++ .../Dialogs/MainDialog.cs | 2 +- 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/SkillDialog.cs b/lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/SkillDialog.cs index a68c893560..9b8a85a738 100644 --- a/lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/SkillDialog.cs +++ b/lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/SkillDialog.cs @@ -83,7 +83,7 @@ public override async Task EndDialogAsync(ITurnContext turnContext, DialogInstan /// options. /// cancellation token. /// dialog turn result. - protected override async Task OnBeginDialogAsync(DialogContext innerDc, object options, CancellationToken cancellationToken = default(CancellationToken)) + protected override async Task OnBeginDialogAsync(DialogContext innerDc, object options = null, CancellationToken cancellationToken = default(CancellationToken)) { SkillContext slots = new SkillContext(); @@ -95,7 +95,7 @@ public override async Task EndDialogAsync(ITurnContext turnContext, DialogInstan In other scenarios (aggregated skill dispatch) we evaluate all possible slots against context and pass across enabling the Skill to perform it's own action identification. */ - var actionName = options as string; + var actionName = options != null ? options as string : null; if (actionName != null) { // Find the specified within the selected Skill for slot filling evaluation diff --git a/lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/SkillRouter.cs b/lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/SkillRouter.cs index 26c428a160..e570e4c609 100644 --- a/lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/SkillRouter.cs +++ b/lib/csharp/microsoft.bot.builder.skills/Microsoft.Bot.Builder.Skills/SkillRouter.cs @@ -17,7 +17,14 @@ public static class SkillRouter /// Whether the intent matches a Skill. public static SkillManifest IsSkill(List skillConfiguration, string dispatchIntent) { - return skillConfiguration.SingleOrDefault(s => s.Actions.Any(a => a.Id == dispatchIntent.ToString())); + var manifest = skillConfiguration.SingleOrDefault(s => s.Actions.Any(a => a.Id == dispatchIntent.ToString())); + + if (manifest == null) + { + manifest = skillConfiguration.SingleOrDefault(s => s.Id == dispatchIntent.ToString()); + } + + return manifest; } } } \ No newline at end of file diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Deployment/Scripts/add_remote_skill.ps1 b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Deployment/Scripts/add_remote_skill.ps1 index 2ca839ab6c..bc131162a8 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Deployment/Scripts/add_remote_skill.ps1 +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Deployment/Scripts/add_remote_skill.ps1 @@ -159,6 +159,62 @@ catch { Break } + + +Write-Host "> Adding skill to dispatch ..." +try { + $intentName = $manifest.Id + foreach ($luisApp in $dictionary.Keys) { + $intents = $dictionary[$luisApp] + $luFile = Get-ChildItem -Path $(Join-Path $luisFolder "$($luisApp).lu") ` 2>> $logFile + + if (-not $luFile) { + $luFile = Get-ChildItem -Path $(Join-Path $luisFolder $langCode "$($luisApp).lu") ` 2>> $logFile + + if ($luFile) { + $luisFolder = $(Join-Path $luisFolder $langCode) + } + else { + Write-Host "! Could not find $($manifest.Name) LU file. Please provide the -luisFolder parameter." -ForegroundColor DarkRed + Write-Host "! Checked the following locations:" -ForegroundColor DarkRed + Write-Host " $(Join-Path $luisFolder "$($luisApp).lu")" -ForegroundColor DarkRed + Write-Host " $(Join-Path $luisFolder $langCode "$($luisApp).lu")" -ForegroundColor DarkRed + Throw + } + } + + # Parse LU file + ludown parse toluis ` + --in $luFile ` + --luis_culture $language ` + --out_folder $luisFolder ` + --out "$($luisApp).luis" + + $luisFile = Get-ChildItem ` + -Path $luisFolder ` + -Filter "$($luisApp).luis" ` + -Recurse ` + -Force 2>> $logFile + + if ($luisFile) { + (dispatch add ` + --type file ` + --filePath $luisFile ` + --intentName $intentName ` + --includedIntents $intents + --dataFolder $dispatchFolder ` + --dispatch $(Join-Path $dispatchFolder "$($dispatchName).dispatch")) 2>> $logFile | Out-Null + } + else { + Write-Host "! Could not find LUIS file: $(Join-Path $luisFolder "$($luisApp).luis")" -ForegroundColor DarkRed + Break + } + } +} +catch { + Break +} + Write-Host "> Running dispatch refresh ..." (dispatch refresh ` --dispatch $(Join-Path $dispatchFolder "$($dispatchName).dispatch") ` diff --git a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/MainDialog.cs b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/MainDialog.cs index 6510543fb4..6aed6dabca 100644 --- a/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/MainDialog.cs +++ b/templates/Virtual-Assistant-Template/csharp/Sample/VirtualAssistantSample/Dialogs/MainDialog.cs @@ -117,7 +117,7 @@ protected override async Task OnInterruptDialogAsync(DialogC { // 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.ToString()); + await dc.BeginDialogAsync(identifiedSkill.Id); // Pass the activity we have var result = await dc.ContinueDialogAsync();