@defra/flood-webchat 0.0.1-beta.16 → 0.0.1-beta.18

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/client.js CHANGED
@@ -26,7 +26,8 @@ function Availability() {
26
26
  availability,
27
27
  messages,
28
28
  isChatOpen,
29
- setChatVisibility
29
+ setChatVisibility,
30
+ unseenCount
30
31
  } = (0,_store_useApp__WEBPACK_IMPORTED_MODULE_3__.useApp)();
31
32
  const [isFixed, setIsFixed] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false);
32
33
  const buttonRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
@@ -84,7 +85,9 @@ function Availability() {
84
85
  onClick: onClick,
85
86
  onKeyUp: onKeyUp,
86
87
  onKeyDown: onKeyDown
87
- }, TextComponent))), isChatOpen && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_jsx__WEBPACK_IMPORTED_MODULE_2__.Panel, null));
88
+ }, TextComponent, unseenCount > 0 && !isChatOpen ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", {
89
+ className: "wc-open-btn__unseen"
90
+ }, unseenCount) : null))), isChatOpen && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_jsx__WEBPACK_IMPORTED_MODULE_2__.Panel, null));
88
91
  case 'EXISTING':
89
92
  case 'UNAVAILABLE':
90
93
  return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
@@ -128,7 +131,8 @@ __webpack_require__.r(__webpack_exports__);
128
131
 
129
132
 
130
133
  function Chat({
131
- onEndChat
134
+ onEndChat,
135
+ onSettings
132
136
  }) {
133
137
  const {
134
138
  availability,
@@ -136,13 +140,14 @@ function Chat({
136
140
  messages,
137
141
  agent,
138
142
  agentStatus,
139
- isAgentTyping
143
+ isAgentTyping,
144
+ settings
140
145
  } = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_5__.useApp)();
141
146
  const [userMessage, setUserMessage] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)('');
142
147
  const messageRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
143
148
  (0,_hooks_useTextareaAutosize_js__WEBPACK_IMPORTED_MODULE_6__.useTextareaAutosize)(messageRef.current, userMessage);
144
149
  (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
145
- if (messages.length !== 0) {
150
+ if (settings.scroll && messages.length !== 0) {
146
151
  const chatBody = document.querySelector('.wc-body');
147
152
  chatBody.scrollTop = chatBody.scrollHeight;
148
153
  }
@@ -268,8 +273,10 @@ function Chat({
268
273
  className: "wc-footer__settings"
269
274
  }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
270
275
  href: "#",
276
+ id: "wc-settings",
271
277
  className: "wc-footer__settings-link",
272
- "data-module": "govuk-button"
278
+ "data-module": "govuk-button",
279
+ onClick: onSettings
273
280
  }, "Settings"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
274
281
  href: "#",
275
282
  id: "transcript-download",
@@ -406,11 +413,14 @@ __webpack_require__.r(__webpack_exports__);
406
413
  function PanelHeader() {
407
414
  const {
408
415
  thread,
409
- setChatVisibility
416
+ setChatVisibility,
417
+ setUnseenCount
410
418
  } = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_1__.useApp)();
411
419
  const onClose = e => {
412
420
  e.preventDefault();
413
421
  setChatVisibility(false);
422
+ thread.lastMessageSeen();
423
+ setUnseenCount(0);
414
424
  };
415
425
  let ButtonComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
416
426
  className: "wc-header__close",
@@ -471,9 +481,11 @@ __webpack_require__.r(__webpack_exports__);
471
481
  /* harmony import */ var _chat_chat_jsx__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../chat/chat.jsx */ "./src/client/components/chat/chat.jsx");
472
482
  /* harmony import */ var _screens_unavailable_jsx__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../screens/unavailable.jsx */ "./src/client/components/screens/unavailable.jsx");
473
483
  /* harmony import */ var _screens_end_chat_jsx__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../screens/end-chat.jsx */ "./src/client/components/screens/end-chat.jsx");
