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

[DO NOT MERGE][4.4] Template updates #1143

Merged
merged 19 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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 @@ -10,8 +10,6 @@
<PackageReference Include="Microsoft.AspNetCore.All" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.4.0-preview-8" />
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.4.0-preview-8" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public virtual void Initialize()
new SampleResponses());

Services.AddSingleton(ResponseManager);
Services.AddSingleton<TestAdapter, DefaultTestAdapter>();
Services.AddTransient<MainDialog>();
Services.AddTransient<SampleDialog>();
Services.AddSingleton<TestAdapter, DefaultTestAdapter>();
Services.AddTransient<IBot, DialogBot<MainDialog>>();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using SkillSample.Responses.Shared;
using SkillSample.Services;
using System.Globalization;

namespace SkillSample.Adapters
{
public class CustomSkillAdapter : SkillAdapter
public class CustomSkillAdapter : SkillWebSocketBotAdapter
{
public CustomSkillAdapter(
BotSettings settings,
ICredentialProvider credentialProvider,
UserState userState,
ConversationState conversationState,
BotStateSet botStateSet,
ResponseManager responseManager,
IBotTelemetryClient telemetryClient,
UserState userState)
: base(credentialProvider)
IBotTelemetryClient telemetryClient)
{
OnTurnError = async (context, exception) =>
{
Expand All @@ -37,7 +36,7 @@ public CustomSkillAdapter(
Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
Use(new EventDebuggerMiddleware());
Use(new AutoSaveStateMiddleware(botStateSet));
Use(new SkillMiddleware(userState));
Use(new SkillMiddleware(userState, conversationState, conversationState.CreateProperty<DialogState>(nameof(SkillSample))));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,84 @@
Param(
[string] $name,
[string] $resourceGroup = $name,
[string] $resourceGroup,
[string] $location,
[string] $appId,
[string] $appPassword,
[string] $luisAuthoringKey,
[string] $luisAuthoringRegion,
[string] $parametersFile,
[string] $outFolder = $(Get-Location)
[string] $outFolder = $(Get-Location),
[string] $logFile = $(Join-Path $PSScriptRoot .. "deploy_log.txt")
)

# Reset log file
if (Test-Path $logFile) {
Clear-Content $logFile -Force | Out-Null
}
else {
New-Item -Path $logFile | Out-Null
}

# Get mandatory parameters
if (-not $name) {
$name = Read-Host "Azure resource group name"
$resourceGroup = $name
$name = Read-Host "? Bot Name (used as default name for resource group and deployed resources)"
}

if (-not $resourceGroup) {
$resourceGroup = $name
}

if (-not $location) {
$location = Read-Host "Azure resource group region"
$location = Read-Host "? Azure resource group region"
}

if (-not $appPassword) {
$appPassword = Read-Host "Password for MSA app registration (must be at least 16 characters long, contain at least 1 special character, and contain at least 1 numeric character)"
$appPassword = Read-Host "? Password for MSA app registration (must be at least 16 characters long, contain at least 1 special character, and contain at least 1 numeric character)"
}

if (-not $luisAuthoringRegion) {
$luisAuthoringRegion = Read-Host "? LUIS Authoring Region (westus, westeurope, or australiaeast)"
}

if (-not $luisAuthoringKey) {
$luisAuthoringKey = Read-Host "LUIS Authoring Key (found at https://www.luis.ai/user/settings)"
Switch ($luisAuthoringRegion) {
"westus" {
$luisAuthoringKey = Read-Host "? LUIS Authoring Key (found at https://luis.ai/user/settings)"
Break
}
"westeurope" {
$luisAuthoringKey = Read-Host "? LUIS Authoring Key (found at https://eu.luis.ai/user/settings)"
Break
}
"australiaeast" {
$luisAuthoringKey = Read-Host "? LUIS Authoring Key (found at https://au.luis.ai/user/settings)"
Break
}
default {
Write-Host "! $($luisAuthoringRegion) is not a valid LUIS authoring region." -ForegroundColor DarkRed
Break
}
}

if (-not $luisAuthoringKey) {
Break
}
}

if (-not $appId) {
# Create app registration
$appId = az ad app create `
$appId = (az ad app create `
--display-name $name `
--password $appPassword `
--available-to-other-tenants `
--reply-urls https://token.botframework.com/.auth/web/redirect `
--reply-urls https://token.botframework.com/.auth/web/redirect) 2>> $logFile `
| ConvertFrom-Json `
| Select-Object -ExpandProperty appId

if(-not $appId) {
Write-Host "Could not provision Microsoft App Registration automatically. Please provide the -appId and -appPassword arguments for an existing app and try again." -ForegroundColor Cyan
Write-Host "! Could not provision Microsoft App Registration automatically. Review the log for more information." -ForegroundColor DarkRed
Write-Host "! Log: $($logFile)" -ForegroundColor DarkRed
Write-Host "+ Provision an app manually in the Azure Portal, then try again providing the -appId and -appPassword arguments." -ForegroundColor Magenta
Break
}
}
Expand All @@ -47,35 +87,57 @@ if (-not $appId) {
$timestamp = Get-Date -f MMddyyyyHHmmss

# Create resource group
Write-Host "Creating resource group ..."
az group create --name $name --location $location | Out-Null
Write-Host "> Creating resource group ..."
(az group create --name $name --location $location) 2>> $logFile | Out-Null

# Deploy Azure services (deploys LUIS, QnA Maker, Content Moderator, CosmosDB)
Write-Host "Deploying Azure services ..."
Write-Host "> Deploying Azure services (this could take a while)..." -ForegroundColor Yellow
if ($parametersFile) {
az group deployment create `
(az group deployment create `
--name $timestamp `
--resource-group $resourceGroup `
--template-file "$(Join-Path $PSScriptRoot '..' 'Resources' 'template.json')" `
--parameters "@$($parametersFile)" `
--parameters microsoftAppId=$appId microsoftAppPassword=$appPassword | Out-Null
--parameters microsoftAppId=$appId microsoftAppPassword="`"$($appPassword)`"") 2>> $logFile | Out-Null
}
else {
az group deployment create `
(az group deployment create `
--name $timestamp `
--resource-group $resourceGroup `
--template-file "$(Join-Path $PSScriptRoot '..' 'Resources' 'template.json')" `
--parameters microsoftAppId=$appId microsoftAppPassword=$appPassword | Out-Null
--parameters microsoftAppId=$appId microsoftAppPassword="`"$($appPassword)`"") 2>> $logFile | Out-Null
}

# Check for failed deployments
$operations = az group deployment operation list -g $resourceGroup -n $timestamp | ConvertFrom-Json
$failedOperations = $operations | Where { $_.properties.statusmessage.error -ne $null }
if ($failedOperations) {
foreach ($operation in $failedOperations) {
switch ($operation.properties.statusmessage.error.code) {
"MissingRegistrationForLocation" {
Write-Host "! Deployment failed for resource of type $($operation.properties.targetResource.resourceType). This resource is not avaliable in the location provided." -ForegroundColor DarkRed
Write-Host "+ Update the .\Deployment\Resources\parameters.template.json file with a valid region for this resource and provide the file path in the -parametersFile parameter." -ForegroundColor Magenta
}
default {
Write-Host "! Deployment failed for resource of type $($operation.properties.targetResource.resourceType)."
Write-Host "! Code: $($operation.properties.statusMessage.error.code)."
Write-Host "! Message: $($operation.properties.statusMessage.error.message)."
}
}
}

Write-Host "+ To delete this resource group, run 'az group delete -g $($resourceGroup) --no-wait'" -ForegroundColor Magenta
Break
}

# Get deployment outputs
$outputs = az group deployment show `
$outputs = (az group deployment show `
--name $timestamp `
--resource-group $resourceGroup `
--query properties.outputs | ConvertFrom-Json
--query properties.outputs) 2>> $logFile | ConvertFrom-Json

# Update appsettings.json
Write-Host "Updating appsettings.json ..."
Write-Host "> Updating appsettings.json ..."
if (Test-Path $(Join-Path $outFolder appsettings.json)) {
$settings = Get-Content $(Join-Path $outFolder appsettings.json) | ConvertFrom-Json
}
Expand All @@ -90,4 +152,4 @@ $settings | Add-Member -Type NoteProperty -Force -Name 'cosmosDb' -Value $output
$settings | ConvertTo-Json -depth 100 | Out-File $(Join-Path $outFolder appsettings.json)

# Deploy cognitive models
Invoke-Expression "$(Join-Path $PSScriptRoot 'deploy_cognitive_models.ps1') -name $($name) -location $($location) -luisAuthoringKey $luisAuthoringKey -outFolder $($outFolder)"
Invoke-Expression "$(Join-Path $PSScriptRoot 'deploy_cognitive_models.ps1') -name $($name) -luisAuthoringRegion $($luisAuthoringRegion) -luisAuthoringKey $($luisAuthoringKey) -outFolder $($outFolder)"
Original file line number Diff line number Diff line change
@@ -1,13 +1,58 @@
Param(
[Parameter(Mandatory=$true)][string] $name,
[Parameter(Mandatory=$true)][string] $location,
[Parameter(Mandatory=$true)][string] $luisAuthoringKey,
[string] $name,
[string] $luisAuthoringRegion,
[string] $luisAuthoringKey,
[string] $languages = "en-us",
[string] $outFolder = $(Get-Location)
[string] $outFolder = $(Get-Location),
[string] $logFile = $(Join-Path $PSScriptRoot .. "deploy_cognitive_models_log.txt")
)

. $PSScriptRoot\luis_functions.ps1


# Reset log file
if (Test-Path $logFile) {
Clear-Content $logFile -Force | Out-Null
}
else {
New-Item -Path $logFile | Out-Null
}

# Get mandatory parameters
if (-not $name) {
$name = Read-Host "? Base name for Cognitive Models"
$resourceGroup = $name
}

if (-not $luisAuthoringRegion) {
$luisAuthoringRegion = Read-Host "? LUIS Authoring Region (westus, westeurope, or australiaeast)"
}

if (-not $luisAuthoringKey) {
Switch ($luisAuthoringRegion) {
"westus" {
$luisAuthoringKey = Read-Host "? LUIS Authoring Key (found at https://luis.ai/user/settings)"
Break
}
"westeurope" {
$luisAuthoringKey = Read-Host "? LUIS Authoring Key (found at https://eu.luis.ai/user/settings)"
Break
}
"australiaeast" {
$luisAuthoringKey = Read-Host "? LUIS Authoring Key (found at https://au.luis.ai/user/settings)"
Break
}
default {
Write-Host "! $($luisAuthoringRegion) is not a valid LUIS authoring region." -ForegroundColor DarkRed
Break
}
}

if (-not $luisAuthoringKey) {
Break
}
}

# Initialize settings obj
$settings = @{ cognitiveModels = New-Object PSObject }

Expand All @@ -26,20 +71,25 @@ foreach ($language in $languages -split ",")
foreach ($lu in $luisFiles)
{
# Deploy LUIS model
$luisApp = DeployLUIS -name $name -lu_file $lu -region $location -luisAuthoringKey $luisAuthoringKey -language $language
$luisApp = DeployLUIS -name $name -lu_file $lu -region $location -luisAuthoringKey $luisAuthoringKey -language $language -log $logFile

# Add to config
$config.languageModels += @{
id = $lu.BaseName
name = $luisApp.name
appid = $luisApp.id
authoringkey = $luisauthoringkey
subscriptionkey = $luisauthoringkey
version = $luisApp.activeVersion
region = $location
}

RunLuisGen $lu "$($lu.BaseName)" $(Join-Path $outFolder Services)
if ($luisApp) {
# Add to config
$config.languageModels += @{
id = $lu.BaseName
name = $luisApp.name
appid = $luisApp.id
authoringkey = $luisauthoringkey
subscriptionkey = $luisauthoringkey
version = $luisApp.activeVersion
region = $location
}

RunLuisGen $lu "$($lu.BaseName)" $(Join-Path $outFolder Services)
}
else {
Write-Host "! Deployment failed for LUIS app: $($lu.BaseName)" -ForegroundColor Cyan
}
}

# Add config to cognitivemodels dictionary
Expand Down
Loading