@microsoft/omnichannel-chat-widget 0.1.0-main.8b6c0d8 → 0.1.0-main.cf54410

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.
Files changed (64) hide show
  1. package/lib/cjs/common/Constants.js +2 -0
  2. package/lib/cjs/common/contextDataStore/DataStoreManager.js +14 -0
  3. package/lib/cjs/common/interfaces/IContextDataStore.js +1 -0
  4. package/lib/cjs/common/telemetry/TelemetryConstants.js +1 -0
  5. package/lib/cjs/common/telemetry/TelemetryHelper.js +9 -4
  6. package/lib/cjs/common/telemetry/TelemetryManager.js +12 -4
  7. package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +3 -3
  8. package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +14 -1
  9. package/lib/cjs/common/telemetry/loggers/consoleLogger.js +3 -0
  10. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +8 -1
  11. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +13 -26
  12. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +27 -26
  13. package/lib/cjs/components/livechatwidget/common/disposeTelemetryLoggers.js +14 -0
  14. package/lib/cjs/components/livechatwidget/common/endChat.js +8 -0
  15. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -9
  16. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +18 -3
  17. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +23 -22
  18. package/lib/cjs/components/livechatwidget/common/startChat.js +64 -18
  19. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +27 -13
  20. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +25 -8
  21. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +4 -0
  22. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +6 -3
  23. package/lib/cjs/contexts/createReducer.js +27 -0
  24. package/lib/esm/common/Constants.js +2 -0
  25. package/lib/esm/common/contextDataStore/DataStoreManager.js +5 -0
  26. package/lib/esm/common/interfaces/IContextDataStore.js +1 -0
  27. package/lib/esm/common/telemetry/TelemetryConstants.js +1 -0
  28. package/lib/esm/common/telemetry/TelemetryHelper.js +9 -4
  29. package/lib/esm/common/telemetry/TelemetryManager.js +8 -4
  30. package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +3 -3
  31. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +14 -1
  32. package/lib/esm/common/telemetry/loggers/consoleLogger.js +3 -0
  33. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +9 -1
  34. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +13 -26
  35. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +29 -28
  36. package/lib/esm/components/livechatwidget/common/disposeTelemetryLoggers.js +4 -0
  37. package/lib/esm/components/livechatwidget/common/endChat.js +8 -0
  38. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +8 -9
  39. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +18 -2
  40. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +22 -22
  41. package/lib/esm/components/livechatwidget/common/startChat.js +62 -17
  42. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +23 -12
  43. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +26 -10
  44. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +4 -0
  45. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +6 -3
  46. package/lib/esm/contexts/createReducer.js +27 -0
  47. package/lib/types/common/Constants.d.ts +1 -0
  48. package/lib/types/common/contextDataStore/DataStoreManager.d.ts +4 -0
  49. package/lib/types/common/interfaces/IContextDataStore.d.ts +14 -0
  50. package/lib/types/common/telemetry/TelemetryConstants.d.ts +2 -1
  51. package/lib/types/common/telemetry/TelemetryManager.d.ts +1 -0
  52. package/lib/types/common/telemetry/definitions/Contracts.d.ts +3 -0
  53. package/lib/types/common/telemetry/definitions/Payload.d.ts +3 -0
  54. package/lib/types/common/telemetry/interfaces/IChatSDKLogger.d.ts +1 -0
  55. package/lib/types/common/telemetry/interfaces/IInternalTelemetryData.d.ts +2 -0
  56. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +12 -0
  57. package/lib/types/components/livechatwidget/common/disposeTelemetryLoggers.d.ts +1 -0
  58. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  59. package/lib/types/components/livechatwidget/common/startChat.d.ts +1 -1
  60. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -0
  61. package/lib/types/components/prechatsurveypanestateful/interfaces/IPreChatSurveyPaneStatefulParams.d.ts +1 -1
  62. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +3 -0
  63. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +5 -1
  64. package/package.json +3 -1
