@microsoft/omnichannel-chat-widget 0.1.0-main.c461296 → 0.1.0-main.d80ebb6

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 (101) hide show
  1. package/README.md +35 -11
  2. package/lib/cjs/common/Constants.js +46 -6
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +27 -2
  4. package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
  5. package/lib/cjs/common/telemetry/TelemetryManager.js +16 -5
  6. package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  7. package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  8. package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +33 -13
  9. package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
  10. package/lib/cjs/common/utils.js +30 -2
  11. package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  12. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +16 -4
  13. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +4 -39
  14. package/lib/cjs/components/footerstateful/FooterStateful.js +1 -2
  15. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
  16. package/lib/cjs/components/headerstateful/HeaderStateful.js +1 -7
  17. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +12 -15
  18. package/lib/cjs/components/livechatwidget/common/endChat.js +63 -12
  19. package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +1 -1
  20. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +15 -3
  21. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +105 -20
  22. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
  23. package/lib/cjs/components/livechatwidget/common/startChat.js +87 -39
  24. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +113 -21
  25. package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
  26. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -5
  27. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +16 -0
  28. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  29. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  30. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  31. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  32. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  33. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  34. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/mesageTimestampMiddleware.js +116 -0
  35. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +45 -0
  36. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +8 -7
  37. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -1
  38. package/lib/cjs/contexts/createReducer.js +8 -10
  39. package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
  40. package/lib/esm/common/Constants.js +42 -5
  41. package/lib/esm/common/telemetry/TelemetryConstants.js +27 -2
  42. package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
  43. package/lib/esm/common/telemetry/TelemetryManager.js +14 -5
  44. package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  45. package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  46. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +36 -14
  47. package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
  48. package/lib/esm/common/utils.js +19 -1
  49. package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  50. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +18 -6
  51. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -37
  52. package/lib/esm/components/footerstateful/FooterStateful.js +1 -2
  53. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
  54. package/lib/esm/components/headerstateful/HeaderStateful.js +1 -7
  55. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +12 -16
  56. package/lib/esm/components/livechatwidget/common/endChat.js +58 -13
  57. package/lib/esm/components/livechatwidget/common/initCallingSdk.js +1 -1
  58. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +13 -4
  59. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +94 -20
  60. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
  61. package/lib/esm/components/livechatwidget/common/startChat.js +90 -44
  62. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +106 -24
  63. package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
  64. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +6 -7
  65. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +16 -0
  66. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  67. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  68. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  69. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  70. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  71. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  72. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/mesageTimestampMiddleware.js +106 -0
  73. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
  74. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +8 -7
  75. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -1
  76. package/lib/esm/contexts/createReducer.js +8 -9
  77. package/lib/esm/plugins/newMessageEventHandler.js +10 -12
  78. package/lib/types/common/Constants.d.ts +23 -2
  79. package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
  80. package/lib/types/common/telemetry/TelemetryConstants.d.ts +22 -4
  81. package/lib/types/common/telemetry/TelemetryHelper.d.ts +2 -0
  82. package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
  83. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
  84. package/lib/types/common/utils.d.ts +3 -0
  85. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
  86. package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
  87. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
  88. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -2
  89. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  90. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -1
  91. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -0
  92. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  93. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  94. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  95. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  96. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  97. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/mesageTimestampMiddleware.d.ts +5 -0
  98. package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
  99. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -0
  100. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +9 -8
  101. package/package.json +6 -7
