@microsoft/omnichannel-chat-widget 0.1.0-main.dbc1afa → 0.1.0-main.df02f14

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 (105) hide show
  1. package/README.md +32 -0
  2. package/lib/cjs/common/Constants.js +16 -0
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +20 -2
  4. package/lib/cjs/common/utils.js +65 -6
  5. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +19 -3
  6. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  7. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +10 -1
  8. package/lib/cjs/components/headerstateful/HeaderStateful.js +4 -3
  9. package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
  10. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  11. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  12. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
  13. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  14. package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
  15. package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
  16. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  17. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -3
  18. package/lib/cjs/components/livechatwidget/common/endChat.js +55 -23
  19. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +16 -3
  20. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  21. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  22. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  23. package/lib/cjs/components/livechatwidget/common/startChat.js +169 -82
  24. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +219 -91
  25. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
  26. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  27. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  28. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -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/messageTimestampMiddleware.js +117 -0
  35. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  36. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +3 -0
  37. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
  38. package/lib/cjs/contexts/createReducer.js +16 -0
  39. package/lib/cjs/controller/componentController.js +3 -3
  40. package/lib/esm/common/Constants.js +16 -0
  41. package/lib/esm/common/telemetry/TelemetryConstants.js +20 -2
  42. package/lib/esm/common/utils.js +49 -4
  43. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +21 -6
  44. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  45. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -2
  46. package/lib/esm/components/headerstateful/HeaderStateful.js +4 -3
  47. package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
  48. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  49. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  50. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
  51. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  52. package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
  53. package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
  54. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  55. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -3
  56. package/lib/esm/components/livechatwidget/common/endChat.js +56 -23
  57. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +15 -5
  58. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  59. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  60. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  61. package/lib/esm/components/livechatwidget/common/startChat.js +162 -81
  62. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +213 -94
  63. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
  64. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  65. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  66. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -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/messageTimestampMiddleware.js +107 -0
  73. package/lib/esm/contexts/common/ConversationState.js +3 -2
  74. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +3 -0
  75. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
  76. package/lib/esm/contexts/createReducer.js +16 -0
  77. package/lib/esm/controller/componentController.js +3 -3
  78. package/lib/types/common/Constants.d.ts +8 -0
  79. package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
  80. package/lib/types/common/telemetry/TelemetryConstants.d.ts +20 -3
  81. package/lib/types/common/utils.d.ts +7 -3
  82. package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
  83. package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
  84. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  85. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  86. package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
  87. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  88. package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
  89. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +4 -3
  90. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  91. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  92. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
  93. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -0
  94. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
  95. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  96. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  97. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  98. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  99. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  100. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  101. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  102. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  103. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
  104. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +4 -1
  105. package/package.json +4 -3
@@ -7,7 +7,7 @@ import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostC
7
7
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
8
8
  import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
9
9
  import attachmentProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware";
10
- import { changeLanguageCodeFormatForWebChat } from "../../../common/utils";
10
+ import { addDelayInMs, changeLanguageCodeFormatForWebChat } from "../../../common/utils";
11
11
  import channelDataMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware";