@@ -7,8 +7,8 @@ import createAttachmentMiddleware from "../../../webchatcontainerstateful/webcha
7
7
  import { createAvatarMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware";
8
8
  import { createMarkdown } from "../createMarkdown";
9
9
  import { groupActivitiesMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/groupActivitiesMiddleware";
10
- import { typingIndicatorMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware"; // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
-
10
+ import { typingIndicatorMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware";
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
12
  export const dummyDefaultProps = {
13
13
  audioNotificationProps: {
14
14
  audioSrc: "assets/audios/newMessageNotification.mp3"
@@ -132,7 +132,7 @@ export const dummyDefaultProps = {
132
132
  id: "oc-lcw-CurrentCall-timer",
133
133
  showHours: false,
134
134
  timerStyles: {
135
- color: "white",
135
+ color: "#FFFFFF",
136
136
  textAlign: "center",
137
137
  backgroundColor: "#3d3c3c",
138
138
  height: "45px",
@@ -163,8 +163,8 @@ export const dummyDefaultProps = {
163
163
  },
164
164
  audioCallButtonStyleProps: {
165
165
  borderRadius: "50%",
166
- color: "white",
167
- backgroundColor: "green",
166
+ color: "#FFFFFF",
167
+ backgroundColor: "#008000",
168
168
  lineHeight: "40px",
169
169
  height: "40px",
170
170
  width: "40px",
@@ -175,8 +175,8 @@ export const dummyDefaultProps = {
175
175
  },
176
176
  videoCallButtonStyleProps: {
177
177
  borderRadius: "50%",
178
- color: "white",
179
- backgroundColor: "green",
178
+ color: "#FFFFFF",
179
+ backgroundColor: "#008000",
180
180
  lineHeight: "40px",
181
181
  height: "40px",
182
182
  width: "40px",
@@ -191,8 +191,8 @@ export const dummyDefaultProps = {
191
191
  },
192
192
  declineCallButtonStyleProps: {
193
193
  borderRadius: "50%",
194
- color: "white",
195
- backgroundColor: "red",
194
+ color: "#FFFFFF",
195
+ backgroundColor: "#DC0000",
196
196
  lineHeight: "40px",
197
197
  height: "40px",
198
198
  width: "40px",
@@ -201,12 +201,12 @@ export const dummyDefaultProps = {
201
201
  },
202
202
  incomingCallTitleStyleProps: {
203
203
  margin: "0 5px",
204
- color: "white",
204
+ color: "#FFFFFF",
205
205
  fontSize: 12,
206
206
  fontFamily: "Segoe UI, Arial, sans-serif"
207
207
  },
208
208
  itemFocusStyleProps: {
209
- outline: "2px solid white"
209
+ outline: "2px solid #FFFFFF"
210
210
  }
211
211
  },
212
212
  currentCallStyleProps: {
@@ -218,7 +218,7 @@ export const dummyDefaultProps = {
218
218
  },
219
219
  micButtonStyleProps: {
220
220
  borderRadius: "2px",
221
- color: "white",
221
+ color: "#FFFFFF",
222
222
  backgroundColor: "#3d3c3c",
223
223
  height: "45px",
224
224
  width: "50px",
@@ -229,7 +229,7 @@ export const dummyDefaultProps = {
229
229
  },
230
230
  videoOffButtonStyleProps: {
231
231
  borderRadius: "2px",
232
- color: "white",
232
+ color: "#FFFFFF",
233
233
  backgroundColor: "#3d3c3c",
234
234
  height: "45px",
235
235
  width: "50px",
@@ -243,8 +243,8 @@ export const dummyDefaultProps = {
243
243
  },
244
244
  endCallButtonStyleProps: {
245
245
  borderRadius: "2px",
246
- color: "white",
247
- backgroundColor: "red",
246
+ color: "#FFFFFF",
247
+ backgroundColor: "#DC0000",
248
248
  lineHeight: "50px",
249
249
  height: "45px",
250
250
  width: "50px",
@@ -253,7 +253,7 @@ export const dummyDefaultProps = {
253
253
  currentCallTimerStyleProps: {
254
254
  borderRadius: "2px",
255
255
  margin: "1px",
256
- color: "white",
256
+ color: "#FFFFFF",
257
257
  paddingTop: "18px",
258
258
  fontSize: 12,
259
259
  fontFamily: "Segoe UI, Arial, sans-serif",
@@ -475,7 +475,7 @@ export const dummyDefaultProps = {
475
475
  },
476
476
  styleProps: {
477
477
  generalStyleProps: {
478
- backgroundColor: "white",
478
+ backgroundColor: "#FFFFFF",
479
479
  borderRadius: "2px",
480
480
  color: "black",
481
481
  fontFamily: "Segoe UI, Arial, sans-serif",
@@ -517,7 +517,7 @@ export const dummyDefaultProps = {
517
517
  },
518
518
  confirmButtonStyleProps: {
519
519
  backgroundColor: "rgba(9,72,159,1)",
520
- color: "white",
520
+ color: "#FFFFFF",
521
521
  fontFamily: "Segoe UI, Arial, sans-serif",
522
522
  fontSize: "14px",
523
523
  fontWeight: "500",
@@ -531,7 +531,7 @@ export const dummyDefaultProps = {
531
531
  border: "2px dotted #000"
532
532
  },
533
533
  cancelButtonStyleProps: {
534
- backgroundColor: "white",
534
+ backgroundColor: "#FFFFFF",
535
535
  fontFamily: "Segoe UI, Arial, sans-serif",
536
536
  fontSize: "14px",
537
537
  fontWeight: "500",
@@ -916,16 +916,16 @@ export const dummyDefaultProps = {
916
916
  fontSize: 16,
917
917
  fontFamily: "Segoe UI, Arial, sans-serif",
918
918
  fontWeight: "450",
919
- color: "white",
919
+ color: "#FFFFFF",
920
920
  padding: "3px 0"
921
921
  },
922
922
  minimizeButtonStyleProps: {
923
- color: "white",
923
+ color: "#FFFFFF",
924
924
  margin: "5px 0",
925
925
  fontSize: "12px"
926
926
  },
927
927
  closeButtonStyleProps: {
928
- color: "white",
928
+ color: "#FFFFFF",
929
929
  margin: "5px 0",
930
930
  fontSize: "12px"
931
931
  },
@@ -1087,7 +1087,7 @@ export const dummyDefaultProps = {
1087
1087
  titleStyleProps: {
1088
1088
  // ...[Existing chat button title style props]
1089
1089
  margin: "0 0 0 10px",
1090
- color: "White"
1090
+ color: "#FFFFFF"
1091
1091
  }
1092
1092
  }
1093
1093
  },
@@ -1453,7 +1453,7 @@ export const dummyDefaultProps = {
1453
1453
  bubbleBackground: "#315FA2",
1454
1454
  bubbleBorderRadius: 4,
1455
1455
  bubbleBorderWidth: 0,
1456
- bubbleFromUserBackground: "White",
1456
+ bubbleFromUserBackground: "#FFFFFF",
1457
1457
  bubbleFromUserBorderRadius: 4,
1458
1458
  bubbleFromUserBorderWidth: 1,
1459
1459
  bubbleFromUserTextColor: "Black",
@@ -1461,7 +1461,7 @@ export const dummyDefaultProps = {
1461
1461
  bubbleMaxWidth: 250,
1462
1462
  bubbleMinHeight: 34,
1463
1463
  bubbleMinWidth: 20,
1464
- bubbleTextColor: "White",
1464
+ bubbleTextColor: "#FFFFFF",
1465
1465
  hideSendBox: false,
1466
1466
  hideUploadButton: true,
1467
1467
  primaryFont: "Segoe UI, Arial, sans-serif",
@@ -1470,7 +1470,7 @@ export const dummyDefaultProps = {
1470
1470
  sendBoxTextWrap: true,
1471
1471
  sendBoxHeight: 60,
1472
1472
  sendBoxMaxHeight: 96,
1473
- sendBoxBackground: "White",
1473
+ sendBoxBackground: "#FFFFFF",
1474
1474
  showAvatarInGroup: true,
1475
1475
  suggestedActionsStackedHeight: 125,
1476
1476
  suggestedActionsStackedOverflow: "scroll",
@@ -1581,7 +1581,7 @@ export const dummyDefaultProps = {
1581
1581
  fontWeight: 600,
1582
1582
  fontSize: "13px",
1583
1583
  lineHeight: "18px",
1584
- color: "white",
1584
+ color: "#FFFFFF",
1585
1585
  paddingTop: "7px",
1586
1586
  WebkitUserSelect: "none",
1587
1587
  MozUserSelect: "none",
@@ -1685,5 +1685,6 @@ export const dummyDefaultProps = {
1685
1685
  PRECHAT_REQUIRED_FIELD_MISSING_MESSAGE: "{0} field is required",
1686
1686
  MARKDOWN_EXTERNAL_LINK_ALT: "Opens in a new window; external."
1687
1687
  }
1688
- }
1688
+ },
1689
+ telemetryConfig: undefined
1689
1690
  };
@@ -0,0 +1,4 @@
1
+ import { disposeLoggers } from "../../../common/telemetry/TelemetryManager";
2
+ export const disposeTelemetryLoggers = () => {
3
+ disposeLoggers();
4
+ };
@@ -26,6 +26,10 @@ export const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
26
26
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
27
27
  payload: ConversationState.Closed
28
28
  });
29
+ dispatch({
30
+ type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
31
+ payload: false
32
+ });
29
33
  dispatch({
30
34
  type: LiveChatWidgetActionType.SET_RECONNECT_ID,
31
35
  payload: undefined
@@ -38,6 +42,10 @@ export const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
38
42
  type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
39
43
  payload: undefined
40
44
  });
45
+ dispatch({
46
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
47
+ payload: undefined
48
+ });
41
49
  BroadcastService.postMessage({
42
50
  eventName: "EndChat"
43
51
  });
@@ -1,5 +1,4 @@
1
1
  import { createStore } from "botframework-webchat";
2
- import { ConversationState } from "../../../contexts/common/ConversationState";
3
2
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
4
3
  import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
5
4
  import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
@@ -23,8 +22,8 @@ import htmlPlayerMiddleware from "../../webchatcontainerstateful/webchatcontroll
23
22
  import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware";
24
23
  import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
25
24
  import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
26
- import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
-
25
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
27
  export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
29
28
  var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21;
30
29
 
@@ -54,15 +53,15 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
54
53
  }
55
54
 
56
55
  if (isPostChatEnabled === "true" && postChatSurveyMode === PostChatSurveyMode.Embed) {
56
+ const loadPostChatEvent = {
57
+ eventName: "LoadPostChatSurvey"
58
+ };
59
+ BroadcastService.postMessage(loadPostChatEvent);
60
+ } else {
57
61
  dispatch({
58
- type: LiveChatWidgetActionType.SET_SHOULD_SHOW_POST_CHAT,
62
+ type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
59
63
  payload: true
60
64
  });
61
- dispatch({
62
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
63
- payload: ConversationState.Loading
64
- });
65
- await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
66
65
  }
67
66
 
68
67
  dispatch({
@@ -4,10 +4,19 @@ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
4
4
  import { defaultAriaConfig } from "../../../common/telemetry/defaultConfigs/defaultAriaConfig";
5
5
  import { defaultInternalTelemetryData } from "../../../common/telemetry/defaultConfigs/defaultTelemetryInternalData";
6
6
  import { defaultTelemetryConfiguration } from "../../../common/telemetry/defaultConfigs/defaultTelemetryConfiguration";
7
- import packageInfo from "@microsoft/omnichannel-chat-sdk/package.json";
7
+ import { version as chatComponentVersion } from "@microsoft/omnichannel-chat-components/package.json";
8
+ import { version as chatSdkVersion } from "@microsoft/omnichannel-chat-sdk/package.json";
8
9
  export const registerTelemetryLoggers = (props, dispatch) => {
9
10
  var _props$liveChatContex, _props$liveChatContex2;
10
11
 
12
+ let widgetPackageInfo;
13
+
14
+ try {
15
+ widgetPackageInfo = require("@microsoft/omnichannel-chat-widget/package.json");
16
+ } catch (error) {
17
+ widgetPackageInfo = "0.0.0-0";
18
+ }
19
+
11
20
  const telemetryConfig = { ...defaultTelemetryConfiguration,
12
21
  ...props.telemetryConfig
13
22
  };
@@ -17,6 +26,8 @@ export const registerTelemetryLoggers = (props, dispatch) => {
17
26
 
18
27
  TelemetryManager.InternalTelemetryData = (_props$liveChatContex3 = props.liveChatContextFromCache) === null || _props$liveChatContex3 === void 0 ? void 0 : (_props$liveChatContex4 = _props$liveChatContex3.domainStates) === null || _props$liveChatContex4 === void 0 ? void 0 : _props$liveChatContex4.telemetryInternalData;
19
28
  } else {
29
+ var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic, _props$chatSDK3, _props$chatSDK3$omnic;
30
+
20
31
  let telemetryData = { ...defaultInternalTelemetryData,
21
32
  telemetryConfig: Object.assign({}, defaultTelemetryConfiguration, telemetryConfig),
22
33
  ariaConfig: Object.assign({}, defaultAriaConfig, telemetryConfig === null || telemetryConfig === void 0 ? void 0 : telemetryConfig.ariaConfigurations)
@@ -27,7 +38,12 @@ export const registerTelemetryLoggers = (props, dispatch) => {
27
38
  }
28
39
 
29
40
  telemetryData = TelemetryHelper.addWidgetDataToTelemetry(telemetryConfig, telemetryData);
30
- telemetryData.OCChatSDKVersion = packageInfo.version;
41
+ telemetryData.OCChatSDKVersion = chatSdkVersion;
42
+ telemetryData.chatComponentVersion = chatComponentVersion;
43
+ telemetryData.chatWidgetVersion = widgetPackageInfo;
44
+ telemetryData.orgId = (_props$chatSDK = props.chatSDK) === null || _props$chatSDK === void 0 ? void 0 : (_props$chatSDK$omnich = _props$chatSDK.omnichannelConfig) === null || _props$chatSDK$omnich === void 0 ? void 0 : _props$chatSDK$omnich.orgId;
45
+ telemetryData.widgetId = (_props$chatSDK2 = props.chatSDK) === null || _props$chatSDK2 === void 0 ? void 0 : (_props$chatSDK2$omnic = _props$chatSDK2.omnichannelConfig) === null || _props$chatSDK2$omnic === void 0 ? void 0 : _props$chatSDK2$omnic.widgetId;
46
+ telemetryData.orgUrl = (_props$chatSDK3 = props.chatSDK) === null || _props$chatSDK3 === void 0 ? void 0 : (_props$chatSDK3$omnic = _props$chatSDK3.omnichannelConfig) === null || _props$chatSDK3$omnic === void 0 ? void 0 : _props$chatSDK3$omnic.orgUrl;
31
47
  dispatch({
32
48
  type: LiveChatWidgetActionType.SET_TELEMETRY_DATA,
33
49
  payload: telemetryData
@@ -1,20 +1,23 @@
1
1
  import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
2
2
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
3
3
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
4
- import { ConversationState } from "../../../contexts/common/ConversationState"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
-
6
- export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, loadSurvey) => {
4
+ import { ConversationState } from "../../../contexts/common/ConversationState";
5
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat) => {
7
8
  try {
8
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
- const context = await chatSDK.getPostChatSurveyContext();
10
- TelemetryHelper.logSDKEvent(LogLevel.INFO, {
11
- Event: TelemetryEvent.PostChatContextCallSucceed,
12
- Description: "Postchat context call succeed."
13
- });
14
- dispatch({
15
- type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
16
- payload: context
17
- });
9
+ if (!persistedChat) {
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ const context = await chatSDK.getPostChatSurveyContext();
12
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
13
+ Event: TelemetryEvent.PostChatContextCallSucceed,
14
+ Description: "Postchat context call succeed."
15
+ });
16
+ dispatch({
17
+ type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
18
+ payload: context
19
+ });
20
+ }
18
21
  } catch (ex) {
19
22
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
20
23
  Event: TelemetryEvent.PostChatContextCallFailed,
@@ -23,18 +26,15 @@ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, loadSur
23
26
  }
24
27
  });
25
28
  }
26
- /* -true: setPostChatContextAndLoadSurvey is called after passing all checks from ConfirmationPane and endChatMiddleware in usual scenario.
27
- -false: Below if condition is needed for multi-tab scenarios. So when agent ends a chat and customer has opened chat in multiple tabs,
28
- all tabs should show post chat survey as per existing functionality. But when an agent end a conversation, Omnichannel SDK
29
- getPostChatSurveyContext returns as invalid conversation. To avoid that, caching the survey url is needed after chat starts and
30
- in this case loadSurvey is false
31
- */
32
-
33
29
 
34
- if (loadSurvey) {
30
+ BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
31
+ dispatch({
32
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
33
+ payload: ConversationState.Loading
34
+ });
35
35
  dispatch({
36
36
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
37
37
  payload: ConversationState.Postchat
38
38
  });
39
- }
39
+ });
40
40
  };
@@ -1,5 +1,5 @@
1
1
  import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
2
- import { ChatSDKError } from "../../../common/Constants";
2
+ import { ChatSDKError, Constants } from "../../../common/Constants";
3
3
  import { ConversationState } from "../../../contexts/common/ConversationState";
4
4
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
5
5
  import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
@@ -10,10 +10,15 @@ import { createAdapter } from "./createAdapter";
10
10
  import { createTimer } from "../../../common/utils";
11
11
  import { getReconnectIdForAuthenticatedChat } from "./reconnectChatHelper";
12
12
  import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
13
- import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
14
+ import { DataStoreManager } from "../../../common/contextDataStore/DataStoreManager"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
15
 
15
16
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
16
- // Getting PreChat Survey Context
17
+ if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
18
+ return;
19
+ } // Getting PreChat Survey Context
20
+
21
+
17
22
  const parseToJson = false;
18
23
  const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
19
24
  const showPrechat = state.appStates.conversationState === ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
@@ -48,16 +53,16 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
48
53
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
54
 
50
55
 
51
- const initStartChat = async (chatSDK, dispatch, setAdapter, params) => {
56
+ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedState) => {
52
57
  try {
53
58
  var _TelemetryTimers$Widg;
54
59
 
55
60
  try {
61
+ TelemetryTimers.WidgetLoadTimer = createTimer();
56
62
  TelemetryHelper.logConfigDataEvent(LogLevel.INFO, {
57
63
  Event: TelemetryEvent.StartChatSDKCall
58
64
  });
59
65
  await chatSDK.startChat(params);
60
- TelemetryTimers.WidgetLoadTimer = createTimer();
61
66
  } catch (error) {
62
67
  TelemetryHelper.logLoadingEvent(LogLevel.ERROR, {
63
68
  Event: TelemetryEvent.StartChatMethodException,
@@ -68,24 +73,40 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params) => {
68
73
  }
69
74
 
70
75
  const newAdapter = await createAdapter(chatSDK);
71
- setAdapter(newAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ setAdapter(newAdapter);
72
77
 
73
- if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
78
+ if (!persistedState) {
74
79
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
- const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
80
+ if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
83
+ dispatch({
84
+ type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
85
+ payload: chatToken
86
+ });
87
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
+
89
+
90
+ const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
76
91
  dispatch({
77
- type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
78
- payload: chatToken
92
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
93
+ payload: liveChatContext
79
94
  });
80
- }
95
+ await setPostChatContextAndLoadSurvey(chatSDK, dispatch);
96
+ await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
81
97
 
82
- await setPostChatContextAndLoadSurvey(chatSDK, dispatch, false);
83
- await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
98
+ dispatch({
99
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
100
+ payload: ConversationState.Active
101
+ });
102
+ } else {
103
+ dispatch({
104
+ type: LiveChatWidgetActionType.SET_WIDGET_STATE,
105
+ payload: persistedState
106
+ });
107
+ await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
108
+ }
84
109
 
85
- dispatch({
86
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
87
- payload: ConversationState.Active
88
- });
89
110
  TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
90
111
  Event: TelemetryEvent.WidgetLoadComplete,
91
112
  Description: "Widget load complete",
@@ -111,6 +132,30 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params) => {
111
132
  });
112
133
  }
113
134
  }
135
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
136
+
137
+
138
+ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
139
+ var _DataStoreManager$cli, _persistedState$domai;
140
+
141
+ const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(Constants.widgetStateDataKey, "localStorage");
142
+ const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
143
+
144
+ if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
145
+ var _persistedState$domai2;
146
+
147
+ dispatch({
148
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
149
+ payload: ConversationState.Loading
150
+ });
151
+ const optionalParams = {
152
+ liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai2 = persistedState.domainStates) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.liveChatContext
153
+ };
154
+ await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
155
+ return true;
156
+ } else {
157
+ return false;
158
+ }
114
159
  };
115
160
 
116
161
  export { prepareStartChat, initStartChat };
@@ -39,6 +39,9 @@ import { startProactiveChat } from "../common/startProactiveChat";
39
39
  import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
40
40
  import useChatContextStore from "../../../hooks/useChatContextStore";
41
41
  import useChatSDKStore from "../../../hooks/useChatSDKStore";
42
+ import { TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
43
+ import { disposeTelemetryLoggers } from "../common/disposeTelemetryLoggers";
44
+ import { DataStoreManager } from "../../../common/contextDataStore/DataStoreManager";
42
45
  export const LiveChatWidgetStateful = props => {
43
46
  var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps5, _props$componentOverr, _props$controlProps6, _props$componentOverr2, _props$controlProps7, _props$componentOverr3, _props$controlProps8, _props$componentOverr4, _props$controlProps9, _props$componentOverr5, _props$controlProps10, _props$componentOverr6, _props$controlProps11, _props$controlProps12, _props$controlProps13, _props$componentOverr7, _props$controlProps14, _props$componentOverr8, _props$controlProps15, _props$componentOverr9, _props$componentOverr10, _props$componentOverr11;
44
47
 
@@ -67,6 +70,7 @@ export const LiveChatWidgetStateful = props => {
67
70
 
68
71
  registerTelemetryLoggers(props, dispatch);
69
72
  createInternetConnectionChangeHandler();
73
+ DataStoreManager.clientDataStore = props.contextDataStore ?? undefined;
70
74
  dispatch({
71
75
  type: LiveChatWidgetActionType.SET_WIDGET_ELEMENT_ID,
72
76
  payload: widgetElementId
@@ -144,11 +148,16 @@ export const LiveChatWidgetStateful = props => {
144
148
  startProactiveChat(dispatch, msg === null || msg === void 0 ? void 0 : (_msg$payload = msg.payload) === null || _msg$payload === void 0 ? void 0 : _msg$payload.bodyTitle, msg === null || msg === void 0 ? void 0 : (_msg$payload2 = msg.payload) === null || _msg$payload2 === void 0 ? void 0 : _msg$payload2.showPrechat, msg === null || msg === void 0 ? void 0 : (_msg$payload3 = msg.payload) === null || _msg$payload3 === void 0 ? void 0 : _msg$payload3.inNewWindow);
145
149
  }
146
150
  });
151
+ window.addEventListener("beforeunload", event => {
152
+ disposeTelemetryLoggers();
153
+ });
154
+
155
+ if (state.appStates.conversationEndedByAgent) {
156
+ endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
157
+ }
147
158
  }, []);
148
159
  useEffect(() => {
149
- if (state.appStates.conversationState !== ConversationState.Closed) {
150
- canStartProactiveChat.current = false;
151
- }
160
+ canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed;
152
161
 
153
162
  if (state.appStates.conversationState === ConversationState.Active) {
154
163
  chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
@@ -159,7 +168,7 @@ export const LiveChatWidgetStateful = props => {
159
168
  } // Track the message count
160
169
 
161
170
 
162
- if (state.appStates.conversationState == ConversationState.Active) {
171
+ if (state.appStates.conversationState === ConversationState.Active) {
163
172
  chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
164
173
  currentMessageCountRef.current++;
165
174
  dispatch({
@@ -203,23 +212,25 @@ export const LiveChatWidgetStateful = props => {
203
212
  }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]);
204
213
  const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
205
214
 
206
- const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
215
+ const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch);
207
216
 
208
217
  const endChatRelay = () => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
209
218
 
210
219
  const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
211
220
 
212
221
 
213
- const initStartChatRelay = optionalParams => initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
222
+ const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
214
223
 
215
224
  const confirmationPaneProps = initConfirmationPropsComposer(props); // publish chat widget state
216
225
 
217
- const chatWidgetStateChangeEvent = {
218
- eventName: "ChatWidgetStateChanged",
219
- payload: { ...state
220
- }
221
- };
222
- BroadcastService.postMessage(chatWidgetStateChangeEvent);
226
+ useEffect(() => {
227
+ const chatWidgetStateChangeEvent = {
228
+ eventName: TelemetryEvent.ChatWidgetStateChanged,
229
+ payload: { ...state
230
+ }
231
+ };
232
+ BroadcastService.postMessage(chatWidgetStateChangeEvent);
233
+ }, [state]);
223
234
  return /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
224
235
  styleOptions: webChatStyles,
225
236
  directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? defaultWebChatContainerStatefulProps.directLine
@@ -4,11 +4,12 @@ import { extractPreChatSurveyResponseValues, findAllFocusableElement, parseAdapt
4
4
  import { ConversationState } from "../../contexts/common/ConversationState";
5
5
  import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
6
6
  import { PreChatSurveyPane } from "@microsoft/omnichannel-chat-components";
7
- import { HtmlAttributeNames, Regex } from "../../common/Constants";
7
+ import { Constants, HtmlAttributeNames, Regex } from "../../common/Constants";
8
8
  import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
9
9
  import { defaultGeneralPreChatSurveyPaneStyleProps } from "./common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps";
10
10
  import { defaultPreChatSurveyLocalizedTexts } from "./common/defaultProps/defaultPreChatSurveyLocalizedTexts";
11
- import useChatContextStore from "../../hooks/useChatContextStore"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ import useChatContextStore from "../../hooks/useChatContextStore";
12
+ import { DataStoreManager } from "../../common/contextDataStore/DataStoreManager"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
13
 
13
14
  export const PreChatSurveyPaneStateful = props => {
14
15
  var _surveyProps$stylePro, _props$surveyProps, _props$surveyProps$co;
@@ -66,14 +67,29 @@ export const PreChatSurveyPaneStateful = props => {
66
67
  });
67
68
 
68
69
  try {
69
- const prechatResponseValues = extractPreChatSurveyResponseValues(state.domainStates.preChatSurveyResponse, values);
70
- const optionalParams = {
71
- initContext: {
72
- preChatResponse: prechatResponseValues
73
- }
74
- };
75
- setPreChatResponseEmail(values);
76
- await initStartChat(optionalParams);
70
+ var _DataStoreManager$cli, _persistedState$domai;
71
+
72
+ const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(Constants.widgetStateDataKey, "localStorage");
73
+ const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
74
+ let optionalParams = {};
75
+
76
+ if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
77
+ var _persistedState$domai2;
78
+
79
+ optionalParams = {
80
+ liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai2 = persistedState.domainStates) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.liveChatContext
81
+ };
82
+ await initStartChat(optionalParams, persistedState);
83
+ } else {
84
+ const prechatResponseValues = extractPreChatSurveyResponseValues(state.domainStates.preChatSurveyResponse, values);
85
+ optionalParams = {
86
+ initContext: {
87
+ preChatResponse: prechatResponseValues
88
+ }
89
+ };
90
+ setPreChatResponseEmail(values);
91
+ await initStartChat(optionalParams);
92
+ }
77
93
  } catch (ex) {
78
94
  TelemetryHelper.logActionEvent(LogLevel.ERROR, {
79
95
  Event: TelemetryEvent.PreChatSurveyStartChatMethodFailed,
@@ -28,4 +28,8 @@ export let LiveChatWidgetActionType;
28
28
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_TELEMETRY_DATA"] = 24] = "SET_TELEMETRY_DATA";
29
29
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_RECONNECT_ID"] = 25] = "SET_RECONNECT_ID";
30
30
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_UNREAD_MESSAGE_COUNT"] = 26] = "SET_UNREAD_MESSAGE_COUNT";
31
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_FOCUS_CHAT_BUTTON"] = 27] = "SET_FOCUS_CHAT_BUTTON";
32
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_CONVERSATION_ENDED_BY_AGENT"] = 28] = "SET_CONVERSATION_ENDED_BY_AGENT";
33
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_STATE"] = 29] = "SET_WIDGET_STATE";
34
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_LIVE_CHAT_CONTEXT"] = 30] = "SET_LIVE_CHAT_CONTEXT";
31
35
  })(LiveChatWidgetActionType || (LiveChatWidgetActionType = {}));