@@ -9,7 +9,8 @@ import createAttachmentMiddleware from "../../../webchatcontainerstateful/webcha
9
9
  import { createAvatarMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware";
10
10
  import { createMarkdown } from "../createMarkdown";
11
11
  import { groupActivitiesMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/groupActivitiesMiddleware";
12
- import { typingIndicatorMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware"; // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ import { typingIndicatorMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware";
13
+ import { createWebChatTelemetry } from "../../../webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger"; // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
14
 
14
15
  export const dummyDefaultProps = {
15
16
  audioNotificationProps: {
@@ -252,18 +253,6 @@ export const dummyDefaultProps = {
252
253
  width: "50px",
253
254
  fontSize: "18px"
254
255
  },
255
- currentCallTimerStyleProps: {
256
- borderRadius: "2px",
257
- margin: "1px",
258
- color: "#FFFFFF",
259
- paddingTop: "18px",
260
- fontSize: 12,
261
- fontFamily: "Segoe UI, Arial, sans-serif",
262
- backgroundColor: "darkgrey",
263
- height: "45px",
264
- width: "50px",
265
- textAlign: "center"
266
- },
267
256
  videoTileStyleProps: {
268
257
  width: "100%",
269
258
  marginLeft: "auto",
@@ -327,7 +316,9 @@ export const dummyDefaultProps = {
327
316
  hideChatTextContainer: false,
328
317
  hideChatSubtitle: false,
329
318
  hideChatTitle: false,
330
- hideNotificationBubble: true
319
+ hideNotificationBubble: true,
320
+ unreadMessageString: "new messages",
321
+ largeUnreadMessageString: "99+"
331
322
  },
332
323
  styleProps: {
333
324
  generalStyleProps: {
@@ -1424,7 +1415,8 @@ export const dummyDefaultProps = {
1424
1415
  },
1425
1416
  authClientFunction: undefined,
1426
1417
  isReconnectEnabled: undefined,
1427
- reconnectId: undefined
1418
+ reconnectId: undefined,
1419
+ redirectInSameWindow: undefined
1428
1420
  },
1429
1421
  styleProps: {
1430
1422
  generalStyles: {
@@ -1496,7 +1488,7 @@ export const dummyDefaultProps = {
1496
1488
  internalErrorBoxClass: undefined,
1497
1489
  internalRenderErrorBox: undefined,
1498
1490
  locale: "en-US",
1499
- onTelemetry: undefined,
1491
+ onTelemetry: createWebChatTelemetry(),
1500
1492
  overrideLocalizedStrings: undefined,
1501
1493
  renderMarkdown: createMarkdown(false, false),
1502
1494
  scrollToEndButtonMiddleware: undefined,
@@ -1686,6 +1678,10 @@ export const dummyDefaultProps = {
1686
1678
  MIDDLEWARE_MESSAGE_RETRY: "Retry",
1687
1679
  PRECHAT_REQUIRED_FIELD_MISSING_MESSAGE: "{0} field is required",
1688
1680
  MARKDOWN_EXTERNAL_LINK_ALT: "Opens in a new window; external."
1681
+ },
1682
+ botMagicCode: {
1683
+ disabled: false,
1684
+ fwdUrl: ""
1689
1685
  }
1690
1686
  },
1691
1687
  telemetryConfig: undefined
@@ -4,15 +4,56 @@ import { ConversationState } from "../../../contexts/common/ConversationState";
4
4
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
5
5
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
6
6
  import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
7
- import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
8
+ import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
9
+ import { Constants } from "../../../common/Constants";
10
+ import { getWidgetEndChatEventName } from "../../../common/utils"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
11
 
9
- export const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat) => {
12
+ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
13
+ var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4;
14
+
15
+ const isPostChatEnabled = (_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable;
16
+ const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode;
17
+ const conversationDetails = await chatSDK.getConversationDetails();
18
+
19
+ if (isPostChatEnabled === "true" && (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === Constants.truePascal) {
20
+ const skipEndChatSDK = false;
21
+ const skipCloseChat = true;
22
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, true);
23
+
24
+ if (postChatSurveyMode === PostChatSurveyMode.Embed) {
25
+ const loadPostChatEvent = {
26
+ eventName: BroadcastEvent.LoadPostChatSurvey
27
+ };
28
+ BroadcastService.postMessage(loadPostChatEvent);
29
+ } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
30
+ dispatch({
31
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
32
+ payload: ConversationState.InActive
33
+ });
34
+ }
35
+ } else {
36
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
37
+ }
38
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+
40
+
41
+ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => {
10
42
  if (!skipEndChatSDK) {
11
43
  try {
12
44
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
13
45
  Event: TelemetryEvent.EndChatSDKCall
14
46
  });
15
- await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
47
+ await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat()); // Need to clear these states immediately when chat ended from OC.
48
+
49
+ dispatch({
50
+ type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
51
+ payload: undefined
52
+ });
53
+ dispatch({
54
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
55
+ payload: undefined
56
+ });
16
57
  } catch (ex) {
17
58
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
18
59
  Event: TelemetryEvent.EndChatSDKCallFailed,
@@ -20,6 +61,7 @@ export const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
20
61
  exception: ex
21
62
  }
22
63
  });
64
+ postMessageToOtherTab = false;
23
65
  }
24
66
  }
25
67
 
@@ -49,17 +91,18 @@ export const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
49
91
  type: LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
50
92
  payload: null
51
93
  });
52
- dispatch({
53
- type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
54
- payload: undefined
55
- });
56
- dispatch({
57
- type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
58
- payload: undefined
59
- });
60
94
  BroadcastService.postMessage({
61
- eventName: BroadcastEvent.EndChat
95
+ eventName: BroadcastEvent.ChatEnded
62
96
  });
97
+
98
+ if (postMessageToOtherTab) {
99
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
100
+
101
+ const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId);
102
+ BroadcastService.postMessage({
103
+ eventName: endChatEventName
104
+ });
105
+ }
63
106
  } catch (error) {
64
107
  TelemetryHelper.logActionEvent(LogLevel.ERROR, {
65
108
  Event: TelemetryEvent.CloseChatMethodException,
@@ -69,4 +112,6 @@ export const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
69
112
  });
70
113
  }
