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

Commit

Permalink
Update Sample Skill
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoCardozo94 committed Jul 30, 2019
1 parent db429a6 commit c1ac5da
Show file tree
Hide file tree
Showing 9 changed files with 605 additions and 111 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appInsightsLocation": {
"value": "westus2"
},
"luisServiceLocation": {
"value": "westus"
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"useCosmosDb": {
"value": false
},
"useStorage": {
"value": false
},
"appServicePlanSku": {
"value": {
"tier": "Free",
"name": "F1"
}
},
"botServiceSku": {
"value": "F0"
},
"luisServiceSku": {
"value": "F0"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,35 @@
"type": "string",
"defaultValue": "[resourceGroup().location]"
},
"suffix": {
"type": "string",
"defaultValue": "[take(uniqueString(resourceGroup().id), 7)]"
},
"microsoftAppId": {
"type": "string"
},
"microsoftAppPassword": {
"type": "string"
},
"useCosmosDb": {
"type": "bool",
"defaultValue": true
},
"cosmosDbName": {
"type": "string",
"defaultValue": "[toLower(parameters('name'))]"
"defaultValue": "[concat(parameters('name'), '-', parameters('suffix'))]"
},
"useStorage": {
"type": "bool",
"defaultValue": true
},
"storageAccountName": {
"type": "string",
"defaultValue": "[toLower(parameters('name'))]"
"defaultValue": "[concat(parameters('name'), '-', parameters('suffix'))]"
},
"appServicePlanName": {
"type": "string",
"defaultValue": "[parameters('name')]"
"defaultValue": "[concat(parameters('name'), '-', parameters('suffix'))]"
},
"appServicePlanSku": {
"type": "object",
Expand All @@ -37,27 +49,27 @@
},
"appInsightsName": {
"type": "string",
"defaultValue": "[parameters('name')]"
"defaultValue": "[concat(parameters('name'), '-', parameters('suffix'))]"
},
"appInsightsLocation": {
"type": "string",
"defaultValue": "westus2"
"defaultValue": "[resourceGroup().location]"
},
"botWebAppName": {
"type": "string",
"defaultValue": "[parameters('name')]"
"defaultValue": "[concat(parameters('name'), '-', parameters('suffix'))]"
},
"botServiceName": {
"type": "string",
"defaultValue": "[parameters('name')]"
"defaultValue": "[concat(parameters('name'), '-', parameters('suffix'))]"
},
"botServiceSku": {
"type": "string",
"defaultValue": "S1"
},
"luisServiceName": {
"type": "string",
"defaultValue": "[concat(parameters('name'), '-luis')]"
"defaultValue": "[concat(parameters('name'), '-luis-', parameters('suffix'))]"
},
"luisServiceSku": {
"type": "string",
Expand All @@ -69,8 +81,10 @@
}
},
"variables": {
"botEndpoint": "[concat('https://', toLower(parameters('botWebAppName')), '.azurewebsites.net/api/messages')]",
"cleanStorageAccountName": "[toLower(take(replace(replace(parameters('storageAccountName'), '-', ''), '_', ''), 24))]"
"botWebAppName": "[replace(parameters('botWebAppName'), '_', '')]",
"storageAccountName": "[toLower(take(replace(replace(parameters('storageAccountName'), '-', ''), '_', ''), 24))]",
"cosmosDbAccountName": "[toLower(take(replace(parameters('cosmosDbName'), '_', ''), 31))]",
"botEndpoint": "[concat('https://', toLower(variables('botWebAppName')), '.azurewebsites.net/api/messages')]"
},
"resources": [
{
Expand All @@ -91,7 +105,7 @@
"type": "Microsoft.DocumentDB/databaseAccounts",
"kind": "GlobalDocumentDB",
"apiVersion": "2015-04-08",
"name": "[parameters('cosmosDbName')]",
"name": "[variables('cosmosDbAccountName')]",
"location": "[parameters('location')]",
"properties": {
"databaseAccountOfferType": "Standard",
Expand All @@ -101,18 +115,20 @@
"failoverPriority": 0
}
]
}
},
},
"condition": "[parameters('useCosmosDb')]"
},
{
"comments": "storage account",
"type": "Microsoft.Storage/storageAccounts",
"kind": "StorageV2",
"apiVersion": "2018-07-01",
"name": "[variables('cleanStorageAccountName')]",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_LRS"
}
},
"condition": "[parameters('useStorage')]"
},
{
"comments": "app service plan",
Expand All @@ -138,7 +154,7 @@
"comments": "bot web app",
"type": "Microsoft.Web/sites",
"apiVersion": "2018-02-01",
"name": "[parameters('botWebAppName')]",
"name": "[variables('botWebAppName')]",
"location": "[parameters('location')]",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
Expand Down Expand Up @@ -185,7 +201,7 @@
"displayName": "[parameters('botServiceName')]",
"endpoint": "[variables('botEndpoint')]",
"msaAppId": "[parameters('microsoftAppId')]",
"developerAppInsightKey": "[reference(resourceId('Microsoft.Insights/components', parameters('appInsightsName'))).InstrumentationKey]",
"developerAppInsightKey": "[reference(resourceId('Microsoft.Insights/components', parameters('appInsightsName'))).instrumentationKey]",
"developerAppInsightsApplicationId": "[reference(resourceId('Microsoft.Insights/components', parameters('appInsightsName'))).ApplicationId]"
}
},
Expand All @@ -202,32 +218,37 @@
}
],
"outputs": {
"botWebAppName": {
"type": "string",
"value": "[variables('botWebAppName')]"
},
"appInsights": {
"type": "object",
"value": {
"appId": "[reference(resourceId('Microsoft.Insights/components', parameters('appInsightsName'))).AppId]",
"instrumentationKey": "[reference(resourceId('Microsoft.Insights/components', parameters('appInsightsName'))).InstrumentationKey]"
"instrumentationKey": "[reference(resourceId('Microsoft.Insights/components', parameters('appInsightsName'))).instrumentationKey]"
}
},
"storage": {
"blobStorage": {
"type": "object",
"value": {
"connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('cleanStorageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('cleanStorageAccountName')), '2018-07-01').keys[0].value, ';EndpointSuffix=core.windows.net')]",
"connectionString": "[if(parameters('useStorage'), concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2018-07-01').keys[0].value, ';EndpointSuffix=core.windows.net'), '')]",
"container": "transcripts"
}
},
"cosmosDb": {
"type": "object",
"value": {
"cosmosDBEndpoint": "[reference(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('cosmosDbName'))).documentEndpoint]",
"authkey": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('cosmosDbName')), '2015-04-08').primaryMasterKey]",
"cosmosDBEndpoint": "[if(parameters('useCosmosDb'), reference(resourceId('Microsoft.DocumentDB/databaseAccounts', variables('cosmosDbAccountName'))).documentEndpoint, '')]",
"authKey": "[if(parameters('useCosmosDb'), listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', variables('cosmosDbAccountName')), '2015-04-08').primaryMasterKey, '')]",
"databaseId": "botstate-db",
"collectionId": "botstate-collection"
}
},
"luis": {
"type": "object",
"value": {
"accountName": "[parameters('luisServiceName')]",
"region": "[parameters('luisServiceLocation')]",
"key": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', parameters('luisServiceName')),'2017-04-18').key1]"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ else {
New-Item -Path $logFile | Out-Null
}

if (-not (Test-Path (Join-Path $projDir 'appsettings.json')))
{
Write-Host "! Could not find an 'appsettings.json' file in the current directory." -ForegroundColor DarkRed
Write-Host "+ Please re-run this script from your project directory." -ForegroundColor Magenta
Break
}

# Get mandatory parameters
if (-not $name) {
$name = Read-Host "? Bot Name (used as default name for resource group and deployed resources)"
Expand Down Expand Up @@ -72,9 +79,10 @@ if (-not $appId) {
# Create app registration
$app = (az ad app create `
--display-name $name `
--password $appPassword `
--password `"$($appPassword)`" `
--available-to-other-tenants `
--reply-urls 'https://token.botframework.com/.auth/web/redirect')
--reply-urls 'https://token.botframework.com/.auth/web/redirect' `
--output json)

# Retrieve AppId
if ($app) {
Expand All @@ -94,18 +102,20 @@ $timestamp = Get-Date -f MMddyyyyHHmmss

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

# Deploy Azure services (deploys LUIS, QnA Maker, Content Moderator, CosmosDB)
if ($parametersFile) {
Write-Host "> Validating Azure deployment ..."
$validation = az group deployment validate `
--resource-group $resourceGroup `
--template-file "$(Join-Path $PSScriptRoot '..' 'resources' 'template.json')" `
--resource-group $resourcegroup `
--template-file "$(Join-Path $PSScriptRoot '..' 'resources' 'template.json')" `
--parameters "@$($parametersFile)" `
--parameters name=$name microsoftAppId=$appId microsoftAppPassword="`"$($appPassword)`""
--parameters name=$name microsoftAppId=$appId microsoftAppPassword="`"$($appPassword)`"" `
--output json

if ($validation) {
$validation >> $logFile
$validation = $validation | ConvertFrom-Json

if (-not $validation.error) {
Expand All @@ -115,11 +125,13 @@ if ($parametersFile) {
--resource-group $resourceGroup `
--template-file "$(Join-Path $PSScriptRoot '..' 'resources' 'template.json')" `
--parameters "@$($parametersFile)" `
--parameters name=$name microsoftAppId=$appId microsoftAppPassword="`"$($appPassword)`""
--parameters name=$name microsoftAppId=$appId microsoftAppPassword="`"$($appPassword)`"" `
--output json
}
else {
Write-Host "! Template is not valid with provided parameters." -ForegroundColor DarkRed
Write-Host "! Template is not valid with provided parameters. Review the log for more information." -ForegroundColor DarkRed
Write-Host "! Error: $($validation.error.message)" -ForegroundColor DarkRed
Write-Host "! Log: $($logFile)" -ForegroundColor DarkRed
Write-Host "+ To delete this resource group, run 'az group delete -g $($resourceGroup) --no-wait'" -ForegroundColor Magenta
Break
}
Expand All @@ -128,11 +140,13 @@ if ($parametersFile) {
else {
Write-Host "> Validating Azure deployment ..."
$validation = az group deployment validate `
--resource-group $resourceGroup `
--template-file "$(Join-Path $PSScriptRoot '..' 'resources' 'template.json')" `
--parameters name=$name microsoftAppId=$appId microsoftAppPassword="`"$($appPassword)`""
--resource-group $resourcegroup `
--template-file "$(Join-Path $PSScriptRoot '..' 'resources' 'template.json')" `
--parameters name=$name microsoftAppId=$appId microsoftAppPassword="`"$($appPassword)`"" `
--output json

if ($validation) {
$validation >> $logFile
$validation = $validation | ConvertFrom-Json

if (-not $validation.error) {
Expand All @@ -141,11 +155,13 @@ else {
--name $timestamp `
--resource-group $resourceGroup `
--template-file "$(Join-Path $PSScriptRoot '..' 'resources' 'template.json')" `
--parameters name=$name microsoftAppId=$appId microsoftAppPassword="`"$($appPassword)`""
--parameters name=$name microsoftAppId=$appId microsoftAppPassword="`"$($appPassword)`"" `
--output json
}
else {
Write-Host "! Template is not valid with provided parameters." -ForegroundColor DarkRed
Write-Host "! Error: $($validation.error.message)" -ForegroundColor DarkRed
Write-Host "! Template is not valid with provided parameters. Review the log for more information." -ForegroundColor DarkRed
Write-Host "! Error: $($validation.error.message)" -ForegroundColor DarkRed
Write-Host "! Log: $($logFile)" -ForegroundColor DarkRed
Write-Host "+ To delete this resource group, run 'az group delete -g $($resourceGroup) --no-wait'" -ForegroundColor Magenta
Break
}
Expand All @@ -156,14 +172,17 @@ else {
$outputs = (az group deployment show `
--name $timestamp `
--resource-group $resourceGroup `
--query properties.outputs) 2>> $logFile
--query properties.outputs `
--output json) 2>> $logFile

# If it succeeded then we perform the remainder of the steps
if ($outputs)
{
# Log and convert to JSON
$outputs >> $logFile
$outputs = $outputs | ConvertFrom-Json
$outputMap = @{}
$outputs.PSObject.Properties | Foreach-Object { $outputMap[$_.Name] = $_.Value }

# Update appsettings.json
Write-Host "> Updating appsettings.json ..."
Expand All @@ -176,27 +195,24 @@ if ($outputs)

$settings | Add-Member -Type NoteProperty -Force -Name 'microsoftAppId' -Value $appId
$settings | Add-Member -Type NoteProperty -Force -Name 'microsoftAppPassword' -Value $appPassword
if ($outputs.appInsights) { $settings | Add-Member -Type NoteProperty -Force -Name 'appInsights' -Value $outputs.appInsights.value }
if ($outputs.storage) { $settings | Add-Member -Type NoteProperty -Force -Name 'blobStorage' -Value $outputs.storage.value }
if ($outputs.cosmosDb) { $settings | Add-Member -Type NoteProperty -Force -Name 'cosmosDb' -Value $outputs.cosmosDb.value }
if ($outputs.contentModerator) { $settings | Add-Member -Type NoteProperty -Force -Name 'contentModerator' -Value $outputs.contentModerator.value }

foreach ($key in $outputMap.Keys) { $settings | Add-Member -Type NoteProperty -Force -Name $key -Value $outputMap[$key].value }
$settings | ConvertTo-Json -depth 100 | Out-File $(Join-Path $projDir appsettings.json)

if ($outputs.qnaMaker.value.key) { $qnaSubscriptionKey = $outputs.qnaMaker.value.key }
# Delay to let QnA Maker finish setting up
Start-Sleep -s 30

# Deploy cognitive models
Invoke-Expression "$(Join-Path $PSScriptRoot 'deploy_cognitive_models.ps1') -name $($name) -luisAuthoringRegion $($luisAuthoringRegion) -luisAuthoringKey $($luisAuthoringKey) -outFolder $($projDir) -languages `"$($languages)`""
Invoke-Expression "& '$(Join-Path $PSScriptRoot 'deploy_cognitive_models.ps1')' -name $($name) -luisAuthoringRegion $($luisAuthoringRegion) -luisAuthoringKey $($luisAuthoringKey) -luisAccountName $($outputs.luis.value.accountName) -luisAccountRegion $($outputs.luis.value.region) -luisSubscriptionKey $($outputs.luis.value.key) -resourceGroup $($resourceGroup) -qnaSubscriptionKey '$($qnaSubscriptionKey)' -outFolder '$($projDir)' -languages '$($languages)'"

# Publish bot
Write-Host "+ To publish your bot, run '$(Join-Path $PSScriptRoot 'publish.ps1') -name $($name) -resourceGroup $($resourceGroup)'" -ForegroundColor Magenta
Write-Host "+ To publish your bot, run '$(Join-Path $PSScriptRoot 'publish.ps1')' -name $($outputs.botWebAppName.value) -resourceGroup $($resourceGroup) -projFolder '$($projDir)'" -ForegroundColor Magenta
Write-Host "> Done."
}
else
{
# Check for failed deployments
$operations = (az group deployment operation list -g $resourceGroup -n $timestamp) 2>> $logFile | Out-Null
$operations = (az group deployment operation list -g $resourceGroup -n $timestamp --output json) 2>> $logFile | Out-Null

if ($operations) {
$operations = $operations | ConvertFrom-Json
Expand All @@ -206,7 +222,7 @@ else
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
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)."
Expand All @@ -224,4 +240,4 @@ else

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

0 comments on commit c1ac5da

Please sign in to comment.