12
12
  import { createActivityMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware";
13
13
  import createAttachmentMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware";
@@ -26,10 +26,13 @@ import gifUploadMiddleware from "../../webchatcontainerstateful/webchatcontrolle
26
26
  import htmlPlayerMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlPlayerMiddleware";
27
27
  import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware";
28
28
  import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
29
- 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/messageTimestampMiddleware";
32
+ import { Constants } from "../../../common/Constants"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
33
 
31
34
  export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
32
- 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;
35
+ 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;
33
36
 
34
37
  const localizedTexts = { ...defaultMiddlewareLocalizedTexts,
35
38
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -63,6 +66,12 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
63
66
 
64
67
  if (isPostChatEnabled === "true") {
65
68
  if (postChatSurveyMode === PostChatSurveyMode.Embed) {
69
+ WebChatStoreLoader.store = null;
70
+ dispatch({
71
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
72
+ payload: ConversationState.PostchatLoading
73
+ });
74
+ await addDelayInMs(Constants.PostChatLoadingDurationInMs);
66
75
  const loadPostChatEvent = {
67
76
  eventName: BroadcastEvent.LoadPostChatSurvey
68
77
  };
@@ -91,7 +100,7 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
91
100
  };
92
101
 
93
102
  webChatStore = createStore({}, //initial state
94
- 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
103
+ 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
95
104
  ...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
96
105
  WebChatStoreLoader.store = webChatStore;
97
106
  } // Initialize the remaining Web Chat props
@@ -109,7 +118,8 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
109
118
  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,
110
119
  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,
111
120
  onTelemetry: createWebChatTelemetry(),
112
- ...((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.webChatProps)
121
+ cardActionMiddleware: createCardActionMiddleware(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
122
+ ...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
113
123
  };
114
124
  return webChatProps;
115
125
  };
@@ -29,9 +29,17 @@ const getChatReconnectContext = async (chatSDK, reconnectId) => {
29
29
 
30
30
 
31
31
  const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
32
- var _props$reconnectChatP, _props$reconnectChatP2;
32
+ var _props$chatConfig, _props$reconnectChatP;
33
33
 
34
- if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && (_props$reconnectChatP2 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP2 !== void 0 && _props$reconnectChatP2.authClientFunction // TODO: Implement this after storage is in place
34
+ let authClientFunction = undefined;
35
+
36
+ if ((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) {
37
+ var _props$chatConfig2, _props$chatConfig2$Li;
38
+
39
+ authClientFunction = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveChatConfigAuthSettings) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_javascriptclientfunction) ?? undefined;
40
+ }
41
+
42
+ if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && authClientFunction // TODO: Implement this after storage is in place
35
43
 
36
44
  /* && !isLoadWithState() */
37
45
  ) {
@@ -46,27 +54,27 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
46
54
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
55
 
48
56
 
49
- const handleUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
57
+ const handleUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
50
58
  const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
51
59
 
52
60
  if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
53
- await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
61
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
54
62
  } else {
55
- await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
63
+ await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
56
64
  }
57
65
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
66
 
59
67
 
60
- const startUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
68
+ const startUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat) => {
61
69
  const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
62
70
 
63
71
  if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
64
- await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
72
+ await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
65
73
  }
66
74
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
75
 
68
76
 
69
- const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
77
+ const setReconnectIdAndStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat) => {
70
78
  const startUnauthenticatedReconnectChat = {
71
79
  eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
72
80
  };
@@ -82,7 +90,7 @@ const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconne
82
90
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
83
91
  payload: ConversationState.Loading
84
92
  });
85
- await initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
93
+ await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, optionalParams);
86
94
  };
87
95
 
88
96
  const redirectPage = (redirectURL, redirectInSameWindow) => {
@@ -104,7 +112,7 @@ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
104
112
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
113
 
106
114
 
107
- const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, initStartChat) => {
115
+ const startNewChatEmptyRedirectionUrl = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat) => {
108
116
  const startUnauthenticatedReconnectChat = {
109
117
  eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
110
118
  };
@@ -127,25 +135,25 @@ const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, in
127
135
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
128
136
  payload: ConversationState.Loading
129
137
  });
130
- await initStartChat(chatSDK, dispatch, setAdapter);
138
+ await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
131
139
  }
132
140
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
141
 
134
142
 
135
- const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
143
+ const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
136
144
  const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
137
145
 
138
146
  if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
139
- await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
147
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
140
148
  }
141
149
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
150
 
143
151
 
144
- const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
152
+ const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
145
153
  if (reconnectAvailabilityResponse.redirectURL) {
146
154
  redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
147
155
  } else {
148
- await startNewChatEmptyRedirectionUrl(chatSDK, dispatch, setAdapter, initStartChat);
156
+ await startNewChatEmptyRedirectionUrl(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat);
149
157
  }
150
158
  };
151
159
 
@@ -29,10 +29,6 @@ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persist
29
29
 