71
114
  }
72
- };
115
+ };
116
+
117
+ export { prepareEndChat, endChat };
@@ -8,7 +8,7 @@ export const initCallingSdk = async (chatSDK, setVoiceVideoCallingSDK) => {
8
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
9
  const callingSDK = await chatSDK.getVoiceVideoCalling();
10
10
  setVoiceVideoCallingSDK(callingSDK);
11
- TelemetryHelper.logCallingEvent(LogLevel.ERROR, {
11
+ TelemetryHelper.logCallingEvent(LogLevel.INFO, {
12
12
  Event: TelemetryEvent.CallingSDKLoadSuccess
13
13
  });
14
14
  return true;
@@ -17,6 +17,7 @@ import createConversationEndMiddleware from "../../webchatcontainerstateful/webc
17
17
  import createDataMaskingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/dataMaskingMiddleware";
18
18
  import { createMarkdown } from "./createMarkdown";
19
19
  import createMaxMessageSizeValidator from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/maxMessageSizeValidator";
20
+ import { createWebChatTelemetry } from "../../webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger";
20
21
  import { defaultAttachmentProps } from "../../webchatcontainerstateful/common/defaultProps/defaultAttachmentProps";
21
22
  import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
22
23
  import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
@@ -25,10 +26,12 @@ import gifUploadMiddleware from "../../webchatcontainerstateful/webchatcontrolle
25
26
  import htmlPlayerMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlPlayerMiddleware";
26
27
  import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware";
27
28
  import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
28
- import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
30
+ import { createCardActionMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware";
31
+ import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/mesageTimestampMiddleware"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
32
 
30
33
  export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
31
- 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;
34
+ 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, _props$webChatContain22;
32
35
 
33
36
  const localizedTexts = { ...defaultMiddlewareLocalizedTexts,
34
37
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -83,10 +86,14 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
83
86
  type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
84
87
  payload: undefined
85
88
  });
89
+ dispatch({
90
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
91
+ payload: undefined
92
+ });
86
93
  };
87
94
 
88
95
  webChatStore = createStore({}, //initial state
89
- preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.allowedFileExtensions, (_state$domainStates$l6 = state.domainStates.liveChatConfig) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware, // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
+ preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.allowedFileExtensions, (_state$domainStates$l6 = state.domainStates.liveChatConfig) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), createMessageTimeStampMiddleware, gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware, // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
97
  ...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
91
98
  WebChatStoreLoader.store = webChatStore;
92
99
  } // Initialize the remaining Web Chat props
@@ -103,7 +110,9 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
103
110
  avatarMiddleware: (_props$webChatContain15 = props.webChatContainerProps) !== null && _props$webChatContain15 !== void 0 && (_props$webChatContain16 = _props$webChatContain15.renderingMiddlewareProps) !== null && _props$webChatContain16 !== void 0 && _props$webChatContain16.disableAvatarMiddleware ? undefined : createAvatarMiddleware((_state$domainStates$r5 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r5 === void 0 ? void 0 : _state$domainStates$r5.avatarStyleProps, (_state$domainStates$r6 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r6 === void 0 ? void 0 : _state$domainStates$r6.avatarTextStyleProps),
104
111
  groupActivitiesMiddleware: (_props$webChatContain17 = props.webChatContainerProps) !== null && _props$webChatContain17 !== void 0 && (_props$webChatContain18 = _props$webChatContain17.renderingMiddlewareProps) !== null && _props$webChatContain18 !== void 0 && _props$webChatContain18.disableGroupActivitiesMiddleware ? undefined : (_defaultWebChatContai2 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai2 === void 0 ? void 0 : _defaultWebChatContai2.groupActivitiesMiddleware,
105
112
  typingIndicatorMiddleware: (_props$webChatContain19 = props.webChatContainerProps) !== null && _props$webChatContain19 !== void 0 && (_props$webChatContain20 = _props$webChatContain19.renderingMiddlewareProps) !== null && _props$webChatContain20 !== void 0 && _props$webChatContain20.disableTypingIndicatorMiddleware ? undefined : (_defaultWebChatContai3 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai3 === void 0 ? void 0 : _defaultWebChatContai3.typingIndicatorMiddleware,
106
- ...((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.webChatProps)
113
+ onTelemetry: createWebChatTelemetry(),
114
+ cardActionMiddleware: createCardActionMiddleware(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
115
+ ...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
107
116
  };
108
117
  return webChatProps;
109
118
  };
@@ -1,6 +1,6 @@
1
1
  import "regenerator-runtime/runtime";
2
- import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
- import { Constants } from "../../../common/Constants";
2
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
4
4
  import { ConversationState } from "../../../contexts/common/ConversationState";
5
5
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
6
6
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -46,33 +46,107 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
46
46
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
47
 
48
48
 
49
- const handleUnauthenticatedReconnectChat = async (dispatch, reconnectId, initStartChat) => {
50
- const reconnectAvailabilityResponse = await getChatReconnectContext(reconnectId);
49
+ const handleUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
50
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
51
51
 
52
- if (reconnectAvailabilityResponse && reconnectAvailabilityResponse.redirectURL) {
53
- redirectPage(reconnectAvailabilityResponse.redirectURL);
52
+ if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
53
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
54
54
  } else {
55
- const optionalParams = {
56
- reconnectId: reconnectId
57
- };
55
+ await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
56
+ }
57
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
+
59
+
60
+ const startUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
61
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
62
+
63
+ if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
64
+ await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
65
+ }
66
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+
68
+
69
+ const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
70
+ const startUnauthenticatedReconnectChat = {
71
+ eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
72
+ };
73
+ BroadcastService.postMessage(startUnauthenticatedReconnectChat);
74
+ const optionalParams = {
75
+ reconnectId: reconnectId
76
+ };
77
+ dispatch({
78
+ type: LiveChatWidgetActionType.SET_RECONNECT_ID,
79
+ payload: reconnectId
80
+ });
81
+ dispatch({
82
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
83
+ payload: ConversationState.Loading
84
+ });
85
+ await initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
86
+ };
87
+
88
+ const redirectPage = (redirectURL, redirectInSameWindow) => {
89
+ const redirectPageRequest = {
90
+ eventName: BroadcastEvent.RedirectPageRequest,
91
+ payload: {
92
+ redirectURL: redirectURL
93
+ }
94
+ };
95
+ BroadcastService.postMessage(redirectPageRequest);
96
+
97
+ if (redirectInSameWindow) {
98
+ window.location.href = redirectURL;
99
+ }
100
+ };
101
+
102
+ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
103
+ return reconnectAvailabilityResponse && !reconnectAvailabilityResponse.reconnectId;
104
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
+
106
+
107
+ const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, initStartChat) => {
108
+ const startUnauthenticatedReconnectChat = {
109
+ eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
110
+ };
111
+ BroadcastService.postMessage(startUnauthenticatedReconnectChat); // Getting PreChat Survey Context
112
+
113
+ const parseToJson = false;
114
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
115
+
116
+ if (preChatSurveyResponse) {
58
117
  dispatch({
59
- type: LiveChatWidgetActionType.SET_RECONNECT_ID,
60
- payload: reconnectId
118
+ type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
119
+ payload: preChatSurveyResponse
61
120
  });
121
+ dispatch({
122
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
123
+ payload: ConversationState.Prechat
124
+ });
125
+ } else {
62
126
  dispatch({
63
127
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
64
128
  payload: ConversationState.Loading
65
129
  });
66
- await initStartChat(optionalParams);
130
+ await initStartChat(chatSDK, dispatch, setAdapter);
67
131
  }
68
- };
132
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
133
 
70
- const redirectPage = newUrl => {
71
- const data = {
72
- messageName: Constants.redirectPageRequest,
73
- newUrl: newUrl
74
- };
75
- window.parent.postMessage(data, "*");
134
+
135
+ const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
136
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
137
+
138
+ if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
139
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
140
+ }
141
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
+
143
+
144
+ const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
145
+ if (reconnectAvailabilityResponse.redirectURL) {
146
+ redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
147
+ } else {
148
+ await startNewChatEmptyRedirectionUrl(chatSDK, dispatch, setAdapter, initStartChat);
149
+ }
76
150
  };
77
151
 
78
- export { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat };
152
+ export { getChatReconnectContext, getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat, startUnauthenticatedReconnectChat, handleRedirectUnauthenticatedReconnectChat };
@@ -1,22 +1,12 @@
1
- import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
2
1
  import { RegisterLoggers, TelemetryManager } from "../../../common/telemetry/TelemetryManager";
2
+ import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
3
3
  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 { version as chatComponentVersion } from "@microsoft/omnichannel-chat-components/package.json";
8
- import { version as chatSdkVersion } from "@microsoft/omnichannel-chat-sdk/package.json";
9
7
  export const registerTelemetryLoggers = (props, dispatch) => {
10
8
  var _props$liveChatContex, _props$liveChatContex2;
11
9
 
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
-
20
10
  const telemetryConfig = { ...defaultTelemetryConfiguration,
21
11
  ...props.telemetryConfig
22
12
  };
@@ -38,12 +28,13 @@ export const registerTelemetryLoggers = (props, dispatch) => {
38
28
  }
39
29
 
40
30
  telemetryData = TelemetryHelper.addWidgetDataToTelemetry(telemetryConfig, telemetryData);
41
- telemetryData.OCChatSDKVersion = chatSdkVersion;
42
- telemetryData.chatComponentVersion = chatComponentVersion;
43
- telemetryData.chatWidgetVersion = widgetPackageInfo;
31
+ telemetryData.OCChatSDKVersion = telemetryConfig.OCChatSDKVersion ?? "0.0.0-0";
32
+ telemetryData.chatComponentVersion = telemetryConfig.chatComponentVersion ?? "0.0.0-0";
33
+ telemetryData.chatWidgetVersion = telemetryConfig.chatWidgetVersion ?? "0.0.0-0";
44
34
  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
35
  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
36
  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;
37
+ TelemetryManager.InternalTelemetryData = telemetryData;
47
38
  dispatch({
48
39
  type: LiveChatWidgetActionType.SET_TELEMETRY_DATA,
49
40
  payload: telemetryData
@@ -1,5 +1,5 @@
1
- import { ChatSDKError, Constants } from "../../../common/Constants";
2
- import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
1
+ import { ChatSDKError } from "../../../common/Constants";
2
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
3
  import { ConversationState } from "../../../contexts/common/ConversationState";
4
4
  import { DataStoreManager } from "../../../common/contextDataStore/DataStoreManager";
5
5
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
@@ -9,47 +9,61 @@ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
9
9
  import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
10
10
  import { createAdapter } from "./createAdapter";
11
11
  import { createOnNewAdapterActivityHandler } from "../../../plugins/newMessageEventHandler";
12
- import { createTimer } from "../../../common/utils";
13
- import { getReconnectIdForAuthenticatedChat } from "./reconnectChatHelper";
12
+ import { createTimer, getWidgetCacheId } from "../../../common/utils";
13
+ import { getReconnectIdForAuthenticatedChat, handleRedirectUnauthenticatedReconnectChat } from "./reconnectChatHelper";
14
14
  import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
15
- import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
16
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+
18
+ let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
19
 
17
20
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
21
+ var _props$reconnectChatP;
22
+
18
23
  if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
19
24
  return;
20
- } // Getting PreChat Survey Context
25
+ } // Redirecting if unauthenticated reconnect chat expired
21
26
 
22
27
 
23
- const parseToJson = false;
24
- const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
25
- const showPrechat = state.appStates.conversationState === ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
28
+ if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
29
+ var _props$reconnectChatP2, _props$reconnectChatP3;
26
30
 
27
- const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
28
-
29
- if (reconnectId) {
30
- dispatch({
31
- type: LiveChatWidgetActionType.SET_RECONNECT_ID,
32
- payload: reconnectId
33
- });
34
- dispatch({
35
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
36
- payload: ConversationState.ReconnectChat
37
- });
38
- } else if (showPrechat) {
39
- dispatch({
40
- type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
41
- payload: preChatSurveyResponse
42
- });
43
- dispatch({
44
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
45
- payload: ConversationState.Prechat
46
- });
31
+ await handleRedirectUnauthenticatedReconnectChat(chatSDK, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.redirectInSameWindow);
47
32
  } else {
48
- dispatch({
49
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
50
- payload: ConversationState.Loading
51
- });
52
- await initStartChat(chatSDK, dispatch, setAdapter);
33
+ // Getting PreChat Survey Context
34
+ const parseToJson = false;
35
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
36
+ const showPrechat = state.appStates.conversationState === ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
37
+
38
+ const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
39
+
40
+ if (reconnectId) {
41
+ dispatch({
42
+ type: LiveChatWidgetActionType.SET_RECONNECT_ID,
43
+ payload: reconnectId
44
+ });
45
+ dispatch({
46
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
47
+ payload: ConversationState.ReconnectChat
48
+ });
49
+ } else if (showPrechat) {
50
+ dispatch({
51
+ type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
52
+ payload: preChatSurveyResponse
53
+ });
54
+ dispatch({
55
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
56
+ payload: ConversationState.Prechat
57
+ });
58
+ setCustomContextParams(props, state);
59
+ } else {
60
+ dispatch({
61
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
62
+ payload: ConversationState.Loading
63
+ });
64
+ setCustomContextParams(props, state);
65
+ await initStartChat(chatSDK, dispatch, setAdapter);
66
+ }
53
67
  }
54
68
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
69
 
@@ -58,12 +72,29 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
58
72
  try {
59
73
  var _newAdapter$activity$, _TelemetryTimers$Widg;
60
74
 
75
+ let isStartChatSuccessful = false;
76
+
77
+ if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
78
+ var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
79
+
80
+ // Broadcasting limited cached chat details
81
+ BroadcastService.postMessage({
82
+ eventName: BroadcastEvent.ChatRetrievedFromCache,
83
+ payload: {
84
+ chatId: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : (_persistedState$domai2 = _persistedState$domai.liveChatContext) === null || _persistedState$domai2 === void 0 ? void 0 : (_persistedState$domai3 = _persistedState$domai2.chatToken) === null || _persistedState$domai3 === void 0 ? void 0 : _persistedState$domai3.chatId,
85
+ requestId: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai4 = persistedState.domainStates) === null || _persistedState$domai4 === void 0 ? void 0 : (_persistedState$domai5 = _persistedState$domai4.liveChatContext) === null || _persistedState$domai5 === void 0 ? void 0 : _persistedState$domai5.requestId
86
+ }
87
+ });
88
+ }
89
+
61
90
  try {
62
91
  TelemetryTimers.WidgetLoadTimer = createTimer();
63
92
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
64
93
  Event: TelemetryEvent.StartChatSDKCall
65
94
  });
66
- await chatSDK.startChat(params);
95
+ optionalParams = Object.assign({}, params, optionalParams);
96
+ await chatSDK.startChat(optionalParams);
97
+ isStartChatSuccessful = true;
67
98
  } catch (error) {
68
99
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
69
100
  Event: TelemetryEvent.StartChatMethodException,
@@ -71,6 +102,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
71
102
  exception: `Failed to setup startChat: ${error}`
72
103
  }