474
- /* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
475
- /* harmony import */ var _store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../store/useChatSdk.js */ "./src/client/store/useChatSdk.js");
476
- /* harmony import */ var _hooks_useFocusedElements_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../hooks/useFocusedElements.js */ "./src/client/hooks/useFocusedElements.js");
484
+ /* harmony import */ var _screens_settings_jsx__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../screens/settings.jsx */ "./src/client/components/screens/settings.jsx");
485
+ /* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
486
+ /* harmony import */ var _store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../store/useChatSdk.js */ "./src/client/store/useChatSdk.js");
487
+ /* harmony import */ var _hooks_useFocusedElements_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../hooks/useFocusedElements.js */ "./src/client/hooks/useFocusedElements.js");
488
+
477
489
 
478
490
 
479
491
 
@@ -493,14 +505,15 @@ function Panel() {
493
505
  setThread,
494
506
  setThreadId,
495
507
  setChatVisibility,
496
- setMessages
497
- } = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_7__.useApp)();
508
+ setMessages,
509
+ setUnseenCount
510
+ } = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_8__.useApp)();
498
511
  const {
499
512
  fetchThread,
500
513
  fetchMessages
501
- } = (0,_store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_8__.useChatSdk)(sdk);
514
+ } = (0,_store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_9__.useChatSdk)(sdk);
502
515
  const [screen, setScreen] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(threadId ? 2 : 0);
503
- (0,_hooks_useFocusedElements_js__WEBPACK_IMPORTED_MODULE_9__.useFocusedElements)(screen);
516
+ (0,_hooks_useFocusedElements_js__WEBPACK_IMPORTED_MODULE_10__.useFocusedElements)(screen);
504
517
 
505
518
  /**
506
519
  * Initializes the eventListener for pressing the escape key
@@ -530,7 +543,13 @@ function Panel() {
530
543
  }
531
544
  };
532
545
  if (threadId) {
533
- thread ? setScreen(2) : recover();
546
+ if (thread) {
547
+ thread.lastMessageSeen();
548
+ setUnseenCount(0);
549
+ setScreen(2);
550
+ } else {
551
+ recover();
552
+ }
534
553
  }
535
554
  }, [thread, threadId]);
536
555
  const onEscapeKey = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(e => {
@@ -546,6 +565,7 @@ function Panel() {
546
565
  const onBack = handleScreenChange(screen - 1);
547
566
  const onEndChat = handleScreenChange(3);
548
567
  const onResume = handleScreenChange(2);
568
+ const onSettings = handleScreenChange(5);
549
569
  const onEndChatConfirm = e => {
550
570
  e.preventDefault();
551
571
  console.log('confirmed end chat');
@@ -564,7 +584,7 @@ function Panel() {
564
584
  break;
565
585
  case 2:
566
586
  ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_chat_chat_jsx__WEBPACK_IMPORTED_MODULE_4__.Chat, {
567
- setScreen: setScreen,
587
+ onSettings: onSettings,
568
588
  onEndChat: onEndChat
569
589
  });
570
590
  break;
@@ -574,6 +594,11 @@ function Panel() {
574
594
  onEndChatConfirm: onEndChatConfirm
575
595
  });
576
596
  break;
597
+ case 5:
598
+ ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_settings_jsx__WEBPACK_IMPORTED_MODULE_7__.Settings, {
599
+ onCancel: onResume
600
+ });
601
+ break;
577
602
  default:
578
603
  ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_pre_chat_jsx__WEBPACK_IMPORTED_MODULE_2__.PreChat, {
579
604
  onForward: onForward
@@ -584,8 +609,8 @@ function Panel() {
584
609
  }
585
610
  const Component = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
586
611
  id: "wc-panel",
587
- className: "wc-panel",
588
612
  role: "dialog",
613
+ className: "wc-panel",
589
614
  tabIndex: "-1",
590
615
  "aria-modal": "true",
591
616
  "aria-labelledby": "wc-header-title"
@@ -850,6 +875,97 @@ function RequestChat({
850
875
 
851
876
  /***/ }),
852
877
 