30
30
 
31
31
  BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
32
- dispatch({
33
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
34
- payload: ConversationState.Loading
35
- });
36
32
  dispatch({
37
33
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
38
34
  payload: ConversationState.Postchat
@@ -0,0 +1,38 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export function shareObservable(observable) {
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ let observers = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+
6
+ let subscription; // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+
8
+ return new window.Observable(observer => {
9
+ if (!subscription) {
10
+ subscription = observable.subscribe({
11
+ complete() {
12
+ observers.forEach(observer => observer.complete());
13
+ },
14
+
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ error(err) {
17
+ observers.forEach(observer => observer.error(err));
18
+ },
19
+
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ next(value) {
22
+ observers.forEach(observer => observer.next(value));
23
+ }
24
+
25
+ });
26
+ }
27
+
28
+ observers.push(observer);
29
+ return () => {
30
+ observers = observers.filter(o => o !== observer);
31
+
32
+ if (!observers.length) {
33
+ subscription.unsubscribe();
34
+ subscription = null;
35
+ }
36
+ };
37
+ });
38
+ }
@@ -1,7 +1,6 @@
1
1
  import { ChatSDKError } from "../../../common/Constants";
2
2
  import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
3
  import { ConversationState } from "../../../contexts/common/ConversationState";
4
- import { DataStoreManager } from "../../../common/contextDataStore/DataStoreManager";
5
4
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
6
5
  import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
7
6
  import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
@@ -9,16 +8,23 @@ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
9
8
  import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
10
9
  import { createAdapter } from "./createAdapter";
11
10
  import { createOnNewAdapterActivityHandler } from "../../../plugins/newMessageEventHandler";
12
- import { createTimer, getWidgetCacheId } from "../../../common/utils";
11
+ import { createTimer, getStateFromCache, isNullOrEmptyString, isUndefinedOrEmpty } from "../../../common/utils";
13
12
  import { getReconnectIdForAuthenticatedChat, handleRedirectUnauthenticatedReconnectChat } from "./reconnectChatHelper";
14
13
  import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
15
14
  import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
16
- import { BroadcastService } from "@microsoft/omnichannel-chat-components"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
16
+ import { ActivityStreamHandler } from "./ActivityStreamHandler"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
17
 
18
18
  let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
19
 
20
+ let widgetInstanceId; // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+
20
22
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
21
- var _props$reconnectChatP;
23
+ var _props$controlProps, _props$reconnectChatP;
24
+
25
+ optionalParams = {}; //Resetting to ensure no stale values
26
+
27
+ widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId; // Can connect to existing chat session
22
28
 
23
29
  if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
24
30
  return;
@@ -28,56 +34,98 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
28
34
  if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
29
35
  var _props$reconnectChatP2, _props$reconnectChatP3;
30
36
 
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);
32
- } else {
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
+ await handleRedirectUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, 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);
38
+ return;
39
+ } // Getting reconnectId for authenticated chat
37
40
 
