yelda-webchat 1.1.5 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/yeldaWebchatInjector.css +140 -22
- package/dist/css/yeldaWebchatInjector.min.css +18 -8
- package/dist/css/yeldaWebchatInjector.min.css.map +1 -1
- package/dist/js/yeldaWebchatInjector.js +190 -44
- package/dist/js/yeldaWebchatInjector.js.map +1 -1
- package/dist/js/yeldaWebchatInjector.min.js +1 -1
- package/package.json +1 -1
- package/src/config/index.js +7 -2
- package/src/css/yeldaWebchatInjector.css +140 -22
- package/src/js/yeldaWebchatInjector.js +161 -42
- package/uploadBuildToS3.js +1 -3
|
@@ -823,27 +823,68 @@ var YeldaChat = function () {
|
|
|
823
823
|
|
|
824
824
|
/**
|
|
825
825
|
* Create an assistantBubbleText component and add it to webChatContainer element
|
|
826
|
+
* @param {String} text - default null
|
|
827
|
+
* @param {String} cssClass - default ''
|
|
826
828
|
*/
|
|
827
829
|
|
|
828
830
|
}, {
|
|
829
831
|
key: 'addAssistantBubbleText',
|
|
830
832
|
value: function addAssistantBubbleText() {
|
|
831
|
-
|
|
833
|
+
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
834
|
+
var cssClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
835
|
+
|
|
836
|
+
text = text || this.webchatSettings && this.webchatSettings.bubbleText;
|
|
837
|
+
if (!this.webChatContainer || !text) {
|
|
832
838
|
return;
|
|
833
839
|
}
|
|
834
840
|
|
|
841
|
+
// Remove the assistant bubble text element before adding a new one
|
|
842
|
+
this.removeElement('yelda_assistant_bubble_text');
|
|
835
843
|
// create assistantBubbleText element and set the text
|
|
836
844
|
this.assistantBubbleText = document.createElement('span');
|
|
837
845
|
this.assistantBubbleText.setAttribute('id', 'yelda_assistant_bubble_text');
|
|
838
|
-
this.assistantBubbleText.
|
|
846
|
+
this.assistantBubbleText.setAttribute('class', cssClass);
|
|
847
|
+
this.assistantBubbleText.innerText = text;
|
|
848
|
+
this.addCloseButtonForBubbleText();
|
|
839
849
|
|
|
840
850
|
// Add click event to assistant text
|
|
841
|
-
this.assistantBubbleText.addEventListener('click', this.openChat);
|
|
851
|
+
this.assistantBubbleText.addEventListener('click', this.openChat.bind(this));
|
|
842
852
|
|
|
843
853
|
// add assistant text to webChatContainer using the webchatSettings
|
|
844
854
|
this.webChatContainer.appendChild(this.assistantBubbleText);
|
|
845
855
|
}
|
|
846
856
|
|
|
857
|
+
/**
|
|
858
|
+
* Add close button for bubble text
|
|
859
|
+
*/
|
|
860
|
+
|
|
861
|
+
}, {
|
|
862
|
+
key: 'addCloseButtonForBubbleText',
|
|
863
|
+
value: function addCloseButtonForBubbleText() {
|
|
864
|
+
// Create close button and add it to the bubble text container
|
|
865
|
+
var closeButton = document.createElement('a');
|
|
866
|
+
closeButton.setAttribute('class', 'bubbleCloseButton');
|
|
867
|
+
closeButton.setAttribute('id', 'yelda_assistant_bubble_text_close');
|
|
868
|
+
closeButton.setAttribute('href', '#');
|
|
869
|
+
closeButton.innerHTML = '×';
|
|
870
|
+
closeButton.onclick = this.closeBubbleText.bind(this);
|
|
871
|
+
this.assistantBubbleText.prepend(closeButton);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Callback function for bubble text close button
|
|
876
|
+
* @param {Event} event
|
|
877
|
+
*/
|
|
878
|
+
|
|
879
|
+
}, {
|
|
880
|
+
key: 'closeBubbleText',
|
|
881
|
+
value: function closeBubbleText(event) {
|
|
882
|
+
event.preventDefault();
|
|
883
|
+
event.stopPropagation();
|
|
884
|
+
this.removeElement('yelda_assistant_bubble_text');
|
|
885
|
+
this.assistantBubbleText = null;
|
|
886
|
+
}
|
|
887
|
+
|
|
847
888
|
/**
|
|
848
889
|
* Create assistantImage element and add it to webChatContainer element
|
|
849
890
|
*/
|
|
@@ -878,7 +919,7 @@ var YeldaChat = function () {
|
|
|
878
919
|
this.assistantImage.innerHTML = '<i class="fas fa-comment"></i>';
|
|
879
920
|
|
|
880
921
|
// Add click event to assistant image
|
|
881
|
-
this.assistantImage.addEventListener('click', this.openChat);
|
|
922
|
+
this.assistantImage.addEventListener('click', this.openChat.bind(this));
|
|
882
923
|
|
|
883
924
|
// add assistantImage to webChatContainer using the webchatSettings
|
|
884
925
|
this.updateAssistantImageWithAssistantSettings();
|
|
@@ -999,6 +1040,46 @@ var YeldaChat = function () {
|
|
|
999
1040
|
return url;
|
|
1000
1041
|
}
|
|
1001
1042
|
|
|
1043
|
+
/**
|
|
1044
|
+
* Add 'y_active' class to the webChatContainer if required
|
|
1045
|
+
*
|
|
1046
|
+
* To control the opacity of the iframe container (.yelda_iframe_container) and the assistant image (.yelda_assistant_img),
|
|
1047
|
+
* We add and remove the "y_active" CSS class to the webChatContainer (.yelda_container) which is always visible
|
|
1048
|
+
* By default
|
|
1049
|
+
* - yelda_iframe_container is hidden (opacity: 0;)
|
|
1050
|
+
* - assistant image is visible (opacity: 1 for yelda_assistant_img)
|
|
1051
|
+
*
|
|
1052
|
+
* When we add the class "y_active" to (webChatContainer)
|
|
1053
|
+
* - yelda_iframe_container is now visible (.y_active .yelda_iframe_container => opacity: 1)
|
|
1054
|
+
* - the assistant image is hidden (.yelda_container.y_active .yelda_assistant_img => opacity: 0
|
|
1055
|
+
*
|
|
1056
|
+
* @param {Boolean} data.shouldBeOpened
|
|
1057
|
+
* @param {Boolean} data.isStartBtn
|
|
1058
|
+
* @param {Boolean} data.canBeClosed
|
|
1059
|
+
*/
|
|
1060
|
+
|
|
1061
|
+
}, {
|
|
1062
|
+
key: 'initWebChatContainerYActiveClass',
|
|
1063
|
+
value: function initWebChatContainerYActiveClass(data) {
|
|
1064
|
+
// should be opened on load OR has a start button
|
|
1065
|
+
var shoulBeOpened = data.shouldBeOpened || data.isStartBtn;
|
|
1066
|
+
|
|
1067
|
+
// cannot be closed (canBeClosed explicitly set to false)
|
|
1068
|
+
var cantBeClosed = data.hasOwnProperty('canBeClosed') && !data.canBeClosed;
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* If we are sure that the webchat should be opened from the creation and displayed all the time
|
|
1072
|
+
* we add the y_active class to webChatContainer at the creation
|
|
1073
|
+
*
|
|
1074
|
+
* Otherwise yelda_assistant_img click event management will take care of showing and hiding the webchat
|
|
1075
|
+
* - closeChat() remove "y_active" from the yelda container
|
|
1076
|
+
* - openChat() add y_active" to the yelda container
|
|
1077
|
+
*/
|
|
1078
|
+
if (shoulBeOpened && cantBeClosed) {
|
|
1079
|
+
this.webChatContainer.classList.add('y_active');
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1002
1083
|
/**
|
|
1003
1084
|
* Create iframeContainer and it's child webchat iframe, and add it to webChatContainer
|
|
1004
1085
|
* @param {String} url webchat url
|
|
@@ -1028,24 +1109,7 @@ var YeldaChat = function () {
|
|
|
1028
1109
|
classList += ' inner';
|
|
1029
1110
|
}
|
|
1030
1111
|
|
|
1031
|
-
|
|
1032
|
-
* add CSS class which controls the opacity of the frame container if the iframe:
|
|
1033
|
-
* - should be opened on load OR has a start button
|
|
1034
|
-
* - cannot be closed (canBeClosed explicitly set to false)
|
|
1035
|
-
*
|
|
1036
|
-
* If we are sure that the webchat should be opened and displayed all the time, we can add the y_active class right away
|
|
1037
|
-
* Otherwise,
|
|
1038
|
-
*/
|
|
1039
|
-
if ((data.shouldBeOpened || data.isStartBtn) && data.hasOwnProperty('canBeClosed') && !data.canBeClosed) {
|
|
1040
|
-
classList += ' y_active';
|
|
1041
|
-
} else {
|
|
1042
|
-
/**
|
|
1043
|
-
* If the iframe can be closed, hide it by default
|
|
1044
|
-
* yelda_assistant_img click event management will take care of showing and hiding the webchat
|
|
1045
|
-
* And if it should be opened, the webchat will trigger the 'openChat' event on its own
|
|
1046
|
-
*/
|
|
1047
|
-
this.iframeContainer.style.cssText = 'display: none;';
|
|
1048
|
-
}
|
|
1112
|
+
this.initWebChatContainerYActiveClass(data);
|
|
1049
1113
|
|
|
1050
1114
|
this.iframeContainer.setAttribute('class', classList);
|
|
1051
1115
|
this.webChatContainer.appendChild(this.iframeContainer);
|
|
@@ -1161,6 +1225,20 @@ var YeldaChat = function () {
|
|
|
1161
1225
|
// Triggered from webchat to listen leave viewport event
|
|
1162
1226
|
this.listenLeaveViewport();
|
|
1163
1227
|
break;
|
|
1228
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.LISTEN_URL_UPDATE:
|
|
1229
|
+
// Triggered from webchat to listen for url update
|
|
1230
|
+
this.listenUrlUpdate();
|
|
1231
|
+
break;
|
|
1232
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.ABSTAIN_URL_UPDATE:
|
|
1233
|
+
// Triggered form webchat to stop listening for url update
|
|
1234
|
+
this.listenUrlUpdate(true);
|
|
1235
|
+
break;
|
|
1236
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.ADD_BUBBLE_TEXT:
|
|
1237
|
+
// Triggered from webchat to add assistant bubble text if possible
|
|
1238
|
+
if (!this.configurationData.hasOwnProperty('canBeClosed') || this.configurationData.canBeClosed) {
|
|
1239
|
+
this.addAssistantBubbleText();
|
|
1240
|
+
}
|
|
1241
|
+
break;
|
|
1164
1242
|
}
|
|
1165
1243
|
return;
|
|
1166
1244
|
}
|
|
@@ -1187,6 +1265,11 @@ var YeldaChat = function () {
|
|
|
1187
1265
|
window.dispatchEvent(new CustomEvent('isSendingMessage', { detail: eventData.data }));
|
|
1188
1266
|
}
|
|
1189
1267
|
break;
|
|
1268
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.ADD_MINIMAL_NOTIFICATION_TEXT:
|
|
1269
|
+
if (!this.configurationData.hasOwnProperty('canBeClosed') || this.configurationData.canBeClosed) {
|
|
1270
|
+
this.addAssistantBubbleText(eventData.text, 'y_notification');
|
|
1271
|
+
}
|
|
1272
|
+
break;
|
|
1190
1273
|
}
|
|
1191
1274
|
}
|
|
1192
1275
|
|
|
@@ -1250,15 +1333,11 @@ var YeldaChat = function () {
|
|
|
1250
1333
|
}, {
|
|
1251
1334
|
key: 'closeChat',
|
|
1252
1335
|
value: function closeChat() {
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
var yeldaIframeContainerElement = document.getElementById('yelda_iframe_container');
|
|
1259
|
-
if (yeldaIframeContainerElement !== null) {
|
|
1260
|
-
yeldaIframeContainerElement.classList.remove('y_active');
|
|
1261
|
-
yeldaIframeContainerElement.style.display = 'none';
|
|
1336
|
+
// Closing the webchat = remove the y_active class on #yelda_container
|
|
1337
|
+
// Hiding the iframe + showing back the bubble + animation => All is done in CSS
|
|
1338
|
+
var yeldaContainerElement = document.getElementById('yelda_container');
|
|
1339
|
+
if (yeldaContainerElement !== null) {
|
|
1340
|
+
yeldaContainerElement.classList.remove('y_active');
|
|
1262
1341
|
}
|
|
1263
1342
|
}
|
|
1264
1343
|
|
|
@@ -1269,17 +1348,28 @@ var YeldaChat = function () {
|
|
|
1269
1348
|
}, {
|
|
1270
1349
|
key: 'openChat',
|
|
1271
1350
|
value: function openChat() {
|
|
1351
|
+
// Adding the class "activated" allows the CSS to change the transition/animation after the first opening
|
|
1272
1352
|
var assistantImgElement = document.getElementById('yelda_assistant_img');
|
|
1273
1353
|
if (assistantImgElement !== null) {
|
|
1274
|
-
assistantImgElement.
|
|
1354
|
+
assistantImgElement.classList.add('activated');
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// Opening the webchat = adding the y_active class on #yelda_container
|
|
1358
|
+
// Showing the iframe + hiding bubble + hiding minimal notification + animation => All is done in CSS
|
|
1359
|
+
var yeldaContainerElement = document.getElementById('yelda_container');
|
|
1360
|
+
if (yeldaContainerElement !== null) {
|
|
1361
|
+
yeldaContainerElement.classList.add('y_active');
|
|
1275
1362
|
}
|
|
1276
1363
|
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1364
|
+
// Hide the assistant bubble text while opening the webchat window
|
|
1365
|
+
// Note : bubble text container is also hidden in CSS
|
|
1366
|
+
if (this.assistantBubbleText) {
|
|
1367
|
+
this.assistantBubbleText = null;
|
|
1281
1368
|
}
|
|
1282
1369
|
|
|
1370
|
+
// Remove assistant bubble text while opening the webchat window
|
|
1371
|
+
this.removeElement('yelda_assistant_bubble_text');
|
|
1372
|
+
|
|
1283
1373
|
// Propagate the event to the webchat
|
|
1284
1374
|
document.getElementById('web_chat_frame').contentWindow.postMessage(_config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.SENT.OPEN_CHAT, '*');
|
|
1285
1375
|
}
|
|
@@ -1378,7 +1468,7 @@ var YeldaChat = function () {
|
|
|
1378
1468
|
}, _callee, _this2);
|
|
1379
1469
|
}));
|
|
1380
1470
|
|
|
1381
|
-
return function (
|
|
1471
|
+
return function (_x6) {
|
|
1382
1472
|
return _ref.apply(this, arguments);
|
|
1383
1473
|
};
|
|
1384
1474
|
}());
|
|
@@ -1641,11 +1731,14 @@ var YeldaChat = function () {
|
|
|
1641
1731
|
|
|
1642
1732
|
// Remove event listeners when switching bots
|
|
1643
1733
|
_this4.listenLeaveViewport(true);
|
|
1734
|
+
_this4.listenUrlUpdate(true);
|
|
1644
1735
|
|
|
1645
1736
|
_this4.loadChat(data);
|
|
1737
|
+
|
|
1738
|
+
_this4.configurationData = data;
|
|
1646
1739
|
return _context2.abrupt('return', resolve());
|
|
1647
1740
|
|
|
1648
|
-
case
|
|
1741
|
+
case 27:
|
|
1649
1742
|
case 'end':
|
|
1650
1743
|
return _context2.stop();
|
|
1651
1744
|
}
|
|
@@ -1653,7 +1746,7 @@ var YeldaChat = function () {
|
|
|
1653
1746
|
}, _callee2, _this4, [[12, 19]]);
|
|
1654
1747
|
}));
|
|
1655
1748
|
|
|
1656
|
-
return function (
|
|
1749
|
+
return function (_x7) {
|
|
1657
1750
|
return _ref2.apply(this, arguments);
|
|
1658
1751
|
};
|
|
1659
1752
|
}());
|
|
@@ -1774,7 +1867,6 @@ var YeldaChat = function () {
|
|
|
1774
1867
|
// because the assistant image containing the openChat event wouldn't have been created
|
|
1775
1868
|
if (!data.hasOwnProperty('canBeClosed') || data.canBeClosed) {
|
|
1776
1869
|
this.addAssistantImage();
|
|
1777
|
-
this.addAssistantBubbleText();
|
|
1778
1870
|
}
|
|
1779
1871
|
|
|
1780
1872
|
// add the frame lister to receive message from iframe to the parent
|
|
@@ -1795,7 +1887,7 @@ var YeldaChat = function () {
|
|
|
1795
1887
|
if (this.bubbleContainer) {
|
|
1796
1888
|
this.assistantImage.removeAttribute('id', 'yelda_assistant_img');
|
|
1797
1889
|
this.assistantImage.removeAttribute('class', 'yelda_assistant_img default');
|
|
1798
|
-
this.assistantImage.removeEventListener('click', this.openChat);
|
|
1890
|
+
this.assistantImage.removeEventListener('click', this.openChat.bind(this));
|
|
1799
1891
|
this.assistantImage.replaceWith(this.bubbleContainerClone);
|
|
1800
1892
|
} else {
|
|
1801
1893
|
this.removeElement('yelda_assistant_img');
|
|
@@ -1897,7 +1989,7 @@ var YeldaChat = function () {
|
|
|
1897
1989
|
}, _callee4, _this5);
|
|
1898
1990
|
}));
|
|
1899
1991
|
|
|
1900
|
-
return function (
|
|
1992
|
+
return function (_x8) {
|
|
1901
1993
|
return _ref4.apply(this, arguments);
|
|
1902
1994
|
};
|
|
1903
1995
|
}());
|
|
@@ -1917,6 +2009,55 @@ var YeldaChat = function () {
|
|
|
1917
2009
|
}
|
|
1918
2010
|
}
|
|
1919
2011
|
|
|
2012
|
+
/**
|
|
2013
|
+
* Listen to url update on the page
|
|
2014
|
+
* @param {Boolean} shouldRemoveEvent
|
|
2015
|
+
*/
|
|
2016
|
+
|
|
2017
|
+
}, {
|
|
2018
|
+
key: 'listenUrlUpdate',
|
|
2019
|
+
value: function listenUrlUpdate() {
|
|
2020
|
+
var _this6 = this;
|
|
2021
|
+
|
|
2022
|
+
var shouldRemoveEvent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
2023
|
+
|
|
2024
|
+
if (shouldRemoveEvent && this.urlObserver) {
|
|
2025
|
+
this.urlObserver.disconnect();
|
|
2026
|
+
this.urlObserver = null;
|
|
2027
|
+
return;
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
try {
|
|
2031
|
+
this.previousUrl = '';
|
|
2032
|
+
this.urlObserver = new MutationObserver(function () {
|
|
2033
|
+
if (location.href === _this6.previousUrl) {
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
_this6.previousUrl = location.href;
|
|
2037
|
+
_this6.urlUpdateListener();
|
|
2038
|
+
});
|
|
2039
|
+
|
|
2040
|
+
this.urlObserver.observe(document, { childList: true, subtree: true });
|
|
2041
|
+
} catch (err) {
|
|
2042
|
+
console.warn('listenUrlUpdate error', err);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
/**
|
|
2047
|
+
* Callback for url update listener
|
|
2048
|
+
*/
|
|
2049
|
+
|
|
2050
|
+
}, {
|
|
2051
|
+
key: 'urlUpdateListener',
|
|
2052
|
+
value: function urlUpdateListener() {
|
|
2053
|
+
var webchatFrame = document.getElementById('web_chat_frame');
|
|
2054
|
+
|
|
2055
|
+
if (!webchatFrame) {
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
webchatFrame.contentWindow.postMessage({ event: _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.SENT.URL_UPDATE, data: window.location.href }, '*');
|
|
2059
|
+
}
|
|
2060
|
+
|
|
1920
2061
|
/**
|
|
1921
2062
|
* Listen leave viewport event handling
|
|
1922
2063
|
* @param {Boolean} shouldRemoveEvent - default false
|
|
@@ -2470,7 +2611,8 @@ module.exports = {
|
|
|
2470
2611
|
SENT: {
|
|
2471
2612
|
OPEN_CHAT: 'openChat',
|
|
2472
2613
|
LEAVE_VIEWPORT: 'leaveViewPort',
|
|
2473
|
-
SEND_USER_MESSAGE: 'sendUserMessage'
|
|
2614
|
+
SEND_USER_MESSAGE: 'sendUserMessage',
|
|
2615
|
+
URL_UPDATE: 'urlUpdate'
|
|
2474
2616
|
},
|
|
2475
2617
|
RECEIVED: {
|
|
2476
2618
|
OPEN_CHAT: 'openChat',
|
|
@@ -2478,7 +2620,11 @@ module.exports = {
|
|
|
2478
2620
|
ABSTAIN_LEAVE_VIEWPORT: 'abstainLeaveViewport',
|
|
2479
2621
|
OPEN_LIGHT_GALLERY: 'openLightGallery',
|
|
2480
2622
|
IS_SENDING_MESSAGE: 'isSendingMessage',
|
|
2481
|
-
LISTEN_LEAVE_VIEWPORT: 'listenLeaveViewport'
|
|
2623
|
+
LISTEN_LEAVE_VIEWPORT: 'listenLeaveViewport',
|
|
2624
|
+
LISTEN_URL_UPDATE: 'listenUrlUpdate',
|
|
2625
|
+
ABSTAIN_URL_UPDATE: 'abstainUrlUpdate',
|
|
2626
|
+
ADD_BUBBLE_TEXT: 'addBubbleText',
|
|
2627
|
+
ADD_MINIMAL_NOTIFICATION_TEXT: 'addMinimalNotificationText'
|
|
2482
2628
|
}
|
|
2483
2629
|
}
|
|
2484
2630
|
};
|