878
+ /***/ "./src/client/components/screens/settings.jsx":
879
+ /*!****************************************************!*\
880
+ !*** ./src/client/components/screens/settings.jsx ***!
881
+ \****************************************************/
882
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
883
+
884
+ __webpack_require__.r(__webpack_exports__);
885
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
886
+ /* harmony export */ Settings: () => (/* binding */ Settings)
887
+ /* harmony export */ });
888
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
889
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
890
+ /* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
891
+ /* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
892
+
893
+
894
+
895
+ function Settings({
896
+ onCancel
897
+ }) {
898
+ const {
899
+ settings,
900
+ setSettings
901
+ } = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_2__.useApp)();
902
+ const [optionAudio, setOptionAudio] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(settings.audio);
903
+ const [optionScroll, setOptionScroll] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(settings.scroll);
904
+ const onSave = e => {
905
+ e.preventDefault();
906
+ setSettings({
907
+ audio: optionAudio,
908
+ scroll: optionScroll
909
+ });
910
+ onCancel(e);
911
+ };
912
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__.PanelHeader, null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
913
+ className: "wc-body"
914
+ }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("fieldset", {
915
+ className: "govuk-fieldset govuk-!-margin-bottom-4"
916
+ }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("legend", {
917
+ className: "govuk-fieldset__legend govuk-fieldset__legend"
918
+ }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
919
+ id: "wc-subtitle",
920
+ className: "govuk-heading-s"
921
+ }, "Change settings")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
922
+ className: "govuk-checkboxes govuk-checkboxes--small",
923
+ "data-module": "govuk-checkboxes"
924
+ }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
925
+ className: "govuk-checkboxes__item"
926
+ }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("input", {
927
+ id: "audio",
928
+ name: "audio",
929
+ type: "checkbox",
930
+ value: "audio",
931
+ className: "govuk-checkboxes__input",
932
+ defaultChecked: optionAudio,
933
+ onChange: () => setOptionAudio(!optionAudio)
934
+ }), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("label", {
935
+ className: "govuk-label govuk-checkboxes__label govuk-!-font-size-16",
936
+ htmlFor: "audio"
937
+ }, "Play a sound when receiving a new message")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
938
+ className: "govuk-checkboxes__item"
939
+ }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("input", {
940
+ id: "scroll",
941
+ name: "scroll",
942
+ type: "checkbox",
943
+ value: "scroll",
944
+ className: "govuk-checkboxes__input",
945
+ defaultChecked: optionScroll,
946
+ onChange: () => setOptionScroll(!optionScroll)
947
+ }), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("label", {
948
+ className: "govuk-label govuk-checkboxes__label govuk-!-font-size-16",
949
+ htmlFor: "scroll"
950
+ }, "Scroll automatically to a new message")))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
951
+ className: "govuk-button-group"
952
+ }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
953
+ id: "settings-save",
954
+ href: "#",
955
+ className: "govuk-button govuk-!-font-size-16",
956
+ "data-module": "govuk-button",
957
+ onClick: onSave
958
+ }, "Save"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
959
+ id: "settings-cancel",
960
+ href: "#",
961
+ className: "govuk-link govuk-!-font-size-16",
962
+ "data-module": "govuk-button",
963
+ onClick: onCancel
964
+ }, "Cancel"))));
965
+ }
966
+
967
+ /***/ }),
968
+
853
969
  /***/ "./src/client/components/screens/unavailable.jsx":
854
970
  /*!*******************************************************!*\
855
971
  !*** ./src/client/components/screens/unavailable.jsx ***!
@@ -1011,6 +1127,44 @@ const classnames = (...classes) => classes.filter(classname => classname && type
1011
1127
 
1012
1128
  /***/ }),
1013
1129
 
