Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ A simple web page to hand off users to the Microsoft Health bot

[![Deploy to Azure](https://azuredeploy.net/deploybutton.png)](https://azuredeploy.net/)

Note: It is recommended you use the default Linux host type when deploying the container.
However, if you wish to enable online file editing using the App Service Editor, select 'Windows'.

2.Set the following environment variables:

`APP_SECRET`
Expand Down Expand Up @@ -48,7 +51,7 @@ In some cases it is required to set the endpoint URI so that it points to a spec

Pass your preferred geographic endpoint URI by setting the environment variable: `DIRECTLINE_ENDPOINT_URI` in your deployment. If no variable is found it will default to `directline.botframework.com`

**Note:** If you are deploying the code sample using the "Deploy to Azure" option, you should add the above secrets to the application settings for your App Service.
**Note:** If you are deploying the code sample using the "Deploy to Azure" option, you should add the above secrets to the application settings for your App Service.

## Live agent handoff sample

Expand Down
128 changes: 116 additions & 12 deletions azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@
"defaultValue": "[concat('HealthBot', uniqueString(resourceGroup().name, utcNow('F')))]",
"metadata":{
"description": "Web site name. Has to be unique."


}
},
"operatingSystem": {
"type": "string",
"defaultValue": "linux",
"allowedValues": [
"linux",
"windows"
],
"metadata": {
"description": "Host type: Linux or Windows. (Linux is recommended)"
}
},
"skuName": {
"type": "string",
"defaultValue": "P1V2",
"allowedValues": [
"allowedValues": [
"B1",
"S1",
"P1V2"
Expand Down Expand Up @@ -44,7 +55,7 @@
"webchatSecret": {
"type": "securestring",
"metadata":{
"description": "Healthbot webchat secret."
"description": "Healthbot webchat secret."
}
}
},
Expand All @@ -53,21 +64,33 @@
"skuCode": "[parameters('skuName')]",
"numberOfWorkers": "[parameters('numberOfInstances')]",
"linuxFxVersion": "NODE|lts",
"hostingPlanName": "[concat('hpn-', parameters('siteName'))]",
"hostingPlanNameLinux": "[concat('plan-linux-', parameters('siteName'))]",
"hostingPlanNameWin": "[concat('plan-win-', parameters('siteName'))]",
"repoURL": "https://github.com/microsoft/HealthBotContainerSample.git",
"branch": "live_agent_handoff"
"branch": "live_agent_handoff",
"kind": "[if(equals(parameters('operatingSystem'), 'windows'), 'app', 'linux')]",
"linuxSiteName": "[if(equals(parameters('operatingSystem'), 'linux'), parameters('siteName'), 'app-na')]",
"windowsSiteName": "[if(equals(parameters('operatingSystem'), 'windows'), parameters('siteName'), 'app-na')]",
"WinSkuCode": "[parameters('skuName')]",
"WinSku": "Standard",
"workerSize": "0",
"workerSizeId": "0",
"hostingEnvironment": "",
"nodeVersion": "12.13.0",
"currentStack": "node"
},
"resources": [
{
"apiVersion": "2018-02-01",
"name": "[parameters('siteName')]",
"name": "[variables('linuxSiteName')]",
"condition": "[equals(parameters('operatingSystem'),'linux')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('siteLocation')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]"
"[resourceId('Microsoft.Web/serverfarms/', variables('hostingPlanNameLinux'))]"
],
"properties": {
"name": "[parameters('siteName')]",
"name": "[variables('linuxSiteName')]",
"siteConfig": {
"linuxFxVersion": "[variables('linuxFxVersion')]",
"alwaysOn": "[variables('alwaysOn')]",
Expand All @@ -82,17 +105,18 @@
}
]
},
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanNameLinux'))]",
"clientAffinityEnabled": false
},
"resources": [
{
"type": "sourcecontrols",
"condition": "[equals(parameters('operatingSystem'),'linux')]",
"apiVersion": "2018-02-01",
"name": "web",
"location": "[parameters('siteLocation')]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('siteName'))]"
"[resourceId('Microsoft.Web/sites', variables('linuxSiteName'))]"
],
"properties": {
"repoUrl": "[variables('repoURL')]",
Expand All @@ -104,18 +128,98 @@
},
{
"apiVersion": "2018-02-01",
"name": "[variables('hostingPlanName')]",
"condition": "[equals(parameters('operatingSystem'),'linux')]",
"name": "[variables('hostingPlanNameLinux')]",
"type": "Microsoft.Web/serverfarms",
"location": "[parameters('siteLocation')]",
"kind": "linux",
"sku": {
"Name": "[variables('skuCode')]"
},
"properties": {
"name": "[variables('hostingPlanName')]",
"name": "[variables('hostingPlanNameLinux')]",
"numberOfWorkers": "[variables('numberOfWorkers')]",
"reserved": true
}
},
{
"apiVersion": "2018-11-01",
"condition": "[equals(parameters('operatingSystem'),'windows')]",
"name": "[variables('windowsSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('siteLocation')]",
"tags": null,
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', variables('hostingPlanNameWin'))]"
],
"properties": {
"name": "[variables('windowsSiteName')]",
"siteConfig": {
"appSettings": [
{
"name": "APP_SECRET",
"value": "[parameters('appSecret')]"
},
{
"name": "WEBCHAT_SECRET",
"value": "[parameters('webchatSecret')]"
},
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "[variables('nodeVersion')]"
}
],
"metadata": [
{
"name": "CURRENT_STACK",
"value": "[variables('currentStack')]"
}
],
"nodeVersion": "[variables('nodeVersion')]",
"alwaysOn": "[variables('alwaysOn')]"
},
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanNameWin'))]",
"hostingEnvironment": "[variables('hostingEnvironment')]",
"clientAffinityEnabled": true
},
"resources": [
{
"type": "sourcecontrols",
"condition": "[equals(parameters('operatingSystem'),'windows')]",
"apiVersion": "2018-11-01",
"name": "web",
"location": "[parameters('siteLocation')]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('windowsSiteName'))]"
],
"properties": {
"repoUrl": "[variables('repoURL')]",
"branch": "[variables('branch')]",
"isManualIntegration": true
}
}
]
},
{
"apiVersion": "2018-11-01",
"name": "[variables('hostingPlanNameWin')]",
"condition": "[equals(parameters('operatingSystem'),'windows')]",
"type": "Microsoft.Web/serverfarms",
"location": "[parameters('siteLocation')]",
"kind": "",
"tags": null,
"dependsOn": [],
"properties": {
"name": "[variables('hostingPlanNameWin')]",
"workerSize": "[variables('workerSize')]",
"workerSizeId": "[variables('workerSizeId')]",
"numberOfWorkers": "[variables('numberOfWorkers')]",
"hostingEnvironment": "[variables('hostingEnvironment')]"
},
"sku": {
"Tier": "[variables('WinSku')]",
"Name": "[variables('WinSkuCode')]"
}
}
]
}
14 changes: 6 additions & 8 deletions public/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const defaultLocale = 'en-US';
const localeRegExPattern = /^[a-z]{2}(-[A-Z]{2})?$/;

