Skip to content

Commit

Permalink
Send follower link to the backend instead of using signaler scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mirhmousavi committed May 17, 2024
1 parent 90333f7 commit b8aa570
Showing 1 changed file with 95 additions and 57 deletions.
152 changes: 95 additions & 57 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
/**
* 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
# If your BU is not configured for the new signaling flow, you should provide the following variables
- videoSignalerURL
- chatSignalerURL
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>
*/

var nicHomeURL = nicHomeURL || "https://home-" + clusterNiC + ".nice-incontact.com";
Expand Down Expand Up @@ -168,17 +173,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 +205,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 +227,24 @@ function createSurflySession(contactId, inviteType) {
}
}

function sendFollowerLink(followerLink, type, uniquePageId, channelId) {
fetch(
"https://nic.surf.ly/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 +295,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 +332,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 +379,4 @@ function initializeChatNiC() {
});

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

0 comments on commit b8aa570

Please sign in to comment.