机器人的ARM模板

时间:2018-04-17 21:26:49

标签: json azure botframework azure-resource-manager

是否有任何ARM模板可用于在新的bot服务下创建机器人?有没有办法从AZURE cli我可以找到Azure门户GUI等效?

2 个答案:

答案 0 :(得分:1)

根据我的测试,我们可以通过ARM模板创建Azure Bot服务机器人。以下模板可以帮助创建一个带有Basic(C#)模板的bot,你可以参考它。

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "botEnv": {
        "type": "string",
        "defaultValue": "prod"
      },
        "botId": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "sku": {
            "type": "string"
        },
        "kind": {
            "type": "string"
        },
        "siteName": {
            "type": "string"
        },
        "createNewStorage": {
            "type": "bool"
        },
        "storageAccountName": {
            "type": "string"
        },
        "storageAccountResourceId": {
            "type": "string",
            "defaultValue": ""
        },
        "appId": {
            "type": "string",
            "defaultValue": "1234"
        },
        "appSecret": {
            "type": "string",
            "defaultValue": "blank"
        },
        "azureWebJobsBotFrameworkDirectLineSecret": {
            "type": "string",
            "defaultValue": ""
        },
        "zipUrl": {
            "type": "string",
            "defaultValue": ""
        },
        "proactiveZipUrl": {
            "type": "string",
            "defaultValue": ""
        },
        "useAppInsights": {
            "type": "bool"
        },
        "appInsightsLocation": {
            "type": "string"
        },
        "serverFarmId": {
            "type": "string"
        },
        "createServerFarm": {
            "type": "bool"
        },
        "serverFarmLocation": {
            "type": "string",
            "defaultValue": ""
        },
        "serverFarmSku": {
            "type": "object",
            "defaultValue": {
                "name": "S1",
                "tier": "Standard",
                "size": "S1",
                "family": "S",
                "capacity": 1
            }
        },
        "endpoint": {
            "type": "string",
            "defaultValue": ""
        },
        "luisApiLocation": {
            "type": "string",
            "defaultValue": "Global"
        }
    },
    "variables": {
        "storageAccountType": "Standard_LRS",
        "storageAccountId": "[if(or(parameters('createNewStorage'), equals('', parameters('storageAccountResourceId'))), resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), parameters('storageAccountResourceId'))]",
        "serverFarmName": "[last(split(parameters('serverFarmId'), '/'))]",
        "myWorkerSize": 0,
        "proactiveFunctionName": "[concat(parameters('siteName'), '-function')]",
        "insightsName": "[concat(parameters('botId'), substring(uniqueString(resourceGroup().id), 0, 6))]",
        "config": {
            "scratch": {
                "stateEndpoint": "https://intercom-api-scratch.azurewebsites.net",
                "azureWebJobsBotFrameworkDirectLineEndpoint": "https://directline.scratch.botframework.com/",
                "blobStoreName": "icscratch",
                "openIdMetadata": "https://intercom-api-ppe.azurewebsites.net/v1/.well-known/openidconfiguration"
            },
            "ppe": {
                "stateEndpoint": "https://intercom-api-ppe.azurewebsites.net",
                "azureWebJobsBotFrameworkDirectLineEndpoint": "https://directline.ppe.botframework.com/",
                "blobStoreName": "intercomppe",
                "openIdMetadata": "https://intercom-api-ppe.azurewebsites.net/v1/.well-known/openidconfiguration"
            },
            "prod": {
                "stateEndpoint": "",
                "azureWebJobsBotFrameworkDirectLineEndpoint": "https://directline.botframework.com/",
                "blobStoreName": "connectorprod",
                "openIdMetadata": ""
            }
        },
        "botAppKinds": {
            "function": "functionapp",
            "sdk": "app",
            "designer": "app",
            "bot": ""
        },
        "botAppKind": "[variables('botAppKinds')[parameters('kind')]]",
        "currentConfig": "[variables('config')[toLower(parameters('botEnv'))]]",
        "siteHost": "[concat(parameters('siteName'), '.azurewebsites.net')]",
        "botEndpointConfig": {
            "bot": "[parameters('endpoint')]",
            "sdk": "[concat('https://', variables('siteHost'), '/api/messages')]",
            "designer": "[concat('https://', variables('siteHost'), '/api/messages')]",
            "function": "[concat('https://', variables('siteHost'), '/api/messages?code=', 'NYI')]"
        },
        "botEndpoint": "[variables('botEndpointConfig')[parameters('kind')]]",
        "luisApiName": "",
        "luisApiResId": "[resourceId('Microsoft.CognitiveServices/accounts/', variables('luisApiName'))]"
    },
    "resources": [
        {
            "name": "[if(equals('', variables('luisApiName')), 'nosuch', variables('luisApiName'))]",
            "apiVersion": "2017-04-18",
            "condition": "[not(equals(variables('luisApiName'), ''))]",
            "type": "Microsoft.CognitiveServices/accounts",
            "location": "[parameters('luisApiLocation')]",
            "sku": {
                "name": "F0"
            },
            "kind": "LUIS",
            "properties": {}
        },
        {
            "type": "Microsoft.Storage/storageAccounts",
            "condition": "[parameters('createNewStorage')]",
            "name": "[parameters('storageAccountName')]",
            "apiVersion": "2015-05-01-preview",
            "location": "[parameters('location')]",
            "properties": {
                "accountType": "[variables('storageAccountType')]"
            }
        },
        {
            "type": "Microsoft.Web/serverfarms",
            "condition": "[parameters('createServerFarm')]",
            "name": "[variables('serverFarmName')]",
            "apiVersion": "2016-09-01",
            "location": "[parameters('serverFarmLocation')]",
            "sku": "[parameters('serverFarmSku')]",
            "properties": {
                "name": "[variables('serverFarmName')]"
            }
        },
        {
            "name": "[variables('insightsName')]",
            "type": "microsoft.insights/components",
            "kind": "web",
            "apiVersion": "2014-04-01",
            "condition": "[parameters('useAppInsights')]",
            "location": "[parameters('appInsightsLocation')]",
            "tags": {
                "[concat('hidden-link:', resourceId('Microsoft.BotService/botServices/', parameters('botId')))]": "Resource",
                "[concat('hidden-link:', resourceId('Microsoft.Web/sites/', parameters('siteName')))]": "Resource"
            },
            "properties": {
                "ApplicationId": "[parameters('botId')]"
            }
        },
        {
            "name": "[parameters('siteName')]",
            "type": "Microsoft.Web/sites",
            "apiVersion": "2015-08-01",
            "condition": "[not(equals(parameters('zipUrl'), ''))]",
            "location": "[parameters('location')]",
            "kind": "[variables('botAppKind')]",
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
            ],
            "properties": {
                "name": "[parameters('siteName')]",
                "serverFarmId": "[parameters('serverFarmId')]",
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listkeys(variables('storageAccountId'), '2015-05-01-preview').key1,';')]"
                        },
                        {
                            "name": "AzureWebJobsDashboard",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listkeys(variables('storageAccountId'), '2015-05-01-preview').key1,';')]"
                        },
                        {
                            "name": "WEBSITE_NODE_DEFAULT_VERSION",
                            "value": "6.9.1"
                        },
                        {
                            "name": "BotEnv",
                            "value": "[parameters('botEnv')]"
                        },
                        {
                            "name": "BotId",
                            "value": "[parameters('botId')]"
                        },
                        {
                            "name": "MicrosoftAppId",
                            "value": "[parameters('appId')]"
                        },
                        {
                            "name": "MicrosoftAppPassword",
                            "value": "[parameters('appSecret')]"
                        },
                        {
                            "name": "BotStateEndpoint",
                            "value": "[variables('currentConfig').stateEndpoint]"
                        },
                        {
                            "name": "BotOpenIdMetadata",
                            "value": "[variables('currentConfig').openIdMetadata]"
                        },
                        {
                            "name": "UseTableStorageForConversationState",
                            "value": "true"
                        }
                    ],
                    "cors": {
                        "allowedOrigins": [
                            "https://botservice.hosting.portal.azure.net",
                            "https://hosting.onecloud.azure-test.net/"
                        ]
                    }
                }
            },
            "resources": [
                {
                    "name": "MSDeploy",
                    "type": "Extensions",
                    "apiVersion": "2015-02-01",
                    "condition": "[not(equals(parameters('zipUrl'), ''))]",
                    "dependsOn": [
                        "[concat('Microsoft.Web/Sites/', parameters('siteName'))]"
                    ],
                    "properties": {
                        "packageUri": "[parameters('zipUrl')]",
                        "dbType": "None",
                        "connectionString": "",
                        "setParameters": {
                            "IIS Web Application Name": "[parameters('siteName')]"
                        }
                    }
                }
            ]
        },
        {
            "apiVersion": "2016-03-01",
            "type": "Microsoft.Web/sites",
            "condition": "[not(equals(parameters('proactiveZipUrl'), ''))]",
            "name": "[variables('proactiveFunctionName')]",
            "location": "[parameters('location')]",
            "kind": "functionapp",
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
            ],
            "properties": {
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "AzureWebJobsDashboard",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listkeys(variables('storageAccountId'), '2015-05-01-preview').key1,';')]"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listkeys(variables('storageAccountId'), '2015-05-01-preview').key1,';')]"
                        },
                        {
                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listkeys(variables('storageAccountId'), '2015-05-01-preview').key1,';')]"
                        },
                        {
                            "name": "WEBSITE_CONTENTSHARE",
                            "value": "[toLower(variables('proactiveFunctionName'))]"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~1"
                        },
                        {
                            "name": "AzureWebJobsBotFrameworkDirectLineSecret",
                            "value": "[parameters('azureWebJobsBotFrameworkDirectLineSecret')]"
                        },
                        {
                            "name": "AzureWebJobsBotFrameworkDirectLineEndpoint",
                            "value": "[variables('currentConfig').azureWebJobsBotFrameworkDirectLineEndpoint]"
                        }
                    ]
                }
            },
            "resources": [
                {
                    "name": "MSDeploy",
                    "type": "Extensions",
                    "apiVersion": "2015-02-01",
                    "condition": "[not(equals(parameters('proactiveZipUrl'), ''))]",
                    "dependsOn": [
                        "[concat('Microsoft.Web/Sites/', variables('proactiveFunctionName'))]"
                    ],
                    "properties": {
                        "packageUri": "[parameters('proactiveZipUrl')]"
                    }
                }
            ]
        },
        {
            "apiVersion": "2017-12-01",
            "type": "Microsoft.BotService/botServices",
            "name": "[parameters('botId')]",
            "location": "global",
            "kind": "[parameters('kind')]",
            "sku": {
                "name": "[parameters('sku')]"
            },
            "properties": {
                "name": "[parameters('botId')]",
                "displayName": "[parameters('botId')]",
                "endpoint": "[variables('botEndpoint')]",
                "msaAppId": "[parameters('appId')]"
            },
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
                "[resourceId('Microsoft.Web/sites/', parameters('siteName'))]"
            ]
        }
    ]
}