function requestChatBot(info, loc) {
const params = new URLSearchParams(location.search);
const locale = params.has('locale') ? extractLocale(params.get('locale')) : defaultLocale;
const oReq = new XMLHttpRequest();
oReq.addEventListener("load", initBotConversation);
var path = "/chatBot?locale=" + locale;
var path = "/chatBot?locale=" + extractLocale(params.get('locale'));

if (loc) {
path += "&lat=" + loc.lat + "&long=" + loc.long;
Expand All @@ -32,15 +30,15 @@ function requestChatBot(info, loc) {
}

function extractLocale(localeParam) {
if(localeParam === 'autodetect') {
if (!localeParam) {
return defaultLocale;
}
else if (localeParam === 'autodetect') {
return navigator.language;
}

//Before assigning, ensure it's a valid locale string (xx or xx-XX)
if(localeParam.search(localeRegExPattern) === 0) {
else {
return localeParam;
}
return defaultLocale;
}

function chatRequested(info) {
Expand Down
11 changes: 1 addition & 10 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require('dotenv').config();
const defaultLocale = 'en-US';
const localeRegExPattern = /^[a-z]{2}(-[A-Z]{2})?$/;
const crypto = require('crypto');
const express = require("express");
const path = require("path");
Expand Down Expand Up @@ -36,13 +34,6 @@ function isAgentAuthenticated(req) {
return Boolean(req.query.agent);
}

function getValidatedLocale(loc) {
if (loc.search(localeRegExPattern) === 0) {
return loc;
}
return defaultLocale;
}

const appConfig = {
isHealthy : false,
options : {
Expand Down Expand Up @@ -101,7 +92,7 @@ app.post('/chatBot', function(req, res) {
var response = {};
response['userId'] = userid;
response['userName'] = req.query.userName;
response['locale'] = getValidatedLocale(req.query.locale);
response['locale'] = req.query.locale;
response['connectorToken'] = parsedBody.token;

/*
Expand Down