38
- const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
39
41
 
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
42
+ const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
43
+
44
+ if (reconnectId) {
45
+ dispatch({
46
+ type: LiveChatWidgetActionType.SET_RECONNECT_ID,
47
+ payload: reconnectId
48
+ });
49
+ dispatch({
50
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
51
+ payload: ConversationState.ReconnectChat
52
+ });
53
+ return;
54
+ } // Setting Proactive chat settings
55
+
56
+
57
+ const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
58
+ const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
59
+
60
+ setPreChatAndInitiateChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
61
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+
63
+
64
+ const setPreChatAndInitiateChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
65
+ // Getting prechat Survey Context
66
+ const parseToJson = false;
67
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
68
+ const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
69
+
70
+ if (showPrechat) {
71
+ dispatch({
72
+ type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
73
+ payload: preChatSurveyResponse
74
+ });
75
+ dispatch({
76
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
77
+ payload: ConversationState.Prechat
78
+ });
79
+ return;
80
+ } //Initiate start chat
81
+
82
+
83
+ dispatch({
84
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
85
+ payload: ConversationState.Loading
86
+ });
87
+ await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
88
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+
90
+
91
+ const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
92
+ if (getAuthToken) {
93
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
94
+ Event: TelemetryEvent.GetAuthTokenCalled
95
+ });
96
+ let authClientFunction = undefined;
97
+
98
+ if (chatConfig !== null && chatConfig !== void 0 && chatConfig.LiveChatConfigAuthSettings) {
99
+ var _chatConfig$LiveChatC;
100
+
101
+ authClientFunction = (chatConfig === null || chatConfig === void 0 ? void 0 : (_chatConfig$LiveChatC = chatConfig.LiveChatConfigAuthSettings) === null || _chatConfig$LiveChatC === void 0 ? void 0 : _chatConfig$LiveChatC.msdyn_javascriptclientfunction) ?? undefined;
102
+ }
103
+
104
+ const token = await getAuthToken(authClientFunction);
105
+
106
+ if (!isNullOrEmptyString(token)) {
107
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
108
+ chatSDK.setAuthTokenProvider(async () => {
109
+ return token;
57
110
  });
58
- setCustomContextParams(props, state);
59
111
  } else {
60
- dispatch({
61
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
62
- payload: ConversationState.Loading
112
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
113
+ Event: TelemetryEvent.ReceivedNullOrEmptyToken
63
114
  });
64
- setCustomContextParams(props, state);
65
- await initStartChat(chatSDK, dispatch, setAdapter);
66
115
  }
67
116
  }
68
117
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
118
 
70
119
 
71
- const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedState) => {
120
+ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, params, persistedState) => {
72
121
  try {
73
122
  var _newAdapter$activity$, _TelemetryTimers$Widg;
74
123
 
75
- let isStartChatSuccessful = false;
124
+ let isStartChatSuccessful = false; //Check if chat retrieved from cache
76
125
 
77
126
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
78
127
  var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
79
128
 
80
- // Broadcasting limited cached chat details
81
129
  BroadcastService.postMessage({
82
130
  eventName: BroadcastEvent.ChatRetrievedFromCache,
83
131
  payload: {
@@ -88,11 +136,16 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
88
136
  }
89
137
 
90
138
  try {
139
+ //Start widget load timer
91
140
  TelemetryTimers.WidgetLoadTimer = createTimer();
92
141
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
93
142
  Event: TelemetryEvent.StartChatSDKCall
94
- });
95
- optionalParams = Object.assign({}, params, optionalParams);
143
+ }); // Set custom context params
144
+
145
+ setCustomContextParams(chatSDK);
146
+ optionalParams = Object.assign({}, params, optionalParams); // set auth token to chat sdk before start chat
147
+
148
+ await handleAuthentication(chatSDK, chatConfig, getAuthToken);
96
149
  await chatSDK.startChat(optionalParams);
97
150
  isStartChatSuccessful = true;
98
151
  } catch (error) {
@@ -102,46 +155,52 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
102
155
  exception: `Failed to setup startChat: ${error}`
103
156
  }
104
157
  });
105
- isStartChatSuccessful = false;
106
- }
158
+ isStartChatSuccessful = false; // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
159
+ // TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
160
+
161
+ dispatch({
162
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
163
+ payload: ConversationState.Closed
164
+ });
165
+ return;
166
+ } // New adapter creation
167
+
107
168
 
108
169
  const newAdapter = await createAdapter(chatSDK);
109
170
  setAdapter(newAdapter);
110
171
  const chatToken = await chatSDK.getChatToken();
172
+ dispatch({
173
+ type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
174
+ payload: chatToken
175
+ });
111
176
  newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe(createOnNewAdapterActivityHandler(chatToken === null || chatToken === void 0 ? void 0 : chatToken.chatId, chatToken === null || chatToken === void 0 ? void 0 : chatToken.visitorId));
112
177
 
