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

Use Admin API front-end #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
163 changes: 106 additions & 57 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
/**
* Surfly NIC integration
*
* Make sure the following variables are initialized based on your configuration before importing this script
* showLiveChatButton
* showVideoChatButton
* scaleDroneChannelId
* nicHomeURL
* nicBusNumber
* nicChatPOC
* clusterNiC
* videoSignalerURL
* chatSignalerURL
* surflySettings
* surflyWidgetKey
* surflyModalTitle
* surflyModalBody
*
* Example in HTML pages:
*
* <html>
* <head>
* ...
* </head>
* <body>
* ...
* <script>
* var showLiveChatButton = true;
* var showVideoChatButton = true;
* var scaleDroneChannelId = 'fygLrCqVZUYQZL6';
* var nicHomeURL = 'https://home-b99.nice-incontact.com';
* var nicBusNumber = '1809119';
* var nicChatPOC = '1605d121-489c-4df4-83b1-334dbeb0a781u';
* var clusterNiC = 'b99';
* var videoSignalerURL = "https://home-b99.nice-incontact.com/inContact/Manage/Scripts/Spawn.aspx?scriptName=Surfly_Signaler&bus_no=1534130&scriptId=64719900&skill_no=1197136&Guid=602b102c74-c935-4539-9f80-0827ab18918";
* var chatSignalerURL = "https://home-b99.nice-incontact.com/inContact/Manage/Scripts/Spawn.aspx?scriptName=Surfly_Signaler&bus_no=1534130&scriptId=64719900&skill_no=1197136&Guid=602b102c74-c935-4539-9f80-0827ab18918";
* var surflySettings = { ... };
* // The following variables can be passed as part of the surflySettings object. we keep supporting them for backward compatibility
* var surflyWidgetKey = '134f5fd2ac8842c0a1cd6062818yd2ac';
* var surflyModalTitle = 'Start Videochat';
* var surflyModalBody = 'By clicking Accept, an agent will automatically join you in a videochat session. You will be prompted to enable/disable your camera and mute/unmute your microphone. You can access your audio settings using the gear icon. You can end the videochat at any time, by clicking ✕ in the menu or by closing this tab in your browser.';
* ​ </script>
* <script type="text/javascript" src="https://nic.surfly.com/surfly-nic-script.js"></script>
* ...
* ​</body>
* </html>
Surfly NIC integration

Make sure the following variables are initialized based on your configuration before importing this script

- showLiveChatButton
- showVideoChatButton
- scaleDroneChannelId

- surflySettings
- surflyWidgetKey
- surflyModalTitle
- surflyModalBody

- nicChatPOC
- clusterNiC
- nicBusNumber
- nicHomeURL

Example in HTML pages:

<html>
<head>
...
</head>
<body>
...
<script>
var showLiveChatButton = true;
var showVideoChatButton = true;
var scaleDroneChannelId = 'fygLrCqVZUYQZL6';
var nicHomeURL = 'https://home-b99.nice-incontact.com';
var nicBusNumber = '1809119';
var nicChatPOC = '1605d121-489c-4df4-83b1-334dbeb0a781u';
var clusterNiC = 'b99';
var videoSignalerURL = "https://home-b99.nice-incontact.com/inContact/Manage/Scripts/Spawn.aspx?scriptName=Surfly_Signaler&bus_no=1534130&scriptId=64719900&skill_no=1197136&Guid=602b102c74-c935-4539-9f80-0827ab18918";
mirhmousavi marked this conversation as resolved.
Show resolved Hide resolved
var chatSignalerURL = "https://home-b99.nice-incontact.com/inContact/Manage/Scripts/Spawn.aspx?scriptName=Surfly_Signaler&bus_no=1534130&scriptId=64719900&skill_no=1197136&Guid=602b102c74-c935-4539-9f80-0827ab18918";
var surflySettings = { ... };
// The following variables can be passed as part of the surflySettings object. we keep supporting them for backward compatibility
var surflyWidgetKey = '134f5fd2ac8842c0a1cd6062818yd2ac';
var surflyModalTitle = 'Start Videochat';
var surflyModalBody = 'By clicking Accept, an agent will automatically join you in a videochat session. You will be prompted to enable/disable your camera and mute/unmute your microphone. You can access your audio settings using the gear icon. You can end the videochat at any time, by clicking ✕ in the menu or by closing this tab in your browser.';
</script>
<script type="text/javascript" src="https://nic.surfly.com/surfly-nic-script.js"></script>
...
</body>
</html>
*/

