Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

voice org validations #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
83 changes: 65 additions & 18 deletions src/byo-ott-app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let output;
let sfSubject = "Agent";
let endUserClientName = "End User Client";
let typingStartedReady = true;
var orgMode;

window.addEventListener("load", () => {

Expand Down Expand Up @@ -427,19 +428,49 @@ window.addEventListener("load", () => {
// Register custom event to retrieve the replied message from an agent in core app
const evtSource = new EventSource(SERVER_URL + "/replyMessage");
evtSource.addEventListener("replymsg", (e) => {
console.log('\n=============== EventSource - replymsg event:', e.data);
let replyObj = JSON.parse(e.data);
if (replyObj.type === messagingConstants.EVENT_TYPE.INTERACTION) {
appendInboundMessageToChatList(replyObj.replyMessageText, replyObj.attachmentName, replyObj.attachmentUrl, replyObj.payloadField);
} else if (replyObj.type === messagingConstants.EVENT_TYPE.ROUTING_REQUESTED) {
appendInboundEventToChatList(replyObj.type, replyObj.payloadField);
if (!orgMode) {
axios({
method: "get",
url: SERVER_URL + "/getOrgMode"
}).then((res) => {
if (res && res.data && res.data.orgMode) {
orgMode = res.data.orgMode;
registerEvents(e);
}
});
} else {
registerEvents(e);
}
});

if(document.getElementById('healthCheckButton')) {
document.getElementById('healthCheckButton').addEventListener('click', runHealthCheck);
}

function registerEvents(event) {
if (orgMode !== 'VOICE_ONLY') {
console.log('\n=============== EventSource - replymsg event:', event.data);
let replyObj = JSON.parse(event.data);
if (replyObj.type === messagingConstants.EVENT_TYPE.INTERACTION) {
switch(replyObj.messageType) {
case 'ChoicesMessage':
appendChoicesMessageToChatList(replyObj,replyObj.payloadField.string);
break;
case 'FormMessage':
appendFormMessageToChatList(replyObj);
break;
case 'StaticContentMessage':
appendInboundMessageToChatList(replyObj.replyMessageText, replyObj.attachmentName, replyObj.attachmentUrl, replyObj.payloadField);
break;
default:
console.log('Unsupported message type:', replyObj.messageType);
}
} else if (replyObj.type === messagingConstants.EVENT_TYPE.ROUTING_REQUESTED) {
appendInboundEventToChatList(replyObj.type, replyObj.payloadField);
}
}
}

function getTestDescription(testName) {
const descriptionKey = testDescriptionMapping[testName];
const description = testDescriptions[descriptionKey] || 'Description not available.';
Expand Down Expand Up @@ -571,12 +602,26 @@ function initializeAccordion() {
});
}

// get settings from middleware server
// get settings from middleware server
if (!orgMode) {
axios({
method: "get",
url: SERVER_URL + "/getOrgMode"
}).then((res) => {
if (res && res.data && res.data.orgMode) {
orgMode = res.data.orgMode;
getSettingsForApp();
}
});
} else {
getSettingsForApp();
}

function getSettingsForApp() {
axios({
method: "get",
url: SERVER_URL + "/getsettings"
})
.then((res) => {
}).then((res) => {
if (res.status === 200) {
// set settings fields with values retrieved from middleware server
let settings = res.data;
Expand All @@ -601,13 +646,17 @@ function initializeAccordion() {
}
endUserClientName = settings.endUserClientIdentifier;

return axios({
method: "get",
url: SERVER_URL + "/getConversationChannelDefinitions",
});
// Ensuring the demo connector runs gracefully even if the .env is not present
if (!settings.authorizationContext) {
return null;
} else {
return axios({
method: "get",
url: SERVER_URL + "/getConversationChannelDefinitions",
});
}
}
})
.then((ccdResponse) => {
}).then((ccdResponse) => {
if (ccdResponse && ccdResponse.status && ccdResponse.status === 200) {
let ccdData = ccdResponse.data;

Expand Down Expand Up @@ -635,9 +684,7 @@ function initializeAccordion() {
.catch((err) => {
throw err;
});

chatList = document.getElementById('chatList');
});
}

function appendOutboundMessageToChatList(message, originalFileName, fileName) {
if (originalFileName && fileName) {
Expand Down
11 changes: 11 additions & 0 deletions src/remote-control/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,17 @@ function showCcaasDemoAppTab() {
}

function setDemoConnectorMode(mode) {
//set the mode to server cache so that OTT client apps can also access this information
fetch("http://localhost:3030/setOrgMode", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({orgMode : mode }),
}).then(response => response.json()).then((data) => {
console.log('setOrgMode response: ' + JSON.stringify(data));
})

// connector mode only applicable for ccaas remote.
if (!window.location.pathname.startsWith('/ccaas.html')) {
return false;
Expand Down
12 changes: 12 additions & 0 deletions src/server/ottAppServer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,18 @@ export async function initOttApp(expressApp) {

res.send('Connected to PubSub and Subscribed to the Interaction event.');
});

expressApp.post('/setOrgMode', async (_req, res) => {
settingsCache.set('orgMode', _req.body.orgMode);
console.log("OTT SERVER settingsCache.set('orgMode') : " + _req.body.orgMode);
res.send({success:true});
});

expressApp.get('/getOrgMode', async (_req, res) => {
console.log("OTT SERVER settingsCache.get('orgMode') : " + settingsCache.get('orgMode'));
res.send({orgMode:settingsCache.get('orgMode')});
});

// ========== Endpoint definitions end. ==========

// Calling PubSub API in fetchAndCacheCCDValues() function to prevent race conditions
Expand Down
15 changes: 15 additions & 0 deletions src/server/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import { ScrtConnector } from './scrtConnector.mjs';
import { Server } from 'socket.io';
import { initOttApp } from './ottAppServer.mjs';
import { agentWorkCache } from './ottAppLib/sfdc-byocc-agentwork-api.mjs';
import NodeCache from 'node-cache';

customEnv.env();
const app = express();
app.use(express.json());
let onlineUsers = new Map(); // username -> socket.id
let userFullNames = new Map(); // username -> FullName
let connectors = new Set();
const modeCache = new NodeCache();

const server = app.listen(process.env.SERVER_PORT, () => {
console.log(`\n====== App listening to ${process.env.SERVER_PORT}. Press Ctrl+C to quit.`);
Expand Down Expand Up @@ -172,4 +174,17 @@ app.post('/api/clear-agent-work-cache', (req,res) => {
console.log(`Error deleting ${workItemId} from agentWorkCache: \n ${err}`);
res.send({ success: false });
}
});

app.post('/api/setOrgMode', (req, res) => {
try {
if (req && req.body) {
modeCache.set('orgMode', req.body.orgMode);
console.log(`Org Mode set to ${req.body.orgMode}`);
res.send({ success: true});
}
} catch (err) {
console.log(`Error setting Org mode to cache: ${err}`);
res.send({ success: false});
}
});
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ module.exports = {
{from: /^\/$/, to: 'app_debug.html'},
{from: /^\/remote/, to: 'remote.html'},
{from: /^\/login/, to: 'login.html'},
{from: /^\/ottapp/, to: 'ottapp.html'},
{from: /^\/ccaas/, to: 'ccaas.html'}
{from: /^\/ccaas/, to: 'ccaas.html'},
{from: /^\/ottapp/, to: 'ottapp.html'}
]
}
},
Expand Down