1130
+ /***/ "./src/client/lib/message-notification.js":
1131
+ /*!************************************************!*\
1132
+ !*** ./src/client/lib/message-notification.js ***!
1133
+ \************************************************/
1134
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1135
+
1136
+ __webpack_require__.r(__webpack_exports__);
1137
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1138
+ /* harmony export */ messageNotification: () => (/* binding */ messageNotification)
1139
+ /* harmony export */ });
1140
+ const messageNotification = audioUrl => {
1141
+ let buffer;
1142
+ const context = new (window.AudioContext || window.webkitAudioContext)();
1143
+ if (context.state === 'suspended') {
1144
+ const events = ['touchstart', 'touchend', 'mousedown', 'wheel', 'keydown', 'click'];
1145
+ const unlock = _e => {
1146
+ events.forEach(event => {
1147
+ document.body.removeEventListener(event, unlock);
1148
+ });
1149
+ context.resume();
1150
+ };
1151
+ events.forEach(event => {
1152
+ document.body.addEventListener(event, unlock, false);
1153
+ });
1154
+ }
1155
+ fetch(audioUrl).then(response => response.arrayBuffer()).then(data => context.decodeAudioData(data)).then(decodedData => {
1156
+ buffer = decodedData;
1157
+ }).catch(console.error);
1158
+ return () => {
1159
+ const source = context.createBufferSource();
1160
+ source.buffer = buffer;
1161
+ source.connect(context.destination);
1162
+ source.start();
1163
+ };
1164
+ };
1165
+
1166
+ /***/ }),
1167
+
1014
1168
  /***/ "./src/client/lib/transform-messages.js":
1015
1169
  /*!**********************************************!*\
1016
1170
  !*** ./src/client/lib/transform-messages.js ***!
@@ -1080,17 +1234,23 @@ __webpack_require__.r(__webpack_exports__);
1080
1234
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1081
1235
  /* harmony import */ var _nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @nice-devone/nice-cxone-chat-web-sdk */ "@nice-devone/nice-cxone-chat-web-sdk");
1082
1236
  /* harmony import */ var _nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__);
1083
- /* harmony import */ var _reducer_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./reducer.js */ "./src/client/store/reducer.js");
1237
+ /* harmony import */ var _lib_message_notification_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../lib/message-notification.js */ "./src/client/lib/message-notification.js");
1238
+ /* harmony import */ var _reducer_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./reducer.js */ "./src/client/store/reducer.js");
1239
+ /* harmony import */ var _constants_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./constants.js */ "./src/client/store/constants.js");
1240
+
1241
+
1084
1242
 
1085
1243
 
1086
1244
 
1087
- const AppContext = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.createContext)(_reducer_js__WEBPACK_IMPORTED_MODULE_2__.initialState);
1245
+ const AppContext = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.createContext)(_reducer_js__WEBPACK_IMPORTED_MODULE_3__.initialState);
1088
1246
  const AppProvider = ({
1089
1247
  sdk,
1090
1248
  availability,
1249
+ options,
1091
1250
  children
1092
1251
  }) => {
1093
- const [state, dispatch] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useReducer)(_reducer_js__WEBPACK_IMPORTED_MODULE_2__.reducer, _reducer_js__WEBPACK_IMPORTED_MODULE_2__.initialState);
1252
+ const [state, dispatch] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useReducer)(_reducer_js__WEBPACK_IMPORTED_MODULE_3__.reducer, _reducer_js__WEBPACK_IMPORTED_MODULE_3__.initialState);
1253
+ const playSound = (0,_lib_message_notification_js__WEBPACK_IMPORTED_MODULE_2__.messageNotification)(options.audioUrl);
1094
1254
 
