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
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(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 @@ -22,15 +20,15 @@ function requestChatBot(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() {
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 @@ -31,13 +29,6 @@ function isUserAuthenticated(){
return true;
}

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

const appConfig = {
isHealthy : false,
options : {
Expand Down Expand Up @@ -96,7 +87,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