73
104
  });
105
+ isStartChatSuccessful = false;
74
106
  }
75
107
 
76
108
  const newAdapter = await createAdapter(chatSDK);
@@ -98,10 +130,12 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
98
130
  await setPostChatContextAndLoadSurvey(chatSDK, dispatch);
99
131
  await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
100
132
 
101
- dispatch({
102
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
103
- payload: ConversationState.Active
104
- });
133
+ if (isStartChatSuccessful) {
134
+ dispatch({
135
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
136
+ payload: ConversationState.Active
137
+ });
138
+ }
105
139
  } else {
106
140
  dispatch({
107
141
  type: LiveChatWidgetActionType.SET_WIDGET_STATE,
@@ -139,20 +173,21 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
139
173
 
140
174
 
141
175
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
142
- var _DataStoreManager$cli, _persistedState$domai;
176
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli, _persistedState$domai6;
143
177
 
144
- const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(Constants.widgetStateDataKey, "localStorage");
178
+ const widgetStateEventName = getWidgetCacheId((chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId) ?? "", (chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId) ?? "");
179
+ const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
145
180
  const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
146
181
 
147
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
148
- var _persistedState$domai2;
182
+ if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai6 = persistedState.domainStates) !== null && _persistedState$domai6 !== void 0 && _persistedState$domai6.liveChatContext) {
183
+ var _persistedState$domai7;
149
184
 
150
185
  dispatch({
151
186
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
152
187
  payload: ConversationState.Loading
153
188
  });
154
189
  const optionalParams = {
155
- liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai2 = persistedState.domainStates) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.liveChatContext
190
+ liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
156
191
  };
157
192
  await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
158
193
  return true;
@@ -161,4 +196,15 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
161
196
  }
162
197
  };
163
198
 
199
+ const setCustomContextParams = (props, state) => {
200
+ var _props$chatConfig, _state$domainStates;
201
+
202
+ // Add custom context if any only for unauthenticated chat
203
+ if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && (_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.customContext) {
204
+ optionalParams = Object.assign({}, optionalParams, {
205
+ customContext: state.domainStates.customContext
206
+ });
207
+ }
208
+ };
209
+
164
210
  export { prepareStartChat, initStartChat };