113
- if (!persistedState) {
114
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
- if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
116
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
- const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
118
- dispatch({
119
- type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
120
- payload: chatToken
121
- });
122
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
-
124
-
125
- const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
126
- dispatch({
127
- type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
128
- payload: liveChatContext
129
- });
130
- await setPostChatContextAndLoadSurvey(chatSDK, dispatch);
131
- await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
132
-
133
- if (isStartChatSuccessful) {
134
- dispatch({
135
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
136
- payload: ConversationState.Active
137
- });
138
- }
139
- } else {
178
+ if (persistedState) {
140
179
  dispatch({
141
180
  type: LiveChatWidgetActionType.SET_WIDGET_STATE,
142
181
  payload: persistedState
143
182
  });
144
183
  await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
184
+ return;
185
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
186
+
187
+
188
+ const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
189
+ dispatch({
190
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
191
+ payload: liveChatContext
192
+ }); // Set post chat context in state, no survey load
193
+
194
+ await setPostChatContextAndLoadSurvey(chatSDK, dispatch); // Updating chat session detail for telemetry
195
+
196
+ await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
197
+
198
+ if (isStartChatSuccessful) {
199
+ ActivityStreamHandler.uncork();
200
+ dispatch({
201
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
202
+ payload: ConversationState.Active
203
+ });
145
204
  }
146
205
 
147
206
  TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
@@ -168,18 +227,24 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
168
227
  payload: ConversationState.OutOfOffice
169
228
  });
170
229
  }
230
+ } finally {
231
+ optionalParams = {};
232
+ widgetInstanceId = "";
171
233
  }
172
234
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
173
235
 
174
236
 
175
237
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
176
- var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli, _persistedState$domai6;
238
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps2, _persistedState$domai6, _persistedState$appSt;
239
+
240
+ // By pass this function in case of popout chat
241
+ if (state.appStates.skipChatButtonRendering === true) {
242
+ return false;
243
+ }
177
244
 
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");
180
- const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
245
+ const persistedState = getStateFromCache(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, (props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? ""); //Connect to only active chat session
181
246
 
182
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai6 = persistedState.domainStates) !== null && _persistedState$domai6 !== void 0 && _persistedState$domai6.liveChatContext) {
247
+ if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === ConversationState.Active) {
183
248
  var _persistedState$domai7;
184
249
 
185
250
  dispatch({
@@ -189,22 +254,38 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
189
254
  const optionalParams = {
190
255
  liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
191
256
  };
192
- await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
257
+ await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
193
258
  return true;
194
259
  } else {
195
260
  return false;
196
261
  }
197
- };
262
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
263
+
264
+
265
+ const setCustomContextParams = chatSDK => {
266
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _persistedState$domai8;
267
+
268
+ // Add custom context only for unauthenticated chat
269
+ const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId, widgetInstanceId ?? "");
270
+
271
+ if (!isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
272
+ var _persistedState$domai9, _persistedState$domai10;
198
273
 
199
- const setCustomContextParams = (props, state) => {
200
- var _props$chatConfig, _state$domainStates;
274
+ if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai9 = persistedState.domainStates.liveChatConfig) !== null && _persistedState$domai9 !== void 0 && _persistedState$domai9.LiveChatConfigAuthSettings) {
275
+ const errorMessage = "Use of custom context with authenticated chat is deprecated. The chat would not go through.";
276
+ TelemetryHelper.logSDKEvent(LogLevel.WARN, {
277
+ Event: TelemetryEvent.StartChatMethodException,
278
+ ExceptionDetails: {
279
+ exception: errorMessage
280
+ }
281
+ });
282
+ throw new Error(errorMessage);
283
+ }
201
284
 
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
285
  optionalParams = Object.assign({}, optionalParams, {
205
- customContext: state.domainStates.customContext
286
+ customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai10 = persistedState.domainStates) === null || _persistedState$domai10 === void 0 ? void 0 : _persistedState$domai10.customContext
206
287
  });
207
288
  }
208
289
  };
209
290
 
210
- export { prepareStartChat, initStartChat };
291
+ export { prepareStartChat, initStartChat, setPreChatAndInitiateChat };