yelda-webchat 1.1.2 → 1.1.7
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/README.md +3 -1
- package/dist/css/yeldaWebchatInjector.css +51 -0
- package/dist/css/yeldaWebchatInjector.min.css +6 -0
- package/dist/css/yeldaWebchatInjector.min.css.map +1 -1
- package/dist/js/yeldaWebchatInjector.js +288 -57
- package/dist/js/yeldaWebchatInjector.js.map +1 -1
- package/dist/js/yeldaWebchatInjector.min.js +2 -2
- package/package.json +2 -2
- package/src/config/index.js +20 -0
- package/src/css/yeldaWebchatInjector.css +51 -0
- package/src/js/yeldaWebchatInjector.js +223 -40
- package/uploadBuildToS3.js +11 -4
|
@@ -776,7 +776,7 @@ var YeldaChat = function () {
|
|
|
776
776
|
* get Specific parameter from the url
|
|
777
777
|
* @param {*} parameter
|
|
778
778
|
* @param {*} defaultValue, default empty string
|
|
779
|
-
* @return {String}
|
|
779
|
+
* @return {String} urlParameter
|
|
780
780
|
*/
|
|
781
781
|
|
|
782
782
|
}, {
|
|
@@ -823,22 +823,28 @@ 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
|
|
826
827
|
*/
|
|
827
828
|
|
|
828
829
|
}, {
|
|
829
830
|
key: 'addAssistantBubbleText',
|
|
830
831
|
value: function addAssistantBubbleText() {
|
|
831
|
-
|
|
832
|
+
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
833
|
+
|
|
834
|
+
text = text || this.webchatSettings && this.webchatSettings.bubbleText;
|
|
835
|
+
if (!this.webChatContainer || !text) {
|
|
832
836
|
return;
|
|
833
837
|
}
|
|
834
838
|
|
|
839
|
+
// Remove the assistant bubble text element before adding a new one
|
|
840
|
+
this.removeElement('yelda_assistant_bubble_text');
|
|
835
841
|
// create assistantBubbleText element and set the text
|
|
836
842
|
this.assistantBubbleText = document.createElement('span');
|
|
837
843
|
this.assistantBubbleText.setAttribute('id', 'yelda_assistant_bubble_text');
|
|
838
|
-
this.assistantBubbleText.innerText = this.webchatSettings.bubbleText;
|
|
844
|
+
this.assistantBubbleText.innerText = text || this.webchatSettings.bubbleText;
|
|
839
845
|
|
|
840
846
|
// Add click event to assistant text
|
|
841
|
-
this.assistantBubbleText.addEventListener('click', this.openChat);
|
|
847
|
+
this.assistantBubbleText.addEventListener('click', this.openChat.bind(this));
|
|
842
848
|
|
|
843
849
|
// add assistant text to webChatContainer using the webchatSettings
|
|
844
850
|
this.webChatContainer.appendChild(this.assistantBubbleText);
|
|
@@ -878,7 +884,7 @@ var YeldaChat = function () {
|
|
|
878
884
|
this.assistantImage.innerHTML = '<i class="fas fa-comment"></i>';
|
|
879
885
|
|
|
880
886
|
// Add click event to assistant image
|
|
881
|
-
this.assistantImage.addEventListener('click', this.openChat);
|
|
887
|
+
this.assistantImage.addEventListener('click', this.openChat.bind(this));
|
|
882
888
|
|
|
883
889
|
// add assistantImage to webChatContainer using the webchatSettings
|
|
884
890
|
this.updateAssistantImageWithAssistantSettings();
|
|
@@ -1031,7 +1037,7 @@ var YeldaChat = function () {
|
|
|
1031
1037
|
/**
|
|
1032
1038
|
* add CSS class which controls the opacity of the frame container if the iframe:
|
|
1033
1039
|
* - should be opened on load OR has a start button
|
|
1034
|
-
* - cannot be closed (canBeClosed
|
|
1040
|
+
* - cannot be closed (canBeClosed explicitly set to false)
|
|
1035
1041
|
*
|
|
1036
1042
|
* 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
1043
|
* Otherwise,
|
|
@@ -1126,7 +1132,7 @@ var YeldaChat = function () {
|
|
|
1126
1132
|
}
|
|
1127
1133
|
|
|
1128
1134
|
/**
|
|
1129
|
-
* Handles
|
|
1135
|
+
* Handles communication between parent window and iframe, mainly for open and closing the chat
|
|
1130
1136
|
* handles also the chat bubble style
|
|
1131
1137
|
* @param {event} event
|
|
1132
1138
|
*/
|
|
@@ -1134,36 +1140,76 @@ var YeldaChat = function () {
|
|
|
1134
1140
|
}, {
|
|
1135
1141
|
key: 'messageListener',
|
|
1136
1142
|
value: function messageListener(event) {
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
if (event.data === 'openChat' || event.message === 'openChat') {
|
|
1143
|
-
this.openChat();
|
|
1143
|
+
// event.message is only there to support IE11.
|
|
1144
|
+
var eventData = event.data || event.message;
|
|
1145
|
+
if (!eventData) {
|
|
1144
1146
|
return;
|
|
1145
1147
|
}
|
|
1146
1148
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1149
|
+
/*
|
|
1150
|
+
* Simple event management parent.postMessage('string message')
|
|
1151
|
+
*/
|
|
1152
|
+
if (!eventData.event) {
|
|
1153
|
+
switch (eventData) {
|
|
1154
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.OPEN_CHAT:
|
|
1155
|
+
// 'openChat' event triggered from webchat
|
|
1156
|
+
this.openChat();
|
|
1157
|
+
break;
|
|
1158
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.CLOSE_CHAT:
|
|
1159
|
+
// 'closeChat' event triggered from webchat
|
|
1160
|
+
this.closeChat();
|
|
1161
|
+
break;
|
|
1162
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.ABSTAIN_LEAVE_VIEWPORT:
|
|
1163
|
+
// 'abstainLeaveViewport' event triggered from webchat to stop listening to the leave viewport event
|
|
1164
|
+
this.listenLeaveViewport(true);
|
|
1165
|
+
break;
|
|
1166
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.LISTEN_LEAVE_VIEWPORT:
|
|
1167
|
+
// Triggered from webchat to listen leave viewport event
|
|
1168
|
+
this.listenLeaveViewport();
|
|
1169
|
+
break;
|
|
1170
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.LISTEN_URL_UPDATE:
|
|
1171
|
+
// Triggered from webchat to listen for url update
|
|
1172
|
+
this.listenUrlUpdate();
|
|
1173
|
+
break;
|
|
1174
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.ABSTAIN_URL_UPDATE:
|
|
1175
|
+
// Triggered form webchat to stop listening for url update
|
|
1176
|
+
this.listenUrlUpdate(true);
|
|
1177
|
+
break;
|
|
1178
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.ADD_BUBBLE_TEXT:
|
|
1179
|
+
// Triggered from webchat to add assistant bubble text if possible
|
|
1180
|
+
if (!this.configurationData.hasOwnProperty('canBeClosed') || this.configurationData.canBeClosed) {
|
|
1181
|
+
this.addAssistantBubbleText();
|
|
1182
|
+
}
|
|
1183
|
+
break;
|
|
1150
1184
|
}
|
|
1151
|
-
|
|
1152
|
-
this.handleLightGallery(event.data);
|
|
1153
1185
|
return;
|
|
1154
1186
|
}
|
|
1155
1187
|
|
|
1156
|
-
|
|
1157
|
-
*
|
|
1158
|
-
* If isSendingMessage data is true, it means that a user message has already been sent to the webchat and
|
|
1159
|
-
* is still waiting for an answer
|
|
1160
|
-
* If isSendingMessage data is false, the webchat is ready to receive new user messages
|
|
1188
|
+
/*
|
|
1189
|
+
* Complex event management parent.postMessage({ event: 'xxxx', data: yyyy })
|
|
1161
1190
|
*/
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1191
|
+
switch (eventData.event) {
|
|
1192
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.OPEN_LIGHT_GALLERY:
|
|
1193
|
+
if (!eventData.mediaSources || !eventData.mediaSources.length) {
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
this.handleLightGallery(eventData);
|
|
1198
|
+
break;
|
|
1199
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.IS_SENDING_MESSAGE:
|
|
1200
|
+
/**
|
|
1201
|
+
* Custom event to send to Yelda to keep track of the webchat ability to receive a new message
|
|
1202
|
+
* If isSendingMessage data is true, it means that a user message has already been sent to the webchat and
|
|
1203
|
+
* is still waiting for an answer
|
|
1204
|
+
* If isSendingMessage data is false, the webchat is ready to receive new user messages
|
|
1205
|
+
*/
|
|
1206
|
+
if (eventData.hasOwnProperty('data')) {
|
|
1207
|
+
window.dispatchEvent(new CustomEvent('isSendingMessage', { detail: eventData.data }));
|
|
1208
|
+
}
|
|
1209
|
+
break;
|
|
1210
|
+
case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.ADD_MINIMAL_NOTIFICATION_TEXT:
|
|
1211
|
+
this.addAssistantBubbleText(eventData.text);
|
|
1212
|
+
break;
|
|
1167
1213
|
}
|
|
1168
1214
|
}
|
|
1169
1215
|
|
|
@@ -1257,8 +1303,16 @@ var YeldaChat = function () {
|
|
|
1257
1303
|
yeldaIframeContainerElement.classList.add('y_active');
|
|
1258
1304
|
}
|
|
1259
1305
|
|
|
1306
|
+
// hide the assistant bubble text while opening the webchat window
|
|
1307
|
+
if (this.assistantBubbleText) {
|
|
1308
|
+
this.assistantBubbleText = null;
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
// Remove assistant bubble text while opening the webchat window
|
|
1312
|
+
this.removeElement('yelda_assistant_bubble_text');
|
|
1313
|
+
|
|
1260
1314
|
// Propagate the event to the webchat
|
|
1261
|
-
document.getElementById('web_chat_frame').contentWindow.postMessage(
|
|
1315
|
+
document.getElementById('web_chat_frame').contentWindow.postMessage(_config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.SENT.OPEN_CHAT, '*');
|
|
1262
1316
|
}
|
|
1263
1317
|
|
|
1264
1318
|
/**
|
|
@@ -1288,7 +1342,7 @@ var YeldaChat = function () {
|
|
|
1288
1342
|
}
|
|
1289
1343
|
|
|
1290
1344
|
/**
|
|
1291
|
-
* Load CSS
|
|
1345
|
+
* Load CSS asynchronously
|
|
1292
1346
|
*/
|
|
1293
1347
|
|
|
1294
1348
|
}, {
|
|
@@ -1305,7 +1359,7 @@ var YeldaChat = function () {
|
|
|
1305
1359
|
}
|
|
1306
1360
|
|
|
1307
1361
|
/**
|
|
1308
|
-
*
|
|
1362
|
+
* Generate webchatURL and create webchatIframe
|
|
1309
1363
|
* @param {Object} data { chatUrl, assistantId, assistantSlug, shouldBeOpened, isStartBtn, canBeClosed }
|
|
1310
1364
|
*/
|
|
1311
1365
|
|
|
@@ -1355,7 +1409,7 @@ var YeldaChat = function () {
|
|
|
1355
1409
|
}, _callee, _this2);
|
|
1356
1410
|
}));
|
|
1357
1411
|
|
|
1358
|
-
return function (
|
|
1412
|
+
return function (_x5) {
|
|
1359
1413
|
return _ref.apply(this, arguments);
|
|
1360
1414
|
};
|
|
1361
1415
|
}());
|
|
@@ -1498,10 +1552,10 @@ var YeldaChat = function () {
|
|
|
1498
1552
|
}
|
|
1499
1553
|
|
|
1500
1554
|
/**
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1555
|
+
* return getAssistantSettings endpoint URL from data
|
|
1556
|
+
* @param {Object} data { assistantUrl, assistantId, settingId }
|
|
1557
|
+
* @return {String} url
|
|
1558
|
+
*/
|
|
1505
1559
|
|
|
1506
1560
|
}, {
|
|
1507
1561
|
key: 'getAssistantSettingsUrl',
|
|
@@ -1587,41 +1641,53 @@ var YeldaChat = function () {
|
|
|
1587
1641
|
return _context2.abrupt('return', resolve());
|
|
1588
1642
|
|
|
1589
1643
|
case 9:
|
|
1590
|
-
|
|
1591
|
-
|
|
1644
|
+
|
|
1645
|
+
// These data will be needed to avoid loading outdated data in the chat (in case of multiple chat load requests)
|
|
1646
|
+
_this4.assistantId = data.assistantId;
|
|
1647
|
+
_this4.locale = data.locale;
|
|
1648
|
+
_this4.settingId = data.settingId;
|
|
1649
|
+
|
|
1650
|
+
// Get assistant settings from backend
|
|
1651
|
+
_context2.prev = 12;
|
|
1652
|
+
_context2.next = 15;
|
|
1592
1653
|
return _this4.getAssistantSettings(data);
|
|
1593
1654
|
|
|
1594
|
-
case
|
|
1655
|
+
case 15:
|
|
1595
1656
|
_this4.webchatSettings = _context2.sent;
|
|
1596
1657
|
|
|
1597
|
-
|
|
1598
1658
|
// Webchat can be loaded thanks to a single settingId or group of data : {assistantId, assistantSlug, locale}
|
|
1599
1659
|
// If only settingId is provided, then we will fill {assistantId, assistantSlug, locale} thanks to the assistant settings
|
|
1600
1660
|
data = _this4.updateAssistantData(data, _this4.webchatSettings);
|
|
1601
1661
|
|
|
1602
|
-
_context2.next =
|
|
1662
|
+
_context2.next = 22;
|
|
1603
1663
|
break;
|
|
1604
1664
|
|
|
1605
|
-
case
|
|
1606
|
-
_context2.prev =
|
|
1607
|
-
_context2.t0 = _context2['catch'](
|
|
1665
|
+
case 19:
|
|
1666
|
+
_context2.prev = 19;
|
|
1667
|
+
_context2.t0 = _context2['catch'](12);
|
|
1608
1668
|
|
|
1609
1669
|
_this4.webchatSettings = null;
|
|
1610
1670
|
|
|
1611
|
-
case
|
|
1671
|
+
case 22:
|
|
1672
|
+
|
|
1673
|
+
// Remove event listeners when switching bots
|
|
1674
|
+
_this4.listenLeaveViewport(true);
|
|
1675
|
+
_this4.listenUrlUpdate(true);
|
|
1612
1676
|
|
|
1613
1677
|
_this4.loadChat(data);
|
|
1678
|
+
|
|
1679
|
+
_this4.configurationData = data;
|
|
1614
1680
|
return _context2.abrupt('return', resolve());
|
|
1615
1681
|
|
|
1616
|
-
case
|
|
1682
|
+
case 27:
|
|
1617
1683
|
case 'end':
|
|
1618
1684
|
return _context2.stop();
|
|
1619
1685
|
}
|
|
1620
1686
|
}
|
|
1621
|
-
}, _callee2, _this4, [[
|
|
1687
|
+
}, _callee2, _this4, [[12, 19]]);
|
|
1622
1688
|
}));
|
|
1623
1689
|
|
|
1624
|
-
return function (
|
|
1690
|
+
return function (_x6) {
|
|
1625
1691
|
return _ref2.apply(this, arguments);
|
|
1626
1692
|
};
|
|
1627
1693
|
}());
|
|
@@ -1643,7 +1709,9 @@ var YeldaChat = function () {
|
|
|
1643
1709
|
return false;
|
|
1644
1710
|
}
|
|
1645
1711
|
|
|
1646
|
-
// if webchatSettings is null
|
|
1712
|
+
// if webchatSettings is null, it means that the admins didn't created custom webchat settings or
|
|
1713
|
+
// or that the API call to get the settings failed
|
|
1714
|
+
// In this case we can still load the webchat with the default settings
|
|
1647
1715
|
if (!webchatSettings) {
|
|
1648
1716
|
return true;
|
|
1649
1717
|
}
|
|
@@ -1662,14 +1730,57 @@ var YeldaChat = function () {
|
|
|
1662
1730
|
return true;
|
|
1663
1731
|
}
|
|
1664
1732
|
|
|
1733
|
+
/**
|
|
1734
|
+
* Return if the webchat loadChat settings are different from the yeldaChat global assistant settings
|
|
1735
|
+
*
|
|
1736
|
+
* - yeldaChat can be init (and reset) either with the settingId parameter or the pair (assistantId, locale) that we store globally
|
|
1737
|
+
* - Each new webchat loading request implies a "getAssistantSettings" async API call,
|
|
1738
|
+
* => If multiple new webchat loading requests are done in a short amount of time,
|
|
1739
|
+
* "getAssistantSettings" response can be subject to a race condition issue:
|
|
1740
|
+
* The latest requested answer received might not be the latest API call answer.
|
|
1741
|
+
*
|
|
1742
|
+
* isDataOutdated checks if one of the global parameter is different the ones from the webchat settings we got from the "getAssistantSettings" API call
|
|
1743
|
+
* so the "loadChat" function can be informed that the latest request is not the one currently handled
|
|
1744
|
+
* And can stop the current process to let the chat load with the global latest requested settings
|
|
1745
|
+
*
|
|
1746
|
+
* @param {Object} webchatSettings - current settings from the reset or init yeldaChat request
|
|
1747
|
+
* @param {String} webchatSettings.settingId
|
|
1748
|
+
* @param {String} webchatSettings.assistantId
|
|
1749
|
+
* @param {String} webchatSettings.locale
|
|
1750
|
+
* @param {Object} globalData - latest globally stored settings from the reset or init yeldaChat request
|
|
1751
|
+
* @param {String} globalData.settingId
|
|
1752
|
+
* @param {String} globalData.assistantId
|
|
1753
|
+
* @param {String} globalData.locale
|
|
1754
|
+
* @returns {Boolean}
|
|
1755
|
+
*/
|
|
1756
|
+
|
|
1757
|
+
}, {
|
|
1758
|
+
key: 'isDataOutdated',
|
|
1759
|
+
value: function isDataOutdated(data, _ref3) {
|
|
1760
|
+
var settingId = _ref3.settingId,
|
|
1761
|
+
assistantId = _ref3.assistantId,
|
|
1762
|
+
locale = _ref3.locale;
|
|
1763
|
+
|
|
1764
|
+
if (data.settingId && data.settingId !== settingId) {
|
|
1765
|
+
return true;
|
|
1766
|
+
}
|
|
1767
|
+
if (!data.settingId && (data.assistantId !== assistantId || data.locale !== locale)) {
|
|
1768
|
+
return true;
|
|
1769
|
+
}
|
|
1770
|
+
return false;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1665
1773
|
/**
|
|
1666
1774
|
* Load the chat after getting the webchat settings if publication is enabled
|
|
1667
|
-
* @param {Object} data { data.assistantUrl, data.assistantId }
|
|
1775
|
+
* @param {Object} data { data.assistantUrl, data.assistantId, data.locale }
|
|
1668
1776
|
*/
|
|
1669
1777
|
|
|
1670
1778
|
}, {
|
|
1671
1779
|
key: 'loadChat',
|
|
1672
1780
|
value: function loadChat(data) {
|
|
1781
|
+
if (this.isDataOutdated(data, this)) {
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1673
1784
|
if (!this.shouldChatBeLoaded(this.webchatSettings, data)) {
|
|
1674
1785
|
this.unLoadChat();
|
|
1675
1786
|
return;
|
|
@@ -1697,7 +1808,6 @@ var YeldaChat = function () {
|
|
|
1697
1808
|
// because the assistant image containing the openChat event wouldn't have been created
|
|
1698
1809
|
if (!data.hasOwnProperty('canBeClosed') || data.canBeClosed) {
|
|
1699
1810
|
this.addAssistantImage();
|
|
1700
|
-
this.addAssistantBubbleText();
|
|
1701
1811
|
}
|
|
1702
1812
|
|
|
1703
1813
|
// add the frame lister to receive message from iframe to the parent
|
|
@@ -1718,7 +1828,7 @@ var YeldaChat = function () {
|
|
|
1718
1828
|
if (this.bubbleContainer) {
|
|
1719
1829
|
this.assistantImage.removeAttribute('id', 'yelda_assistant_img');
|
|
1720
1830
|
this.assistantImage.removeAttribute('class', 'yelda_assistant_img default');
|
|
1721
|
-
this.assistantImage.removeEventListener('click', this.openChat);
|
|
1831
|
+
this.assistantImage.removeEventListener('click', this.openChat.bind(this));
|
|
1722
1832
|
this.assistantImage.replaceWith(this.bubbleContainerClone);
|
|
1723
1833
|
} else {
|
|
1724
1834
|
this.removeElement('yelda_assistant_img');
|
|
@@ -1766,7 +1876,7 @@ var YeldaChat = function () {
|
|
|
1766
1876
|
var _this5 = this;
|
|
1767
1877
|
|
|
1768
1878
|
return new babel_runtime_core_js_promise__WEBPACK_IMPORTED_MODULE_2___default.a(function () {
|
|
1769
|
-
var
|
|
1879
|
+
var _ref4 = babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()( /*#__PURE__*/babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.mark(function _callee4(resolve) {
|
|
1770
1880
|
return babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.wrap(function _callee4$(_context4) {
|
|
1771
1881
|
while (1) {
|
|
1772
1882
|
switch (_context4.prev = _context4.next) {
|
|
@@ -1820,8 +1930,8 @@ var YeldaChat = function () {
|
|
|
1820
1930
|
}, _callee4, _this5);
|
|
1821
1931
|
}));
|
|
1822
1932
|
|
|
1823
|
-
return function (
|
|
1824
|
-
return
|
|
1933
|
+
return function (_x7) {
|
|
1934
|
+
return _ref4.apply(this, arguments);
|
|
1825
1935
|
};
|
|
1826
1936
|
}());
|
|
1827
1937
|
}
|
|
@@ -1836,9 +1946,110 @@ var YeldaChat = function () {
|
|
|
1836
1946
|
var webchatFrame = document.getElementById('web_chat_frame');
|
|
1837
1947
|
if (webchatFrame) {
|
|
1838
1948
|
this.openChat();
|
|
1839
|
-
webchatFrame.contentWindow.postMessage({ event:
|
|
1949
|
+
webchatFrame.contentWindow.postMessage({ event: _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.SENT.SEND_USER_MESSAGE, data: message });
|
|
1840
1950
|
}
|
|
1841
1951
|
}
|
|
1952
|
+
|
|
1953
|
+
/**
|
|
1954
|
+
* Listen to url update on the page
|
|
1955
|
+
* @param {Boolean} shouldRemoveEvent
|
|
1956
|
+
*/
|
|
1957
|
+
|
|
1958
|
+
}, {
|
|
1959
|
+
key: 'listenUrlUpdate',
|
|
1960
|
+
value: function listenUrlUpdate() {
|
|
1961
|
+
var _this6 = this;
|
|
1962
|
+
|
|
1963
|
+
var shouldRemoveEvent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1964
|
+
|
|
1965
|
+
if (shouldRemoveEvent && this.urlObserver) {
|
|
1966
|
+
this.urlObserver.disconnect();
|
|
1967
|
+
this.urlObserver = null;
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
try {
|
|
1972
|
+
this.previousUrl = '';
|
|
1973
|
+
this.urlObserver = new MutationObserver(function () {
|
|
1974
|
+
if (location.href === _this6.previousUrl) {
|
|
1975
|
+
return;
|
|
1976
|
+
}
|
|
1977
|
+
_this6.previousUrl = location.href;
|
|
1978
|
+
_this6.urlUpdateListener();
|
|
1979
|
+
});
|
|
1980
|
+
|
|
1981
|
+
this.urlObserver.observe(document, { childList: true, subtree: true });
|
|
1982
|
+
} catch (err) {
|
|
1983
|
+
console.warn('listenUrlUpdate error', err);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
/**
|
|
1988
|
+
* Callback for url update listener
|
|
1989
|
+
*/
|
|
1990
|
+
|
|
1991
|
+
}, {
|
|
1992
|
+
key: 'urlUpdateListener',
|
|
1993
|
+
value: function urlUpdateListener() {
|
|
1994
|
+
var webchatFrame = document.getElementById('web_chat_frame');
|
|
1995
|
+
|
|
1996
|
+
if (!webchatFrame) {
|
|
1997
|
+
return;
|
|
1998
|
+
}
|
|
1999
|
+
webchatFrame.contentWindow.postMessage({ event: _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.SENT.URL_UPDATE, data: window.location.href }, '*');
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
/**
|
|
2003
|
+
* Listen leave viewport event handling
|
|
2004
|
+
* @param {Boolean} shouldRemoveEvent - default false
|
|
2005
|
+
*/
|
|
2006
|
+
|
|
2007
|
+
}, {
|
|
2008
|
+
key: 'listenLeaveViewport',
|
|
2009
|
+
value: function listenLeaveViewport() {
|
|
2010
|
+
var shouldRemoveEvent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
2011
|
+
|
|
2012
|
+
var md = new mobile_detect__WEBPACK_IMPORTED_MODULE_7___default.a(navigator.userAgent);
|
|
2013
|
+
var isMobile = md.mobile() !== null;
|
|
2014
|
+
|
|
2015
|
+
/**
|
|
2016
|
+
* Not needed to listen on mobile since webchat covers the full page of the site
|
|
2017
|
+
* and we can't able to detect mouseout events
|
|
2018
|
+
*/
|
|
2019
|
+
if (isMobile) {
|
|
2020
|
+
return;
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
var eventHandler = window[shouldRemoveEvent ? 'removeEventListener' : 'addEventListener'];
|
|
2024
|
+
|
|
2025
|
+
if (!this.viewportListenerBind) {
|
|
2026
|
+
this.viewportListenerBind = this.viewportListener.bind(this);
|
|
2027
|
+
}
|
|
2028
|
+
// mouseout event is used to listen leave viewport
|
|
2029
|
+
eventHandler('mouseout', this.viewportListenerBind);
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
/**
|
|
2033
|
+
* Callback for leave viewport listener
|
|
2034
|
+
* @param {Event} event
|
|
2035
|
+
*/
|
|
2036
|
+
|
|
2037
|
+
}, {
|
|
2038
|
+
key: 'viewportListener',
|
|
2039
|
+
value: function viewportListener(event) {
|
|
2040
|
+
/**
|
|
2041
|
+
* when mouse moves between dom elements mouseout event is trigged but we need to trigger
|
|
2042
|
+
* the event when mouse moves out of the viewport so toElement and relatedTarget is checked
|
|
2043
|
+
*/
|
|
2044
|
+
if (event.toElement || event.relatedTarget) {
|
|
2045
|
+
return;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
// When mouse leaves the viewport send 'leaveViewPort' to webchat
|
|
2049
|
+
document.getElementById('web_chat_frame').contentWindow.postMessage({
|
|
2050
|
+
event: _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.SENT.LEAVE_VIEWPORT
|
|
2051
|
+
}, '*');
|
|
2052
|
+
}
|
|
1842
2053
|
}]);
|
|
1843
2054
|
|
|
1844
2055
|
return YeldaChat;
|
|
@@ -2335,6 +2546,26 @@ module.exports = {
|
|
|
2335
2546
|
HOST: {
|
|
2336
2547
|
PRODUCTION: 'app.yelda.ai',
|
|
2337
2548
|
STAGING: 'staging.yelda.ai'
|
|
2549
|
+
},
|
|
2550
|
+
FRAME_EVENT_TYPES: {
|
|
2551
|
+
SENT: {
|
|
2552
|
+
OPEN_CHAT: 'openChat',
|
|
2553
|
+
LEAVE_VIEWPORT: 'leaveViewPort',
|
|
2554
|
+
SEND_USER_MESSAGE: 'sendUserMessage',
|
|
2555
|
+
URL_UPDATE: 'urlUpdate'
|
|
2556
|
+
},
|
|
2557
|
+
RECEIVED: {
|
|
2558
|
+
OPEN_CHAT: 'openChat',
|
|
2559
|
+
CLOSE_CHAT: 'closeChat',
|
|
2560
|
+
ABSTAIN_LEAVE_VIEWPORT: 'abstainLeaveViewport',
|
|
2561
|
+
OPEN_LIGHT_GALLERY: 'openLightGallery',
|
|
2562
|
+
IS_SENDING_MESSAGE: 'isSendingMessage',
|
|
2563
|
+
LISTEN_LEAVE_VIEWPORT: 'listenLeaveViewport',
|
|
2564
|
+
LISTEN_URL_UPDATE: 'listenUrlUpdate',
|
|
2565
|
+
ABSTAIN_URL_UPDATE: 'abstainUrlUpdate',
|
|
2566
|
+
ADD_BUBBLE_TEXT: 'addBubbleText',
|
|
2567
|
+
ADD_MINIMAL_NOTIFICATION_TEXT: 'addMinimalNotificationText'
|
|
2568
|
+
}
|
|
2338
2569
|
}
|
|
2339
2570
|
};
|
|
2340
2571
|
|