var nicHomeURL = nicHomeURL || "https://home-" + clusterNiC + ".nice-incontact.com";
Expand Down Expand Up @@ -168,17 +169,25 @@ function createSurflySession(contactId, inviteType) {
var surflyMetadata = {
"name": "Customer"
};

if (inviteType == 'cobrowse') {
var regularSession = Surfly.session({
block_until_agent_joins: false
});
regularSession.on("session_started", function(session, event) {
var surflySessionPin = session.pin;
var surflyFollowerLink = session.followerLink;
signalContact(contactId, surflyFollowerLink, surflySessionPin, 'cobrowse');
if(!window.chatSignalerURL) {
sendFollowerLink(
session.followerLink,
inviteType,
localStorage.getItem(nicBusNumber + "-uniquePageId"),
scaleDroneChannelId
);
} else {
signalContact(contactId, session.follower_link, session.pin, inviteType);
}
var chatDiv = document.getElementById("chat-div-wrap");
chatDiv.style.zIndex = "2147483549";
console.log('Session Pin: ' + surflySessionPin);
console.log('Session Pin: ' + session.pin);
console.log('Contact ID: ' + contactId);
}).on("session_ended", function(session, event) {
console.log("Regular session ended, updating Studio");
Expand All @@ -192,12 +201,19 @@ function createSurflySession(contactId, inviteType) {
videochat_start_fullscreen: true
});
regularSession.on("session_started", function(session, event) {
var surflySessionPin = session.pin;
var surflyFollowerLink = session.followerLink;
signalContact(contactId, surflyFollowerLink, surflySessionPin, 'videochat');
if(!window.chatSignalerURL) {
sendFollowerLink(
session.followerLink,
inviteType,
localStorage.getItem(nicBusNumber + "-uniquePageId"),
scaleDroneChannelId
);
} else {
signalContact(contactId, session.follower_link, session.pin, inviteType);
}
var chatDiv = document.getElementById("chat-div-wrap");
chatDiv.style.zIndex = "2147483549";
console.log('Session Pin: ' + surflySessionPin);
console.log('Session Pin: ' + session.pin);
console.log('Contact ID: ' + contactId);
}).on("session_ended", function(session, event) {
console.log("Regular session ended, updating Studio");
Expand All @@ -207,6 +223,24 @@ function createSurflySession(contactId, inviteType) {
}
}

function sendFollowerLink(followerLink, type, uniquePageId, channelId) {
fetch(
"https://admin-api-backend-ef6aeff35287.herokuapp.com/follower_link",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
channel_id: channelId,
room: type,
unique_page_id: uniquePageId,
follower_link: followerLink,
}),
}
);
}


function loadSurfly() {
var settings = {
Expand Down Expand Up @@ -257,8 +291,8 @@ function loadSurfly() {
} = message;

if (data.type == 'ElevateToCobrowse' && data.bu == nicBusNumber && data.uniquePageId == localStorage.getItem(nicBusNumber + "-uniquePageId")) {
createSurflySession(data.contactId, 'cobrowse');

const inviteType = 'cobrowse';
createSurflySession(data.contactId, inviteType);
console.log('Co-browsing session requested');
console.log("Message ID: " + id);
console.log("Timestamp: " + timestamp);
Expand Down Expand Up @@ -294,7 +328,7 @@ function loadSurfly() {
} = message;

if (data.type == 'ElevateToVideo' && data.bu == nicBusNumber && data.uniquePageId == localStorage.getItem(nicBusNumber + "-uniquePageId")) {
createSurflySession(data.contactId, 'videochat');
createSurflySession(data.contactId, inviteType);

console.log('Videochat session requested');
console.log("Message ID: " + id);
Expand Down Expand Up @@ -341,4 +375,19 @@ function initializeChatNiC() {
});

console.log('Initializing NiC');
}
}

var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
console.log("mutation", mutation);
mutation.addedNodes.forEach(function (node) {
console.log("node added 2", node);
});
mutation.removedNodes.forEach(function (node) {
console.log("node removed 2", node);
});

});
});
var chat_messenger_frame = document.getElementById("icChat");
observer.observe(document, { childList: true, subtree: true, attributes: true, characterData: true });