1095
1255
  /**
1096
1256
  * SDK event handlers
@@ -1104,6 +1264,10 @@ const AppProvider = ({
1104
1264
  type: 'SET_AGENT_STATUS',
1105
1265
  payload: e.detail.data.contact.status
1106
1266
  });
1267
+ dispatch({
1268
+ type: 'SET_UNSEEN_COUNT',
1269
+ payload: e.detail.data.contact.customerStatistics.unseenMessagesCount
1270
+ });
1107
1271
  };
1108
1272
  const onAssignedAgentChanged = e => {
1109
1273
  dispatch({
@@ -1136,6 +1300,14 @@ const AppProvider = ({
1136
1300
  type: 'SET_AGENT_STATUS',
1137
1301
  payload: e.detail.data.case.status
1138
1302
  });
1303
+ dispatch({
1304
+ type: 'SET_UNSEEN_COUNT',
1305
+ payload: e.detail.data.case.customerStatistics.unseenMessagesCount
1306
+ });
1307
+ const isAudioOn = JSON.parse(window.localStorage.getItem(_constants_js__WEBPACK_IMPORTED_MODULE_4__.SETTINGS_STORAGE_KEY)).audio;
1308
+ if (isAudioOn && e.detail.data.message.direction === 'outbound') {
1309
+ playSound();
1310
+ }
1139
1311
  };
1140
1312
  const onContactStatusChanged = e => {
1141
1313
  dispatch({
@@ -1160,8 +1332,9 @@ const AppProvider = ({
1160
1332
  type: 'SET_AVAILABILITY',
1161
1333
  payload: availability
1162
1334
  });
1163
- setCustomerId(window.localStorage.getItem(_reducer_js__WEBPACK_IMPORTED_MODULE_2__.CUSTOMER_ID_STORAGE_KEY));
1164
- setThreadId(window.localStorage.getItem(_reducer_js__WEBPACK_IMPORTED_MODULE_2__.THREAD_ID_STORAGE_KEY));
1335
+ setCustomerId(window.localStorage.getItem(_constants_js__WEBPACK_IMPORTED_MODULE_4__.CUSTOMER_ID_STORAGE_KEY));
1336
+ setThreadId(window.localStorage.getItem(_constants_js__WEBPACK_IMPORTED_MODULE_4__.THREAD_ID_STORAGE_KEY));
1337
+ setSettings(JSON.parse(window.localStorage.getItem(_constants_js__WEBPACK_IMPORTED_MODULE_4__.SETTINGS_STORAGE_KEY)) || state.settings);
1165
1338
  if (window.location.hash === '#webchat') {
1166
1339
  setChatVisibility(true);
1167
1340
  }
@@ -1203,6 +1376,18 @@ const AppProvider = ({
1203
1376
  payload: messages
1204
1377
  });
1205
1378
  };
1379
+ const setSettings = data => {
1380
+ dispatch({
1381
+ type: 'SET_SETTINGS',
1382
+ payload: data
1383
+ });
1384
+ };
1385
+ const setUnseenCount = unseenCount => {
1386
+ dispatch({
1387
+ type: 'SET_UNSEEN_COUNT',
1388
+ payload: unseenCount
1389
+ });
1390
+ };
1206
1391
 
1207
1392
  /**
1208
1393
  * Application-wide state and state functions
@@ -1210,10 +1395,12 @@ const AppProvider = ({
1210
1395
  const store = (0,react__WEBPACK_IMPORTED_MODULE_0__.useMemo)(() => ({
1211
1396
  ...state,
1212
1397
  sdk,
1398
+ setSettings,
1213
1399
  setCustomerId,
1214
1400
  setThreadId,
1215
1401
  setThread,
1216
1402
  setMessages,
1403
+ setUnseenCount,
1217
1404
  setChatVisibility,
1218
1405
  onLiveChatRecovered,
1219
1406
  onAssignedAgentChanged,
@@ -1240,14 +1427,25 @@ __webpack_require__.r(__webpack_exports__);
1240
1427
  /* harmony export */ actionsMap: () => (/* binding */ actionsMap)
1241
1428
  /* harmony export */ });
1242
1429
  /* harmony import */ var _lib_transform_messages__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../lib/transform-messages */ "./src/client/lib/transform-messages.js");
1243
- /* harmony import */ var _reducer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./reducer */ "./src/client/store/reducer.js");
1430
+ /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "./src/client/store/constants.js");
1244
1431
 
1245
1432
 