<强>参数:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
  "parameters": {
    "zipUrl": {
      "value": "https://connectorprod.blob.core.windows.net/bot-packages/csharp-abs-webapp_simpleechobot_precompiled.zip"
    },
    "botId": {
      "value": "xxxxxtestchatbot"
    },
    "location": {
      "value": "West US"
    },
    "kind": {
      "value": "sdk"
    },
    "sku": {
      "value": "F0"
    },
    "siteName": {
      "value": "xxxxxtestchatbot"
    },
    "appId": {
      "value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    },
    "appSecret": {
      "value": "xxxxxxxxxxxxxxxx"
    },
    "createNewStorage": {
      "value": true
    },
    "storageAccountName": {
      "value": "xxxxxtestchatbotad0f"
    },
    "storageAccountResourceId": {
      "value": ""
    },
    "botEnv": {
      "value": "prod"
    },
    "useAppInsights": {
      "value": false
    },
    "appInsightsLocation": {
      "value": "East US"
    },
    "createServerFarm": {
      "value": false
    },
    "serverFarmId": {
      "value": "/subscriptions/{subscription_id}/resourceGroups/{rescouce_group_name}/providers/Microsoft.Web/serverfarms/{app_serviceplan_name}"
    },
    "serverFarmLocation": {
      "value": "West US"
    },
    "azureWebJobsBotFrameworkDirectLineSecret": {
      "value": ""
    }
  }
}

注意:要快速获取部署BotService的模板,您可以转到Azure门户创建新的Bot服务并单击自动化选项,然后下载模板。

enter image description here

答案 1 :(得分:0)

即使无法从资源组中导出模板,模板的部署(也称为导入)会接受Bot名称空间并正确创建Bot (已经过测试)。

也有对命名空间的正式引用:https://docs.microsoft.com/en-us/azure/templates/microsoft.botservice/2017-12-01/botservices

以及相同的官方样品:https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/02.echo-bot/DeploymentTemplates