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

Commit

Permalink
[4.4] Misc. Dispatch fixes (#1188)
Browse files Browse the repository at this point in the history
* updated scripts for single intent per skill

* updated template
  • Loading branch information
lauren-mills authored and darrenj committed Apr 30, 2019
1 parent 58d0029 commit 9dea7d0
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,86 +86,30 @@ if (-not $manifest) {
}

Write-Host "> Getting intents for dispatch ..."
try {
foreach ($action in $manifest.actions) {
if ($action.definition.triggers.utteranceSources) {
$sources = @{}
foreach ($source in ($action.definition.triggers.utteranceSources | Where-Object {$_.locale -eq $langCode})) {
foreach ($luisStr in $source.source) {
$luis = $luisStr -Split '#'
if ($sources.ContainsKey($luis[0])) {
$intents = $sources[$luis[0]]
$intents += $luis[1]
$sources[$luis[0]] = $intents
}
else {
$sources.Add($luis[0], @($luis[1]))
}
}
}

Write-Host "> Adding $($action.id) action to dispatch ..."
foreach ($luisApp in $sources.Keys) {
$intents = $sources[$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 `
--name $action.id `
--intentName $action.id `
--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
}
}
}
}
$dictionary = @{ }
foreach ($action in $manifest.actions) {
if ($action.definition.triggers.utteranceSources) {
foreach ($source in $action.definition.triggers.utteranceSources) {
foreach ($luisStr in $source.source) {
$luis = $luisStr -Split '#'
if ($dictionary.ContainsKey($luis[0])) {
$intents = $dictionary[$luis[0]]
$intents += $luis[1]
$dictionary[$luis[0]] = $intents
}
else {
$dictionary.Add($luis[0], @($luis[1]))
}
}
}
}
}
catch {
Break
}



Write-Host "> Adding skill to dispatch ..."
Write-Host "> Adding $($manifest.Id) to dispatch ..."
try {
$intentName = $manifest.Id
foreach ($luisApp in $dictionary.Keys) {
$intents = $dictionary[$luisApp]
$intentName = $manifest.Id
$intents = $dictionary[$luisApp] -Join ","
$luFile = Get-ChildItem -Path $(Join-Path $luisFolder "$($luisApp).lu") ` 2>> $logFile

if (-not $luFile) {
Expand Down Expand Up @@ -198,12 +142,13 @@ try {

if ($luisFile) {
(dispatch add `
--type file `
--filePath $luisFile `
--intentName $intentName `
--includedIntents $intents
--dataFolder $dispatchFolder `
--dispatch $(Join-Path $dispatchFolder "$($dispatchName).dispatch")) 2>> $logFile | Out-Null
--name $intentName `
--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
Expand All @@ -227,25 +172,25 @@ if (Test-Path $dispatchJsonPath) {

Write-Host "> Initializing skill.config ..."
if (Test-Path $skillsFile) {
$skillConfig = Get-Content $skillsFile | ConvertFrom-Json
$skillConfig = Get-Content $skillsFile | ConvertFrom-Json

if ($skillConfig) {
if ($skillConfig.skills) {
if ($skillConfig.skills.Id -eq $manifest.Id) {
Write-Host "! $($manifest.Id) is already registered." -ForegroundColor DarkRed
if ($skillConfig) {
if ($skillConfig.skills) {
if ($skillConfig.skills.Id -eq $manifest.Id) {
Write-Host "! $($manifest.Id) is already registered." -ForegroundColor DarkRed
$alreadyRegistered = $true;
}
else {
Write-Host "> Registering $($manifest.Id) ..."
$skillConfig.skills += $manifest
}
}
else {
Write-Host "> Registering $($manifest.Id) ..."
$skills = @($manifest)
$skillConfig | Add-Member -Type NoteProperty -Force -Name "skills" -Value $skills
}
}
}
else {
Write-Host "> Registering $($manifest.Id) ..."
$skillConfig.skills += $manifest
}
}
else {
Write-Host "> Registering $($manifest.Id) ..."
$skills = @($manifest)
$skillConfig | Add-Member -Type NoteProperty -Force -Name "skills" -Value $skills
}
}
}

if (-not $alreadyRegistered) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ if (-not $manifest) {
Write-Host "> Removing skill from dispatch ..."
$dispatch = Get-Content $dispatchPath | ConvertFrom-Json
if ($dispatch.services) {
$toRemove = $dispatch.services | Where-Object { $manifest.actions.id -contains $_.name }
$dispatch.services = $dispatch.services | Where-Object -FilterScript { $manifest.actions.id -notcontains $_.name }
$toRemove = $dispatch.services | Where-Object { $manifest.id -eq $_.name }
$dispatch.services = $dispatch.services | Where-Object -FilterScript { $manifest.id -ne $_.name }
$dispatch.serviceIds = $dispatch.serviceIds | Where-Object -FilterScript { $toRemove.id -notcontains $_ }

$dispatch | ConvertTo-Json -depth 100 | Out-File $dispatchPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.4.0-preview41" />
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.4.0-preview41" />
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.4.0-preview42" />
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.4.0-preview42" />
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.3.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,74 +86,75 @@ if (-not $manifest) {
}

Write-Host "> Getting intents for dispatch ..."
$dictionary = @{ }
foreach ($action in $manifest.actions) {
if ($action.definition.triggers.utteranceSources) {
foreach ($source in $action.definition.triggers.utteranceSources) {
foreach ($luisStr in $source.source) {
$luis = $luisStr -Split '#'
if ($dictionary.ContainsKey($luis[0])) {
$intents = $dictionary[$luis[0]]
$intents += $luis[1]
$dictionary[$luis[0]] = $intents
}
else {
$dictionary.Add($luis[0], @($luis[1]))
}
}
}
}
}

Write-Host "> Adding $($manifest.Id) to dispatch ..."
try {
foreach ($action in $manifest.actions) {
if ($action.definition.triggers.utteranceSources) {
$sources = @{}
foreach ($source in ($action.definition.triggers.utteranceSources | Where-Object {$_.locale -eq $langCode})) {
foreach ($luisStr in $source.source) {
$luis = $luisStr -Split '#'
if ($sources.ContainsKey($luis[0])) {
$intents = $sources[$luis[0]]
$intents += $luis[1]
$sources[$luis[0]] = $intents
}
else {
$sources.Add($luis[0], @($luis[1]))
}
}
}

Write-Host "> Adding $($action.id) action to dispatch ..."
foreach ($luisApp in $sources.Keys) {
$intents = $sources[$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 `
--name $action.id `
--intentName $action.id `
--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
}
}
foreach ($luisApp in $dictionary.Keys) {
$intentName = $manifest.Id
$intents = $dictionary[$luisApp] -Join ","
$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 `
--name $intentName `
--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
Expand All @@ -171,25 +172,25 @@ if (Test-Path $dispatchJsonPath) {

Write-Host "> Initializing skill.config ..."
if (Test-Path $skillsFile) {
$skillConfig = Get-Content $skillsFile | ConvertFrom-Json
$skillConfig = Get-Content $skillsFile | ConvertFrom-Json

if ($skillConfig) {
if ($skillConfig.skills) {
if ($skillConfig.skills.Id -eq $manifest.Id) {
Write-Host "! $($manifest.Id) is already registered." -ForegroundColor DarkRed
if ($skillConfig) {
if ($skillConfig.skills) {
if ($skillConfig.skills.Id -eq $manifest.Id) {
Write-Host "! $($manifest.Id) is already registered." -ForegroundColor DarkRed
$alreadyRegistered = $true;
}
else {
Write-Host "> Registering $($manifest.Id) ..."
$skillConfig.skills += $manifest
}
}
else {
Write-Host "> Registering $($manifest.Id) ..."
$skills = @($manifest)
$skillConfig | Add-Member -Type NoteProperty -Force -Name "skills" -Value $skills
}
}
}
else {
Write-Host "> Registering $($manifest.Id) ..."
$skillConfig.skills += $manifest
}
}
else {
Write-Host "> Registering $($manifest.Id) ..."
$skills = @($manifest)
$skillConfig | Add-Member -Type NoteProperty -Force -Name "skills" -Value $skills
}
}
}

if (-not $alreadyRegistered) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ if (-not $manifest) {
Write-Host "> Removing skill from dispatch ..."
$dispatch = Get-Content $dispatchPath | ConvertFrom-Json
if ($dispatch.services) {
$toRemove = $dispatch.services | Where-Object { $manifest.actions.id -contains $_.name }
$dispatch.services = $dispatch.services | Where-Object -FilterScript { $manifest.actions.id -notcontains $_.name }
$toRemove = $dispatch.services | Where-Object { $manifest.id -eq $_.name }
$dispatch.services = $dispatch.services | Where-Object -FilterScript { $manifest.id -ne $_.name }
$dispatch.serviceIds = $dispatch.serviceIds | Where-Object -FilterScript { $toRemove.id -notcontains $_ }

$dispatch | ConvertTo-Json -depth 100 | Out-File $dispatchPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected override async Task<InterruptionAction> OnInterruptDialogAsync(DialogC
var intent = dispatchResult.TopIntent().intent;

// 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());
var identifiedSkill = SkillRouter.IsSkill(_settings.Skills);

if(identifiedSkill != null)
{
Expand Down
Loading

0 comments on commit 9dea7d0

Please sign in to comment.