1433
+ const setSettings = (state, payload) => {
1434
+ if (payload) {
1435
+ window.localStorage.setItem(_constants__WEBPACK_IMPORTED_MODULE_1__.SETTINGS_STORAGE_KEY, JSON.stringify(payload));
1436
+ } else {
1437
+ window.localStorage.removeItem(_constants__WEBPACK_IMPORTED_MODULE_1__.SETTINGS_STORAGE_KEY);
1438
+ }
1439
+ return {
1440
+ ...state,
1441
+ settings: payload
1442
+ };
1443
+ };
1246
1444
  const setCustomerId = (state, payload) => {
1247
1445
  if (payload) {
1248
- window.localStorage.setItem(_reducer__WEBPACK_IMPORTED_MODULE_1__.CUSTOMER_ID_STORAGE_KEY, payload);
1446
+ window.localStorage.setItem(_constants__WEBPACK_IMPORTED_MODULE_1__.CUSTOMER_ID_STORAGE_KEY, payload);
1249
1447
  } else {
1250
- window.localStorage.removeItem(_reducer__WEBPACK_IMPORTED_MODULE_1__.CUSTOMER_ID_STORAGE_KEY);
1448
+ window.localStorage.removeItem(_constants__WEBPACK_IMPORTED_MODULE_1__.CUSTOMER_ID_STORAGE_KEY);
1251
1449
  }
1252
1450
  return {
1253
1451
  ...state,
@@ -1256,9 +1454,9 @@ const setCustomerId = (state, payload) => {
1256
1454
  };
1257
1455
  const setThreadId = (state, payload) => {
1258
1456
  if (payload) {
1259
- window.localStorage.setItem(_reducer__WEBPACK_IMPORTED_MODULE_1__.THREAD_ID_STORAGE_KEY, payload);
1457
+ window.localStorage.setItem(_constants__WEBPACK_IMPORTED_MODULE_1__.THREAD_ID_STORAGE_KEY, payload);
1260
1458
  } else {
1261
- window.localStorage.removeItem(_reducer__WEBPACK_IMPORTED_MODULE_1__.THREAD_ID_STORAGE_KEY);
1459
+ window.localStorage.removeItem(_constants__WEBPACK_IMPORTED_MODULE_1__.THREAD_ID_STORAGE_KEY);
1262
1460
  }
1263
1461
  return {
1264
1462
  ...state,
@@ -1313,9 +1511,16 @@ const setAgentStatus = (state, payload) => {
1313
1511
  agentStatus: payload
1314
1512
  };
1315
1513
  };
1514
+ const setUnseenCount = (state, payload) => {
1515
+ return {
1516
+ ...state,
1517
+ unseenCount: payload
1518
+ };
1519
+ };
1316
1520
  const actionsMap = {
1317
1521
  SET_CHAT_VISIBILITY: setChatVisibility,
1318
1522
  SET_AVAILABILITY: setAvailability,
1523
+ SET_SETTINGS: setSettings,
1319
1524
  SET_CUSTOMER_ID: setCustomerId,
1320
1525
  SET_THREAD_ID: setThreadId,
1321
1526
  SET_THREAD: setThread,
@@ -1323,11 +1528,30 @@ const actionsMap = {
1323
1528
  SET_MESSAGES: setMessages,
1324
1529
  SET_AGENT: setAgent,
1325
1530
  SET_AGENT_TYPING: setAgentIsTyping,
1326
- SET_AGENT_STATUS: setAgentStatus
1531
+ SET_AGENT_STATUS: setAgentStatus,
1532
+ SET_UNSEEN_COUNT: setUnseenCount
1327
1533
  };
1328
1534
 
1329
1535
  /***/ }),
1330
1536
 
1537
+ /***/ "./src/client/store/constants.js":
1538
+ /*!***************************************!*\
1539
+ !*** ./src/client/store/constants.js ***!
1540
+ \***************************************/
1541
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1542
+
1543
+ __webpack_require__.r(__webpack_exports__);
1544
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1545
+ /* harmony export */ CUSTOMER_ID_STORAGE_KEY: () => (/* binding */ CUSTOMER_ID_STORAGE_KEY),
1546
+ /* harmony export */ SETTINGS_STORAGE_KEY: () => (/* binding */ SETTINGS_STORAGE_KEY),
1547
+ /* harmony export */ THREAD_ID_STORAGE_KEY: () => (/* binding */ THREAD_ID_STORAGE_KEY)
1548
+ /* harmony export */ });
1549
+ const SETTINGS_STORAGE_KEY = 'webchat_settings';
1550
+ const CUSTOMER_ID_STORAGE_KEY = 'webchat_customer_id';
1551
+ const THREAD_ID_STORAGE_KEY = 'webchat_thread_id';
1552
+
1553
+ /***/ }),
1554
+
1331
1555
  /***/ "./src/client/store/reducer.js":
