skype chat bot init
This commit is contained in:
commit
f17a1b4144
|
|
@ -0,0 +1,3 @@
|
|||
node_modules
|
||||
lib
|
||||
.env
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
# my-chat-bot
|
||||
|
||||
Demonstrate the core capabilities of the Microsoft Bot Framework
|
||||
|
||||
This bot has been created using [Bot Framework](https://dev.botframework.com), it shows how to create a simple bot that accepts input from the user and echoes it back.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- [Node.js](https://nodejs.org) version 10.14.1 or higher
|
||||
|
||||
```bash
|
||||
# determine node version
|
||||
node --version
|
||||
```
|
||||
|
||||
## To run the bot
|
||||
|
||||
- Install modules
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
- Start the bot
|
||||
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
## Testing the bot using Bot Framework Emulator
|
||||
|
||||
[Bot Framework Emulator](https://github.com/microsoft/botframework-emulator) is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.
|
||||
|
||||
- Install the Bot Framework Emulator version 4.9.0 or greater from [here](https://github.com/Microsoft/BotFramework-Emulator/releases)
|
||||
|
||||
### Connect to the bot using Bot Framework Emulator
|
||||
|
||||
- Launch Bot Framework Emulator
|
||||
- File -> Open Bot
|
||||
- Enter a Bot URL of `http://localhost:3978/api/messages`
|
||||
|
||||
## Deploy the bot to Azure
|
||||
|
||||
### Publishing Changes to Azure Bot Service
|
||||
|
||||
```bash
|
||||
# build the TypeScript bot before you publish
|
||||
npm run build
|
||||
```
|
||||
|
||||
To learn more about deploying a bot to Azure, see [Deploy your bot to Azure](https://aka.ms/azuredeployment) for a complete list of deployment instructions.
|
||||
|
||||
## Further reading
|
||||
|
||||
- [Bot Framework Documentation](https://docs.botframework.com)
|
||||
- [Bot Basics](https://docs.microsoft.com/azure/bot-service/bot-builder-basics?view=azure-bot-service-4.0)
|
||||
- [Dialogs](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-dialog?view=azure-bot-service-4.0)
|
||||
- [Gathering Input Using Prompts](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-prompts?view=azure-bot-service-4.0)
|
||||
- [Activity processing](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-activity-processing?view=azure-bot-service-4.0)
|
||||
- [Azure Bot Service Introduction](https://docs.microsoft.com/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0)
|
||||
- [Azure Bot Service Documentation](https://docs.microsoft.com/azure/bot-service/?view=azure-bot-service-4.0)
|
||||
- [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest)
|
||||
- [Azure Portal](https://portal.azure.com)
|
||||
- [Language Understanding using LUIS](https://docs.microsoft.com/en-us/azure/cognitive-services/luis/)
|
||||
- [Channels and Bot Connector Service](https://docs.microsoft.com/en-us/azure/bot-service/bot-concepts?view=azure-bot-service-4.0)
|
||||
- [TypeScript](https://www.typescriptlang.org)
|
||||
- [Restify](https://www.npmjs.com/package/restify)
|
||||
- [dotenv](https://www.npmjs.com/package/dotenv)
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// DO NOT MODIFY THIS CODE
|
||||
// This script is run as part of the Post Deploy step when
|
||||
// deploying the bot to Azure. It ensures the Azure Web App
|
||||
// is configured correctly to host a TypeScript authored bot.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const replace = require('replace');
|
||||
const WEB_CONFIG_FILE = './web.config';
|
||||
|
||||
if (fs.existsSync(path.resolve(WEB_CONFIG_FILE))) {
|
||||
replace({
|
||||
regex: "url=\"index.js\"",
|
||||
replacement: "url=\"lib/index.js\"",
|
||||
paths: ['./web.config'],
|
||||
recursive: false,
|
||||
silent: true,
|
||||
})
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {
|
||||
"azureBotId": {
|
||||
"value": ""
|
||||
},
|
||||
"azureBotSku": {
|
||||
"value": "S1"
|
||||
},
|
||||
"azureBotRegion": {
|
||||
"value": "global"
|
||||
},
|
||||
"botEndpoint": {
|
||||
"value": ""
|
||||
},
|
||||
"appType": {
|
||||
"value": "MultiTenant"
|
||||
},
|
||||
"appId": {
|
||||
"value": ""
|
||||
},
|
||||
"UMSIName": {
|
||||
"value": ""
|
||||
},
|
||||
"UMSIResourceGroupName": {
|
||||
"value": ""
|
||||
},
|
||||
"tenantId": {
|
||||
"value": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {
|
||||
"appServiceName": {
|
||||
"value": ""
|
||||
},
|
||||
"existingAppServicePlanName": {
|
||||
"value": ""
|
||||
},
|
||||
"existingAppServicePlanLocation": {
|
||||
"value": ""
|
||||
},
|
||||
"newAppServicePlanName": {
|
||||
"value": ""
|
||||
},
|
||||
"newAppServicePlanLocation": {
|
||||
"value": ""
|
||||
},
|
||||
"newAppServicePlanSku": {
|
||||
"value": {
|
||||
"name": "S1",
|
||||
"tier": "Standard",
|
||||
"size": "S1",
|
||||
"family": "S",
|
||||
"capacity": 1
|
||||
}
|
||||
},
|
||||
"appType": {
|
||||
"value": "MultiTenant"
|
||||
},
|
||||
"appId": {
|
||||
"value": ""
|
||||
},
|
||||
"appSecret": {
|
||||
"value": ""
|
||||
},
|
||||
"UMSIName": {
|
||||
"value": ""
|
||||
},
|
||||
"UMSIResourceGroupName": {
|
||||
"value": ""
|
||||
},
|
||||
"tenantId": {
|
||||
"value": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
# Usage
|
||||
The BotApp must be deployed prior to AzureBot.
|
||||
|
||||
Command line:
|
||||
- az login
|
||||
- az deployment group create --resource-group <group-name> --template-file <template-file> --parameters @<parameters-file>
|
||||
|
||||
# parameters-for-template-BotApp-with-rg:
|
||||
|
||||
- **appServiceName**:(required) The Name of the Bot App Service.
|
||||
|
||||
- (choose an existingAppServicePlan or create a new AppServicePlan)
|
||||
- **existingAppServicePlanName**: The name of the App Service Plan.
|
||||
- **existingAppServicePlanLocation**: The location of the App Service Plan.
|
||||
- **newAppServicePlanName**: The name of the App Service Plan.
|
||||
- **newAppServicePlanLocation**: The location of the App Service Plan.
|
||||
- **newAppServicePlanSku**: The SKU of the App Service Plan. Defaults to Standard values.
|
||||
|
||||
- **appType**: Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. **Allowed values are: MultiTenant(default), SingleTenant, UserAssignedMSI.**
|
||||
|
||||
- **appId**:(required) Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings.
|
||||
|
||||
- **appSecret**:(required for MultiTenant and SingleTenant) Active Directory App Password, set as MicrosoftAppPassword in the Web App's Application Settings.
|
||||
|
||||
- **UMSIName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource used for the Bot's Authentication.
|
||||
|
||||
- **UMSIResourceGroupName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource Group used for the Bot's Authentication.
|
||||
|
||||
- **tenantId**: The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to <Subscription Tenant ID>.
|
||||
|
||||
MoreInfo: https://docs.microsoft.com/en-us/azure/bot-service/tutorial-provision-a-bot?view=azure-bot-service-4.0&tabs=userassigned%2Cnewgroup#create-an-identity-resource
|
||||
|
||||
|
||||
|
||||
# parameters-for-template-AzureBot-with-rg:
|
||||
|
||||
- **azureBotId**:(required) The globally unique and immutable bot ID.
|
||||
- **azureBotSku**: The pricing tier of the Bot Service Registration. **Allowed values are: F0, S1(default)**.
|
||||
- **azureBotRegion**: Specifies the location of the new AzureBot. **Allowed values are: global(default), westeurope**.
|
||||
- **botEndpoint**: Use to handle client messages, Such as https://<botappServiceName>.azurewebsites.net/api/messages.
|
||||
|
||||
- **appType**: Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. **Allowed values are: MultiTenant(default), SingleTenant, UserAssignedMSI.**
|
||||
- **appId**:(required) Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings.
|
||||
- **UMSIName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource used for the Bot's Authentication.
|
||||
- **UMSIResourceGroupName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource Group used for the Bot's Authentication.
|
||||
- **tenantId**: The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to <Subscription Tenant ID>.
|
||||
|
||||
MoreInfo: https://docs.microsoft.com/en-us/azure/bot-service/tutorial-provision-a-bot?view=azure-bot-service-4.0&tabs=userassigned%2Cnewgroup#create-an-identity-resource
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
{
|
||||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {
|
||||
"azureBotId": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The globally unique and immutable bot ID."
|
||||
}
|
||||
},
|
||||
"azureBotSku": {
|
||||
"defaultValue": "S1",
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The pricing tier of the Bot Service Registration. Allowed values are: F0, S1(default)."
|
||||
}
|
||||
},
|
||||
"azureBotRegion": {
|
||||
"type": "string",
|
||||
"defaultValue": "global",
|
||||
"metadata": {
|
||||
"description": "Specifies the location of the new AzureBot. Allowed values are: global(default), westeurope."
|
||||
}
|
||||
},
|
||||
"botEndpoint": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Use to handle client messages, Such as https://<botappServiceName>.azurewebsites.net/api/messages."
|
||||
}
|
||||
},
|
||||
"appType": {
|
||||
"type": "string",
|
||||
"defaultValue": "MultiTenant",
|
||||
"allowedValues": [
|
||||
"MultiTenant",
|
||||
"SingleTenant",
|
||||
"UserAssignedMSI"
|
||||
],
|
||||
"metadata": {
|
||||
"description": "Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. Allowed values are: MultiTenant, SingleTenant, UserAssignedMSI. Defaults to \"MultiTenant\"."
|
||||
}
|
||||
},
|
||||
"appId": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings."
|
||||
}
|
||||
},
|
||||
"UMSIName": {
|
||||
"type": "string",
|
||||
"defaultValue": "",
|
||||
"metadata": {
|
||||
"description": "The User-Assigned Managed Identity Resource used for the Bot's Authentication."
|
||||
}
|
||||
},
|
||||
"UMSIResourceGroupName": {
|
||||
"type": "string",
|
||||
"defaultValue": "",
|
||||
"metadata": {
|
||||
"description": "The User-Assigned Managed Identity Resource Group used for the Bot's Authentication."
|
||||
}
|
||||
},
|
||||
"tenantId": {
|
||||
"type": "string",
|
||||
"defaultValue": "[subscription().tenantId]",
|
||||
"metadata": {
|
||||
"description": "The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to \"Subscription Tenant ID\"."
|
||||
}
|
||||
}
|
||||
},
|
||||
"variables": {
|
||||
"tenantId": "[if(empty(parameters('tenantId')), subscription().tenantId, parameters('tenantId'))]",
|
||||
"msiResourceId": "[concat(subscription().id, '/resourceGroups/', parameters('UMSIResourceGroupName'), '/providers/', 'Microsoft.ManagedIdentity/userAssignedIdentities/', parameters('UMSIName'))]",
|
||||
"appTypeDef": {
|
||||
"MultiTenant": {
|
||||
"tenantId": "",
|
||||
"msiResourceId": ""
|
||||
},
|
||||
"SingleTenant": {
|
||||
"tenantId": "[variables('tenantId')]",
|
||||
"msiResourceId": ""
|
||||
},
|
||||
"UserAssignedMSI": {
|
||||
"tenantId": "[variables('tenantId')]",
|
||||
"msiResourceId": "[variables('msiResourceId')]"
|
||||
}
|
||||
},
|
||||
"appType": {
|
||||
"tenantId": "[variables('appTypeDef')[parameters('appType')].tenantId]",
|
||||
"msiResourceId": "[variables('appTypeDef')[parameters('appType')].msiResourceId]"
|
||||
}
|
||||
},
|
||||
"resources": [
|
||||
{
|
||||
"apiVersion": "2021-05-01-preview",
|
||||
"type": "Microsoft.BotService/botServices",
|
||||
"name": "[parameters('azureBotId')]",
|
||||
"location": "[parameters('azureBotRegion')]",
|
||||
"kind": "azurebot",
|
||||
"sku": {
|
||||
"name": "[parameters('azureBotSku')]"
|
||||
},
|
||||
"properties": {
|
||||
"displayName": "[parameters('azureBotId')]",
|
||||
"iconUrl": "https://docs.botframework.com/static/devportal/client/images/bot-framework-default.png",
|
||||
"endpoint": "[parameters('botEndpoint')]",
|
||||
"msaAppId": "[parameters('appId')]",
|
||||
"msaAppTenantId": "[variables('appType').tenantId]",
|
||||
"msaAppMSIResourceId": "[variables('appType').msiResourceId]",
|
||||
"msaAppType": "[parameters('appType')]",
|
||||
"luisAppIds": [],
|
||||
"schemaTransformationVersion": "1.3",
|
||||
"isCmekEnabled": false,
|
||||
"isIsolated": false
|
||||
},
|
||||
"dependsOn": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
{
|
||||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {
|
||||
"appServiceName": {
|
||||
"type": "string",
|
||||
"defaultValue": "",
|
||||
"metadata": {
|
||||
"description": "The globally unique name of the Web App."
|
||||
}
|
||||
},
|
||||
"existingAppServicePlanName": {
|
||||
"type": "string",
|
||||
"defaultValue": "",
|
||||
"metadata": {
|
||||
"description": "Name of the existing App Service Plan used to create the Web App for the bot."
|
||||
}
|
||||
},
|
||||
"existingAppServicePlanLocation": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The location of the App Service Plan."
|
||||
}
|
||||
},
|
||||
"newAppServicePlanName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The name of the new App Service Plan."
|
||||
}
|
||||
},
|
||||
"newAppServicePlanLocation": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The location of the App Service Plan."
|
||||
}
|
||||
},
|
||||
"newAppServicePlanSku": {
|
||||
"type": "object",
|
||||
"defaultValue": {
|
||||
"name": "S1",
|
||||
"tier": "Standard",
|
||||
"size": "S1",
|
||||
"family": "S",
|
||||
"capacity": 1
|
||||
},
|
||||
"metadata": {
|
||||
"description": "The SKU of the App Service Plan. Defaults to Standard values."
|
||||
}
|
||||
},
|
||||
"appType": {
|
||||
"type": "string",
|
||||
"defaultValue": "MultiTenant",
|
||||
"allowedValues": [
|
||||
"MultiTenant",
|
||||
"SingleTenant",
|
||||
"UserAssignedMSI"
|
||||
],
|
||||
"metadata": {
|
||||
"description": "Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. Allowed values are: MultiTenant, SingleTenant, UserAssignedMSI. Defaults to \"MultiTenant\"."
|
||||
}
|
||||
},
|
||||
"appId": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings."
|
||||
}
|
||||
},
|
||||
"appSecret": {
|
||||
"type": "string",
|
||||
"defaultValue": "",
|
||||
"metadata": {
|
||||
"description": "Active Directory App Password, set as MicrosoftAppPassword in the Web App's Application Settings. Required for MultiTenant and SingleTenant app types. Defaults to \"\"."
|
||||
}
|
||||
},
|
||||
"UMSIName": {
|
||||
"type": "string",
|
||||
"defaultValue": "",
|
||||
"metadata": {
|
||||
"description": "The User-Assigned Managed Identity Resource used for the Bot's Authentication. Defaults to \"\"."
|
||||
}
|
||||
},
|
||||
"UMSIResourceGroupName": {
|
||||
"type": "string",
|
||||
"defaultValue": "",
|
||||
"metadata": {
|
||||
"description": "The User-Assigned Managed Identity Resource Group used for the Bot's Authentication. Defaults to \"\"."
|
||||
}
|
||||
},
|
||||
"tenantId": {
|
||||
"type": "string",
|
||||
"defaultValue": "[subscription().tenantId]",
|
||||
"metadata": {
|
||||
"description": "The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to \"Subscription Tenant ID\"."
|
||||
}
|
||||
}
|
||||
},
|
||||
"variables": {
|
||||
"tenantId": "[if(empty(parameters('tenantId')), subscription().tenantId, parameters('tenantId'))]",
|
||||
"defaultAppServicePlanName": "[if(empty(parameters('existingAppServicePlanName')), 'createNewAppServicePlan', parameters('existingAppServicePlanName'))]",
|
||||
"useExistingServicePlan": "[not(equals(variables('defaultAppServicePlanName'), 'createNewAppServicePlan'))]",
|
||||
"servicePlanName": "[if(variables('useExistingServicePlan'), parameters('existingAppServicePlanName'), parameters('newAppServicePlanName'))]",
|
||||
"servicePlanLocation": "[if(variables('useExistingServicePlan'), parameters('existingAppServicePlanLocation'), parameters('newAppServicePlanLocation'))]",
|
||||
"msiResourceId": "[concat(subscription().id, '/resourceGroups/', parameters('UMSIResourceGroupName'), '/providers/', 'Microsoft.ManagedIdentity/userAssignedIdentities/', parameters('UMSIName'))]",
|
||||
"appTypeDef": {
|
||||
"MultiTenant": {
|
||||
"tenantId": "",
|
||||
"identity": { "type": "None" }
|
||||
},
|
||||
"SingleTenant": {
|
||||
"tenantId": "[variables('tenantId')]",
|
||||
"identity": { "type": "None" }
|
||||
},
|
||||
"UserAssignedMSI": {
|
||||
"tenantId": "[variables('tenantId')]",
|
||||
"identity": {
|
||||
"type": "UserAssigned",
|
||||
"userAssignedIdentities": {
|
||||
"[variables('msiResourceId')]": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"appType": {
|
||||
"tenantId": "[variables('appTypeDef')[parameters('appType')].tenantId]",
|
||||
"identity": "[variables('appTypeDef')[parameters('appType')].identity]"
|
||||
}
|
||||
},
|
||||
"resources": [
|
||||
{
|
||||
"comments": "Create a new App Service Plan if no existing App Service Plan name was passed in.",
|
||||
"type": "Microsoft.Web/serverfarms",
|
||||
"condition": "[not(variables('useExistingServicePlan'))]",
|
||||
"name": "[variables('servicePlanName')]",
|
||||
"apiVersion": "2018-02-01",
|
||||
"location": "[parameters('newAppServicePlanLocation')]",
|
||||
"sku": "[parameters('newAppServicePlanSku')]",
|
||||
"properties": {
|
||||
"name": "[variables('servicePlanName')]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"comments": "Create a Web App using an App Service Plan",
|
||||
"type": "Microsoft.Web/sites",
|
||||
"apiVersion": "2015-08-01",
|
||||
"location": "[variables('servicePlanLocation')]",
|
||||
"kind": "app",
|
||||
"dependsOn": [
|
||||
"[resourceId('Microsoft.Web/serverfarms', variables('servicePlanName'))]"
|
||||
],
|
||||
"name": "[parameters('appServiceName')]",
|
||||
"identity": "[variables('appType').identity]",
|
||||
"properties": {
|
||||
"name": "[parameters('appServiceName')]",
|
||||
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('servicePlanName'))]",
|
||||
"siteConfig": {
|
||||
"appSettings": [
|
||||
{
|
||||
"name": "WEBSITE_NODE_DEFAULT_VERSION",
|
||||
"value": "10.14.1"
|
||||
},
|
||||
{
|
||||
"name": "MicrosoftAppType",
|
||||
"value": "[parameters('appType')]"
|
||||
},
|
||||
{
|
||||
"name": "MicrosoftAppId",
|
||||
"value": "[parameters('appId')]"
|
||||
},
|
||||
{
|
||||
"name": "MicrosoftAppPassword",
|
||||
"value": "[parameters('appSecret')]"
|
||||
},
|
||||
{
|
||||
"name": "MicrosoftAppTenantId",
|
||||
"value": "[variables('appType').tenantId]"
|
||||
}
|
||||
],
|
||||
"cors": {
|
||||
"allowedOrigins": [
|
||||
"https://botservice.hosting.portal.azure.net",
|
||||
"https://hosting.onecloud.azure-test.net/"
|
||||
]
|
||||
},
|
||||
"webSocketsEnabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {
|
||||
"groupName": {
|
||||
"value": ""
|
||||
},
|
||||
"groupLocation": {
|
||||
"value": ""
|
||||
},
|
||||
"azureBotId": {
|
||||
"value": ""
|
||||
},
|
||||
"azureBotSku": {
|
||||
"value": "S1"
|
||||
},
|
||||
"azureBotRegion": {
|
||||
"value": "global"
|
||||
},
|
||||
"botEndpoint": {
|
||||
"value": ""
|
||||
},
|
||||
"appType": {
|
||||
"value": "MultiTenant"
|
||||
},
|
||||
"appId": {
|
||||
"value": ""
|
||||
},
|
||||
"UMSIName": {
|
||||
"value": ""
|
||||
},
|
||||
"UMSIResourceGroupName": {
|
||||
"value": ""
|
||||
},
|
||||
"tenantId": {
|
||||
"value": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {
|
||||
"groupName": {
|
||||
"value": ""
|
||||
},
|
||||
"groupLocation": {
|
||||
"value": ""
|
||||
},
|
||||
"appServiceName": {
|
||||
"value": ""
|
||||
},
|
||||
"appServicePlanName": {
|
||||
"value": ""
|
||||
},
|
||||
"appServicePlanLocation": {
|
||||
"value": ""
|
||||
},
|
||||
"appServicePlanSku": {
|
||||
"value": {
|
||||
"name": "S1",
|
||||
"tier": "Standard",
|
||||
"size": "S1",
|
||||
"family": "S",
|
||||
"capacity": 1
|
||||
}
|
||||
},
|
||||
"appType": {
|
||||
"value": "MultiTenant"
|
||||
},
|
||||
"appId": {
|
||||
"value": ""
|
||||
},
|
||||
"appSecret": {
|
||||
"value": ""
|
||||
},
|
||||
"UMSIName": {
|
||||
"value": ""
|
||||
},
|
||||
"UMSIResourceGroupName": {
|
||||
"value": ""
|
||||
},
|
||||
"tenantId": {
|
||||
"value": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
# Usage
|
||||
The BotApp must be deployed prior to AzureBot.
|
||||
|
||||
Command line:
|
||||
- az login
|
||||
- az deployment sub create --template-file <template-file> --location <bot-region> --parameters @<parameters-file>
|
||||
|
||||
# parameters-for-template-BotApp-new-rg:
|
||||
|
||||
- **groupName**:(required) Specifies the name of the new Resource Group.
|
||||
- **groupLocation**:(required) Specifies the location of the new Resource Group.
|
||||
|
||||
- **appServiceName**:(required) The location of the App Service Plan.
|
||||
- **appServicePlanName**:(required) The name of the App Service Plan.
|
||||
- **appServicePlanLocation**: The location of the App Service Plan. Defaults to use groupLocation.
|
||||
- **appServicePlanSku**: The SKU of the App Service Plan. Defaults to Standard values.
|
||||
|
||||
- **appType**: Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. **Allowed values are: MultiTenant(default), SingleTenant, UserAssignedMSI.**
|
||||
- **appId**:(required) Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings.
|
||||
- **appSecret**:(required for MultiTenant and SingleTenant) Active Directory App Password, set as MicrosoftAppPassword in the Web App's Application Settings.
|
||||
- **UMSIName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource used for the Bot's Authentication.
|
||||
- **UMSIResourceGroupName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource Group used for the Bot's Authentication.
|
||||
- **tenantId**: The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to <Subscription Tenant ID>.
|
||||
|
||||
MoreInfo: https://docs.microsoft.com/en-us/azure/bot-service/tutorial-provision-a-bot?view=azure-bot-service-4.0&tabs=userassigned%2Cnewgroup#create-an-identity-resource
|
||||
|
||||
|
||||
|
||||
# parameters-for-template-AzureBot-new-rg:
|
||||
|
||||
- **groupName**:(required) Specifies the name of the new Resource Group.
|
||||
- **groupLocation**:(required) Specifies the location of the new Resource Group.
|
||||
|
||||
- **azureBotId**:(required) The globally unique and immutable bot ID. Also used to configure the displayName of the bot, which is mutable.
|
||||
- **azureBotSku**: The pricing tier of the Bot Service Registration. **Allowed values are: F0, S1(default)**.
|
||||
- **azureBotRegion**: Specifies the location of the new AzureBot. **Allowed values are: global(default), westeurope**.
|
||||
- **botEndpoint**: Use to handle client messages, Such as https://<botappServiceName>.azurewebsites.net/api/messages.
|
||||
|
||||
- **appType**: Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. **Allowed values are: MultiTenant(default), SingleTenant, UserAssignedMSI.**
|
||||
- **appId**:(required) Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings.
|
||||
- **UMSIName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource used for the Bot's Authentication.
|
||||
- **UMSIResourceGroupName**:(required for UserAssignedMSI) The User-Assigned Managed Identity Resource Group used for the Bot's Authentication.
|
||||
- **tenantId**: The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to <Subscription Tenant ID>.
|
||||
|
||||
MoreInfo: https://docs.microsoft.com/en-us/azure/bot-service/tutorial-provision-a-bot?view=azure-bot-service-4.0&tabs=userassigned%2Cnewgroup#create-an-identity-resource
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
{
|
||||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {
|
||||
"groupName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Specifies the name of the Resource Group."
|
||||
}
|
||||
},
|
||||
"groupLocation": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Specifies the location of the Resource Group."
|
||||
}
|
||||
},
|
||||
"azureBotId": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The globally unique and immutable bot ID."
|
||||
}
|
||||
},
|
||||
"azureBotSku": {
|
||||
"type": "string",
|
||||
"defaultValue": "S1",
|
||||
"metadata": {
|
||||
"description": "The pricing tier of the Bot Service Registration. Acceptable values are F0 and S1."
|
||||
}
|
||||
},
|
||||
"azureBotRegion": {
|
||||
"type": "string",
|
||||
"defaultValue": "global",
|
||||
"metadata": {
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
"botEndpoint": {
|
||||
"type": "string",
|
||||
"defaultValue": "",
|
||||
"metadata": {
|
||||
"description": "Use to handle client messages, Such as https://<botappServiceName>.azurewebsites.net/api/messages."
|
||||
}
|
||||
},
|
||||
"appType": {
|
||||
"type": "string",
|
||||
"defaultValue": "MultiTenant",
|
||||
"allowedValues": [
|
||||
"MultiTenant",
|
||||
"SingleTenant",
|
||||
"UserAssignedMSI"
|
||||
],
|
||||
"metadata": {
|
||||
"description": "Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. Allowed values are: MultiTenant, SingleTenant, UserAssignedMSI. Defaults to \"MultiTenant\"."
|
||||
}
|
||||
},
|
||||
"appId": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings."
|
||||
}
|
||||
},
|
||||
"tenantId": {
|
||||
"type": "string",
|
||||
"defaultValue": "[subscription().tenantId]",
|
||||
"metadata": {
|
||||
"description": "The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to \"Subscription Tenant ID\"."
|
||||
}
|
||||
},
|
||||
"UMSIName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The User-Assigned Managed Identity Resource used for the Bot's Authentication."
|
||||
}
|
||||
},
|
||||
"UMSIResourceGroupName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The User-Assigned Managed Identity Resource Group used for the Bot's Authentication."
|
||||
}
|
||||
}
|
||||
},
|
||||
"variables": {
|
||||
"tenantId": "[if(empty(parameters('tenantId')), subscription().tenantId, parameters('tenantId'))]",
|
||||
"msiResourceId": "[concat(subscription().id, '/resourceGroups/', parameters('UMSIResourceGroupName'), '/providers/', 'Microsoft.ManagedIdentity/userAssignedIdentities/', parameters('UMSIName'))]",
|
||||
"appTypeDef": {
|
||||
"MultiTenant": {
|
||||
"tenantId": "",
|
||||
"msiResourceId": ""
|
||||
},
|
||||
"SingleTenant": {
|
||||
"tenantId": "[variables('tenantId')]",
|
||||
"msiResourceId": ""
|
||||
},
|
||||
"UserAssignedMSI": {
|
||||
"tenantId": "[variables('tenantId')]",
|
||||
"msiResourceId": "[variables('msiResourceId')]"
|
||||
}
|
||||
},
|
||||
"appType": {
|
||||
"tenantId": "[variables('appTypeDef')[parameters('appType')].tenantId]",
|
||||
"msiResourceId": "[variables('appTypeDef')[parameters('appType')].msiResourceId]"
|
||||
}
|
||||
},
|
||||
"resources": [
|
||||
{
|
||||
"name": "[parameters('groupName')]",
|
||||
"type": "Microsoft.Resources/resourceGroups",
|
||||
"apiVersion": "2018-05-01",
|
||||
"location": "[parameters('groupLocation')]",
|
||||
"properties": {}
|
||||
},
|
||||
{
|
||||
"type": "Microsoft.Resources/deployments",
|
||||
"apiVersion": "2018-05-01",
|
||||
"name": "storageDeployment",
|
||||
"resourceGroup": "[parameters('groupName')]",
|
||||
"dependsOn": [
|
||||
"[resourceId('Microsoft.Resources/resourceGroups/', parameters('groupName'))]"
|
||||
],
|
||||
"properties": {
|
||||
"mode": "Incremental",
|
||||
"template": {
|
||||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {},
|
||||
"variables": {},
|
||||
"resources": [
|
||||
{
|
||||
"apiVersion": "2021-03-01",
|
||||
"type": "Microsoft.BotService/botServices",
|
||||
"name": "[parameters('azureBotId')]",
|
||||
"location": "[parameters('azureBotRegion')]",
|
||||
"kind": "azurebot",
|
||||
"sku": {
|
||||
"name": "[parameters('azureBotSku')]"
|
||||
},
|
||||
"properties": {
|
||||
"name": "[parameters('azureBotId')]",
|
||||
"displayName": "[parameters('azureBotId')]",
|
||||
"iconUrl": "https://docs.botframework.com/static/devportal/client/images/bot-framework-default.png",
|
||||
"endpoint": "[parameters('botEndpoint')]",
|
||||
"msaAppId": "[parameters('appId')]",
|
||||
"msaAppTenantId": "[variables('appType').tenantId]",
|
||||
"msaAppMSIResourceId": "[variables('appType').msiResourceId]",
|
||||
"msaAppType": "[parameters('appType')]",
|
||||
"luisAppIds": [],
|
||||
"schemaTransformationVersion": "1.3",
|
||||
"isCmekEnabled": false,
|
||||
"isIsolated": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,211 @@
|
|||
{
|
||||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {
|
||||
"groupName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Specifies the name of the Resource Group."
|
||||
}
|
||||
},
|
||||
"groupLocation": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Specifies the location of the Resource Group."
|
||||
}
|
||||
},
|
||||
"appServiceName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The globally unique name of the Web App."
|
||||
}
|
||||
},
|
||||
"appServicePlanName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The name of the App Service Plan."
|
||||
}
|
||||
},
|
||||
"appServicePlanLocation": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The location of the App Service Plan."
|
||||
}
|
||||
},
|
||||
"appServicePlanSku": {
|
||||
"type": "object",
|
||||
"defaultValue": {
|
||||
"name": "S1",
|
||||
"tier": "Standard",
|
||||
"size": "S1",
|
||||
"family": "S",
|
||||
"capacity": 1
|
||||
},
|
||||
"metadata": {
|
||||
"description": "The SKU of the App Service Plan. Defaults to Standard values."
|
||||
}
|
||||
},
|
||||
"tenantId": {
|
||||
"type": "string",
|
||||
"defaultValue": "[subscription().tenantId]",
|
||||
"metadata": {
|
||||
"description": "The Azure AD Tenant ID to use as part of the Bot's Authentication. Only used for SingleTenant and UserAssignedMSI app types. Defaults to \"Subscription Tenant ID\"."
|
||||
}
|
||||
},
|
||||
"appType": {
|
||||
"type": "string",
|
||||
"defaultValue": "MultiTenant",
|
||||
"allowedValues": [
|
||||
"MultiTenant",
|
||||
"SingleTenant",
|
||||
"UserAssignedMSI"
|
||||
],
|
||||
"metadata": {
|
||||
"description": "Type of Bot Authentication. set as MicrosoftAppType in the Web App's Application Settings. Allowed values are: MultiTenant, SingleTenant, UserAssignedMSI. Defaults to \"MultiTenant\"."
|
||||
}
|
||||
},
|
||||
"appId": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Active Directory App ID or User-Assigned Managed Identity Client ID, set as MicrosoftAppId in the Web App's Application Settings."
|
||||
}
|
||||
},
|
||||
"appSecret": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "Active Directory App Password, set as MicrosoftAppPassword in the Web App's Application Settings. Required for MultiTenant and SingleTenant app types."
|
||||
}
|
||||
},
|
||||
"UMSIName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The User-Assigned Managed Identity Resource used for the Bot's Authentication."
|
||||
}
|
||||
},
|
||||
"UMSIResourceGroupName": {
|
||||
"type": "string",
|
||||
"metadata": {
|
||||
"description": "The User-Assigned Managed Identity Resource Group used for the Bot's Authentication."
|
||||
}
|
||||
}
|
||||
},
|
||||
"variables": {
|
||||
"tenantId": "[if(empty(parameters('tenantId')), subscription().tenantId, parameters('tenantId'))]",
|
||||
"appServicePlanName": "[parameters('appServicePlanName')]",
|
||||
"resourcesLocation": "[if(empty(parameters('appServicePlanLocation')), parameters('groupLocation'), parameters('appServicePlanLocation'))]",
|
||||
"appServiceName": "[parameters('appServiceName')]",
|
||||
"resourceGroupId": "[concat(subscription().id, '/resourceGroups/', parameters('groupName'))]",
|
||||
"msiResourceId": "[concat(subscription().id, '/resourceGroups/', parameters('UMSIResourceGroupName'), '/providers/', 'Microsoft.ManagedIdentity/userAssignedIdentities/', parameters('UMSIName'))]",
|
||||
"appTypeDef": {
|
||||
"MultiTenant": {
|
||||
"tenantId": "",
|
||||
"identity": { "type": "None" }
|
||||
},
|
||||
"SingleTenant": {
|
||||
"tenantId": "[variables('tenantId')]",
|
||||
"identity": { "type": "None" }
|
||||
},
|
||||
"UserAssignedMSI": {
|
||||
"tenantId": "[variables('tenantId')]",
|
||||
"identity": {
|
||||
"type": "UserAssigned",
|
||||
"userAssignedIdentities": {
|
||||
"[variables('msiResourceId')]": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"appType": {
|
||||
"tenantId": "[variables('appTypeDef')[parameters('appType')].tenantId]",
|
||||
"identity": "[variables('appTypeDef')[parameters('appType')].identity]"
|
||||
}
|
||||
},
|
||||
"resources": [
|
||||
{
|
||||
"name": "[parameters('groupName')]",
|
||||
"type": "Microsoft.Resources/resourceGroups",
|
||||
"apiVersion": "2018-05-01",
|
||||
"location": "[parameters('groupLocation')]",
|
||||
"properties": {}
|
||||
},
|
||||
{
|
||||
"type": "Microsoft.Resources/deployments",
|
||||
"apiVersion": "2018-05-01",
|
||||
"name": "storageDeployment",
|
||||
"resourceGroup": "[parameters('groupName')]",
|
||||
"dependsOn": [
|
||||
"[resourceId('Microsoft.Resources/resourceGroups/', parameters('groupName'))]"
|
||||
],
|
||||
"properties": {
|
||||
"mode": "Incremental",
|
||||
"template": {
|
||||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {},
|
||||
"variables": {},
|
||||
"resources": [
|
||||
{
|
||||
"comments": "Create a new App Service Plan",
|
||||
"type": "Microsoft.Web/serverfarms",
|
||||
"name": "[variables('appServicePlanName')]",
|
||||
"apiVersion": "2018-02-01",
|
||||
"location": "[variables('resourcesLocation')]",
|
||||
"sku": "[parameters('appServicePlanSku')]",
|
||||
"properties": {
|
||||
"name": "[variables('appServicePlanName')]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"comments": "Create a Web App using the new App Service Plan",
|
||||
"type": "Microsoft.Web/sites",
|
||||
"apiVersion": "2015-08-01",
|
||||
"location": "[variables('resourcesLocation')]",
|
||||
"kind": "app",
|
||||
"dependsOn": [
|
||||
"[concat(variables('resourceGroupId'), '/providers/Microsoft.Web/serverfarms/', variables('appServicePlanName'))]"
|
||||
],
|
||||
"name": "[variables('appServiceName')]",
|
||||
"identity": "[variables('appType').identity]",
|
||||
"properties": {
|
||||
"name": "[variables('appServiceName')]",
|
||||
"serverFarmId": "[variables('appServicePlanName')]",
|
||||
"siteConfig": {
|
||||
"appSettings": [
|
||||
{
|
||||
"name": "WEBSITE_NODE_DEFAULT_VERSION",
|
||||
"value": "10.14.1"
|
||||
},
|
||||
{
|
||||
"name": "MicrosoftAppType",
|
||||
"value": "[parameters('appType')]"
|
||||
},
|
||||
{
|
||||
"name": "MicrosoftAppId",
|
||||
"value": "[parameters('appId')]"
|
||||
},
|
||||
{
|
||||
"name": "MicrosoftAppPassword",
|
||||
"value": "[parameters('appSecret')]"
|
||||
},
|
||||
{
|
||||
"name": "MicrosoftAppTenantId",
|
||||
"value": "[variables('appType').tenantId]"
|
||||
}
|
||||
],
|
||||
"cors": {
|
||||
"allowedOrigins": [
|
||||
"https://botservice.hosting.portal.azure.net",
|
||||
"https://hosting.onecloud.azure-test.net/"
|
||||
]
|
||||
},
|
||||
"webSocketsEnabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"outputs": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name": "my-chat-bot",
|
||||
"version": "1.0.0",
|
||||
"description": "Demonstrate the core capabilities of the Microsoft Bot Framework",
|
||||
"author": "Generated using Microsoft Bot Builder Yeoman generator v4.22.1",
|
||||
"license": "MIT",
|
||||
"main": "./lib/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc --build",
|
||||
"lint": "tslint -c tslint.json 'src/**/*.ts'",
|
||||
"postinstall": "npm run build && node ./deploymentScripts/webConfigPrep.js",
|
||||
"start": "tsc --build && node ./lib/index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"watch": "nodemon --watch ./src -e ts --exec \"npm run start\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com"
|
||||
},
|
||||
"dependencies": {
|
||||
"botbuilder": "~4.22.1",
|
||||
"dotenv": "~8.2.0",
|
||||
"replace": "~1.2.0",
|
||||
"restify": "~11.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/restify": "8.4.2",
|
||||
"nodemon": "^2.0.4",
|
||||
"tslint": "^6.1.2",
|
||||
"typescript": "^4.0.7"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import { ActivityHandler, MessageFactory } from 'botbuilder';
|
||||
|
||||
export class EchoBot extends ActivityHandler {
|
||||
constructor() {
|
||||
super();
|
||||
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
|
||||
this.onMessage(async (context, next) => {
|
||||
const replyText = `Echo: tin tự động`;
|
||||
await context.sendActivity(MessageFactory.text(replyText, replyText));
|
||||
// By calling next() you ensure that the next BotHandler is run.
|
||||
await next();
|
||||
});
|
||||
|
||||
this.onMembersAdded(async (context, next) => {
|
||||
const membersAdded = context.activity.membersAdded;
|
||||
const welcomeText = 'Hello and welcome!';
|
||||
for (const member of membersAdded) {
|
||||
if (member.id !== context.activity.recipient.id) {
|
||||
await context.sendActivity(MessageFactory.text(welcomeText, welcomeText));
|
||||
}
|
||||
}
|
||||
// By calling next() you ensure that the next BotHandler is run.
|
||||
await next();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
import * as path from 'path';
|
||||
|
||||
import { config } from 'dotenv';
|
||||
const ENV_FILE = path.join(__dirname, '..', '.env');
|
||||
config({ path: ENV_FILE });
|
||||
|
||||
import * as restify from 'restify';
|
||||
|
||||
import { INodeSocket } from 'botframework-streaming';
|
||||
|
||||
// Import required bot services.
|
||||
// See https://aka.ms/bot-services to learn more about the different parts of a bot.
|
||||
import {
|
||||
CloudAdapter,
|
||||
ConfigurationServiceClientCredentialFactory,
|
||||
createBotFrameworkAuthenticationFromConfiguration
|
||||
} from 'botbuilder';
|
||||
|
||||
// This bot's main dialog.
|
||||
import { EchoBot } from './bot';
|
||||
|
||||
|
||||
// Create HTTP server.
|
||||
const server = restify.createServer();
|
||||
server.use(restify.plugins.bodyParser());
|
||||
|
||||
server.listen(process.env.port || process.env.PORT || 3978, () => {
|
||||
console.log(`\n${server.name} listening to ${server.url}`);
|
||||
console.log('\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator');
|
||||
console.log('\nTo talk to your bot, open the emulator select "Open Bot"');
|
||||
});
|
||||
|
||||
const credentialsFactory = new ConfigurationServiceClientCredentialFactory({
|
||||
MicrosoftAppId: process.env.MicrosoftAppId,
|
||||
MicrosoftAppPassword: process.env.MicrosoftAppPassword,
|
||||
MicrosoftAppType: process.env.MicrosoftAppType,
|
||||
MicrosoftAppTenantId: process.env.MicrosoftAppTenantId
|
||||
});
|
||||
|
||||
const botFrameworkAuthentication = createBotFrameworkAuthenticationFromConfiguration(null, credentialsFactory);
|
||||
|
||||
// Create adapter.
|
||||
// See https://aka.ms/about-bot-adapter to learn more about adapters.
|
||||
const adapter = new CloudAdapter(botFrameworkAuthentication);
|
||||
|
||||
// Catch-all for errors.
|
||||
const onTurnErrorHandler = async (context, error) => {
|
||||
// This check writes out errors to console log .vs. app insights.
|
||||
// NOTE: In production environment, you should consider logging this to Azure
|
||||
// application insights.
|
||||
console.error(`\n [onTurnError] unhandled error: ${ error }`);
|
||||
|
||||
// Send a trace activity, which will be displayed in Bot Framework Emulator
|
||||
await context.sendTraceActivity(
|
||||
'OnTurnError Trace',
|
||||
`${ error }`,
|
||||
'https://www.botframework.com/schemas/error',
|
||||
'TurnError'
|
||||
);
|
||||
|
||||
// Send a message to the user
|
||||
await context.sendActivity('The bot encountered an error or bug.');
|
||||
await context.sendActivity('To continue to run this bot, please fix the bot source code.');
|
||||
};
|
||||
|
||||
// Set the onTurnError for the singleton CloudAdapter.
|
||||
adapter.onTurnError = onTurnErrorHandler;
|
||||
|
||||
// Create the main dialog.
|
||||
const myBot = new EchoBot();
|
||||
|
||||
// Listen for incoming requests.
|
||||
server.post('/api/messages', async (req, res) => {
|
||||
// Route received a request to adapter for processing
|
||||
await adapter.process(req, res, (context) => myBot.run(context));
|
||||
});
|
||||
|
||||
// Listen for Upgrade requests for Streaming.
|
||||
server.on('upgrade', async (req, socket, head) => {
|
||||
// Create an adapter scoped to this WebSocket connection to allow storing session data.
|
||||
const streamingAdapter = new CloudAdapter(botFrameworkAuthentication);
|
||||
|
||||
// Set onTurnError for the CloudAdapter created for each connection.
|
||||
streamingAdapter.onTurnError = onTurnErrorHandler;
|
||||
|
||||
await streamingAdapter.process(req, socket as unknown as INodeSocket, head, (context) => myBot.run(context));
|
||||
});
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"target": "es2017",
|
||||
"module": "commonjs",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"sourceMap": true,
|
||||
"incremental": true,
|
||||
"tsBuildInfoFile": "./lib/.tsbuildinfo"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": [
|
||||
"tslint:recommended"
|
||||
],
|
||||
"jsRules": {},
|
||||
"rules": {
|
||||
"interface-name" : [true, "never-prefix"],
|
||||
"max-line-length": [false],
|
||||
"no-console": [false, "log", "error"],
|
||||
"no-var-requires": false,
|
||||
"quotemark": [true, "single"],
|
||||
"one-variable-per-declaration": false,
|
||||
"curly": [true, "ignore-same-line"],
|
||||
"trailing-comma": [true, {"multiline": "never", "singleline": "never"}]
|
||||
},
|
||||
"rulesDirectory": []
|
||||
}
|
||||
Loading…
Reference in New Issue