1332
1556
  /*!*************************************!*\
1333
1557
  !*** ./src/client/store/reducer.js ***!
@@ -1336,25 +1560,26 @@ const actionsMap = {
1336
1560
 
1337
1561
  __webpack_require__.r(__webpack_exports__);
1338
1562
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1339
- /* harmony export */ CUSTOMER_ID_STORAGE_KEY: () => (/* binding */ CUSTOMER_ID_STORAGE_KEY),
1340
- /* harmony export */ THREAD_ID_STORAGE_KEY: () => (/* binding */ THREAD_ID_STORAGE_KEY),
1341
1563
  /* harmony export */ initialState: () => (/* binding */ initialState),
1342
1564
  /* harmony export */ reducer: () => (/* binding */ reducer)
1343
1565
  /* harmony export */ });
1344
1566
  /* harmony import */ var _actions_map__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./actions-map */ "./src/client/store/actions-map.js");
1345
1567
 
1346
- const CUSTOMER_ID_STORAGE_KEY = 'webchat_customer_id';
1347
- const THREAD_ID_STORAGE_KEY = 'webchat_thread_id';
1348
1568
  const initialState = {
1349
1569
  availability: null,
1350
1570
  customerId: null,
1351
1571
  threadId: null,
1352
1572
  thread: null,
1353
1573
  messages: [],
1574
+ unseenCount: 0,
1354
1575
  agent: null,
1355
1576
  agentStatus: null,
1356
1577
  isAgentTyping: false,
1357
- isChatOpen: false
1578
+ isChatOpen: false,
1579
+ settings: {
1580
+ audio: true,
1581
+ scroll: true
1582
+ }
1358
1583
  };
1359
1584
  const reducer = (state, action) => {
1360
1585
  const {
@@ -1593,7 +1818,7 @@ __webpack_require__.r(__webpack_exports__);
1593
1818
  /* harmony import */ var _components_availability_availability_jsx__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./components/availability/availability.jsx */ "./src/client/components/availability/availability.jsx");
1594
1819
  /* harmony import */ var _lib_check_availability__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./lib/check-availability */ "./src/client/lib/check-availability.js");
1595
1820
  /* harmony import */ var _store_AppProvider_jsx__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./store/AppProvider.jsx */ "./src/client/store/AppProvider.jsx");
1596
- /* harmony import */ var _store_reducer_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./store/reducer.js */ "./src/client/store/reducer.js");
1821
+ /* harmony import */ var _store_constants_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./store/constants.js */ "./src/client/store/constants.js");
1597
1822
 
1598
1823
 
1599
1824
 
@@ -1605,7 +1830,7 @@ async function init(container, options) {
1605
1830
  const sdk = new _nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_2__.ChatSdk({
1606
1831
  brandId: options.brandId,
1607
1832
  channelId: options.channelId,
1608
- customerId: window.localStorage.getItem(_store_reducer_js__WEBPACK_IMPORTED_MODULE_6__.CUSTOMER_ID_STORAGE_KEY) || '',
1833
+ customerId: window.localStorage.getItem(_store_constants_js__WEBPACK_IMPORTED_MODULE_6__.CUSTOMER_ID_STORAGE_KEY) || '',
1609
1834
  environment: options.environment
1610
1835
  });
1611
1836
  const root = (0,react_dom_client__WEBPACK_IMPORTED_MODULE_1__.createRoot)(container);
@@ -1618,10 +1843,9 @@ async function init(container, options) {
1618
1843
  }
1619
1844
  root.render( /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_store_AppProvider_jsx__WEBPACK_IMPORTED_MODULE_5__.AppProvider, {
1620
1845
  sdk: sdk,
1621
- availability: availability
1622
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_components_availability_availability_jsx__WEBPACK_IMPORTED_MODULE_3__.Availability, {
1623
- availability: availability
1624
- })));
1846
+ availability: availability,
1847
+ options: options
1848
+ }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_components_availability_availability_jsx__WEBPACK_IMPORTED_MODULE_3__.Availability, null)));
1625
1849
  }
1626
1850
  })();
1627
1851