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

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 (136) hide show
  1. package/README.md +35 -11
  2. package/lib/cjs/common/Constants.js +48 -6
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +36 -3
  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 +76 -2
  11. package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  12. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +20 -4
  13. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +4 -40
  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 +3 -9
  17. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  18. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  19. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  20. package/lib/cjs/components/livechatwidget/common/createAdapter.js +9 -1
  21. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  22. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +16 -16
  23. package/lib/cjs/components/livechatwidget/common/endChat.js +93 -10
  24. package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +1 -1
  25. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +23 -3
  26. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +107 -22
  27. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
  28. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  29. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  30. package/lib/cjs/components/livechatwidget/common/startChat.js +138 -50
  31. package/lib/cjs/components/livechatwidget/interfaces/IAuthProps.js +1 -0
  32. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +223 -68
  33. package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
  34. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -10
  35. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  36. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  37. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  38. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  39. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  40. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  41. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  42. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  43. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  44. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +45 -0
  45. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  46. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +9 -7
  47. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
  48. package/lib/cjs/contexts/createReducer.js +16 -10
  49. package/lib/cjs/controller/componentController.js +3 -3
  50. package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
  51. package/lib/esm/common/Constants.js +44 -5
  52. package/lib/esm/common/telemetry/TelemetryConstants.js +36 -3
  53. package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
  54. package/lib/esm/common/telemetry/TelemetryManager.js +14 -5
  55. package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  56. package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  57. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +36 -14
  58. package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
  59. package/lib/esm/common/utils.js +55 -1
  60. package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  61. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
  62. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -38
  63. package/lib/esm/components/footerstateful/FooterStateful.js +1 -2
  64. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
  65. package/lib/esm/components/headerstateful/HeaderStateful.js +3 -9
  66. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  67. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  68. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  69. package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -2
  70. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  71. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +16 -17
  72. package/lib/esm/components/livechatwidget/common/endChat.js +89 -11
  73. package/lib/esm/components/livechatwidget/common/initCallingSdk.js +1 -1
  74. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +21 -5
  75. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +98 -23
  76. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
  77. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  78. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  79. package/lib/esm/components/livechatwidget/common/startChat.js +138 -53
  80. package/lib/esm/components/livechatwidget/interfaces/IAuthProps.js +1 -0
  81. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +213 -72
  82. package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
  83. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -11
  84. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  85. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  86. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  87. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  88. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  89. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  90. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  91. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  92. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  93. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
  94. package/lib/esm/contexts/common/ConversationState.js +3 -2
  95. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +9 -7
  96. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
  97. package/lib/esm/contexts/createReducer.js +16 -9
  98. package/lib/esm/controller/componentController.js +3 -3
  99. package/lib/esm/plugins/newMessageEventHandler.js +10 -12
  100. package/lib/types/common/Constants.d.ts +24 -2
  101. package/lib/types/common/interfaces/IContextDataStore.d.ts +2 -2
  102. package/lib/types/common/telemetry/TelemetryConstants.d.ts +30 -5
  103. package/lib/types/common/telemetry/TelemetryHelper.d.ts +3 -1
  104. package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
  105. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
  106. package/lib/types/common/utils.d.ts +6 -0
  107. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
  108. package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
  109. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  110. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  111. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  112. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  113. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
  114. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +6 -2
  115. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  116. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  117. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  118. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
  119. package/lib/types/components/livechatwidget/interfaces/IAuthProps.d.ts +4 -0
  120. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  121. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +3 -1
  122. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -1
  123. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  124. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  125. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  126. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  127. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
  128. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  129. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  130. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  131. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  132. package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
  133. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  134. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
  135. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +10 -8
  136. package/package.json +6 -7
@@ -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";
@@ -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,13 @@ 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/messageTimestampMiddleware";
32
+ import { Constants } from "../../../common/Constants"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
33
 
30
34
  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;
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;
32
36
 
33
37
  const localizedTexts = { ...defaultMiddlewareLocalizedTexts,
34
38
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -62,6 +66,12 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
62
66
 
63
67
  if (isPostChatEnabled === "true") {
64
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);
65
75
  const loadPostChatEvent = {
66
76
  eventName: BroadcastEvent.LoadPostChatSurvey
67
77
  };
@@ -83,10 +93,14 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
83
93
  type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
84
94
  payload: undefined
85
95
  });
96
+ dispatch({
97
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
98
+ payload: undefined
99
+ });
86
100
  };
87
101
 
88
102
  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
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
90
104
  ...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
91
105
  WebChatStoreLoader.store = webChatStore;
92
106
  } // Initialize the remaining Web Chat props
@@ -103,7 +117,9 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
103
117
  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
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,
105
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,
106
- ...((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.webChatProps)
120
+ onTelemetry: createWebChatTelemetry(),
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)
107
123
  };
108
124
  return webChatProps;
109
125
  };
@@ -1,10 +1,11 @@
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
- import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
7
7
 
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
9
  const getChatReconnectContext = async (chatSDK, reconnectId) => {
9
10
  try {
10
11
  if (reconnectId) {
@@ -29,9 +30,9 @@ const getChatReconnectContext = async (chatSDK, reconnectId) => {
29
30
 
30
31
 
31
32
  const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
32
- var _props$reconnectChatP, _props$reconnectChatP2;
33
+ var _props$reconnectChatP, _props$authProps;
33
34
 
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
35
+ if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && (_props$authProps = props.authProps) !== null && _props$authProps !== void 0 && _props$authProps.authClientFunction // TODO: Implement this after storage is in place
35
36
 
36
37
  /* && !isLoadWithState() */
37
38
  ) {
@@ -46,33 +47,107 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
46
47
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
48
 
48
49
 
49
- const handleUnauthenticatedReconnectChat = async (dispatch, reconnectId, initStartChat) => {
50
- const reconnectAvailabilityResponse = await getChatReconnectContext(reconnectId);
50
+ const handleUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
51
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
51
52
 
52
- if (reconnectAvailabilityResponse && reconnectAvailabilityResponse.redirectURL) {
53
- redirectPage(reconnectAvailabilityResponse.redirectURL);
53
+ if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
54
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow);
54
55
  } else {
55
- const optionalParams = {
56
- reconnectId: reconnectId
57
- };
56
+ await setReconnectIdAndStartChat(chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat);
57
+ }
58
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+
60
+
61
+ const startUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat) => {
62
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
63
+
64
+ if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
65
+ await setReconnectIdAndStartChat(chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat);
66
+ }
67
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+
69
+
70
+ const setReconnectIdAndStartChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat) => {
71
+ const startUnauthenticatedReconnectChat = {
72
+ eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
73
+ };
74
+ BroadcastService.postMessage(startUnauthenticatedReconnectChat);
75
+ const optionalParams = {
76
+ reconnectId: reconnectId
77
+ };
78
+ dispatch({
79
+ type: LiveChatWidgetActionType.SET_RECONNECT_ID,
80
+ payload: reconnectId
81
+ });
82
+ dispatch({
83
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
84
+ payload: ConversationState.Loading
85
+ });
86
+ await initStartChat(chatSDK, authProps, dispatch, setAdapter, optionalParams);
87
+ };
88
+
89
+ const redirectPage = (redirectURL, redirectInSameWindow) => {
90
+ const redirectPageRequest = {
91
+ eventName: BroadcastEvent.RedirectPageRequest,
92
+ payload: {
93
+ redirectURL: redirectURL
94
+ }
95
+ };
96
+ BroadcastService.postMessage(redirectPageRequest);
97
+
98
+ if (redirectInSameWindow) {
99
+ window.location.href = redirectURL;
100
+ }
101
+ };
102
+
103
+ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
104
+ return reconnectAvailabilityResponse && !reconnectAvailabilityResponse.reconnectId;
105
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
+
107
+
108
+ const startNewChatEmptyRedirectionUrl = async (chatSDK, authProps, dispatch, setAdapter, initStartChat) => {
109
+ const startUnauthenticatedReconnectChat = {
110
+ eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
111
+ };
112
+ BroadcastService.postMessage(startUnauthenticatedReconnectChat); // Getting PreChat Survey Context
113
+
114
+ const parseToJson = false;
115
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
116
+
117
+ if (preChatSurveyResponse) {
58
118
  dispatch({
59
- type: LiveChatWidgetActionType.SET_RECONNECT_ID,
60
- payload: reconnectId
119
+ type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
120
+ payload: preChatSurveyResponse
61
121
  });
122
+ dispatch({
123
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
124
+ payload: ConversationState.Prechat
125
+ });
126
+ } else {
62
127
  dispatch({
63
128
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
64
129
  payload: ConversationState.Loading
65
130
  });
66
- await initStartChat(optionalParams);
131
+ await initStartChat(chatSDK, authProps, dispatch, setAdapter);
67
132
  }
68
- };
133
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
134
 
70
- const redirectPage = newUrl => {
71
- const data = {
72
- messageName: Constants.redirectPageRequest,
73
- newUrl: newUrl
74
- };
75
- window.parent.postMessage(data, "*");
135
+
136
+ const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
137
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
138
+
139
+ if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
140
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow);
141
+ }
142
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
+
144
+
145
+ const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
146
+ if (reconnectAvailabilityResponse.redirectURL) {
147
+ redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
148
+ } else {
149
+ await startNewChatEmptyRedirectionUrl(chatSDK, authProps, dispatch, setAdapter, initStartChat);
150
+ }
76
151
  };
77
152
 
78
- export { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat };
153
+ 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
@@ -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
- 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
- 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,20 +8,32 @@ 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 } from "../../../common/utils";
13
- import { getReconnectIdForAuthenticatedChat } from "./reconnectChatHelper";
11
+ import { createTimer, getStateFromCache, isUndefinedOrEmpty } from "../../../common/utils";
12
+ import { getReconnectIdForAuthenticatedChat, handleRedirectUnauthenticatedReconnectChat } from "./reconnectChatHelper";
14
13
  import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
15
- import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
15
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
18
 
17
19
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
20
+ var _props$reconnectChatP;
21
+
22
+ optionalParams = {}; //Resetting to ensure no stale values
23
+ // Can connect to existing chat session
24
+
18
25
  if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
19
26
  return;
20
- } // Getting PreChat Survey Context
27
+ } // Redirecting if unauthenticated reconnect chat expired
21
28
 
22
29
 
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
30
+ if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
31
+ var _props$reconnectChatP2, _props$reconnectChatP3;
32
+
33
+ await handleRedirectUnauthenticatedReconnectChat(chatSDK, props.authProps, 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);
34
+ return;
35
+ } // Getting reconnectId for authenticated chat
36
+
26
37
 
27
38
  const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
28
39
 
@@ -35,7 +46,26 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
35
46
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
36
47
  payload: ConversationState.ReconnectChat
37
48
  });
38
- } else if (showPrechat) {
49
+ return;
50
+ } // Set custom context params
51
+
52
+
53
+ setCustomContextParams(props, chatSDK); // Setting Proactive chat settings
54
+
55
+ const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
56
+ const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
57
+
58
+ setPreChatAndInitiateChat(chatSDK, props.authProps, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
59
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
+
61
+
62
+ const setPreChatAndInitiateChat = async (chatSDK, authProps, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
63
+ // Getting prechat Survey Context
64
+ const parseToJson = false;
65
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
66
+ const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
67
+
68
+ if (showPrechat) {
39
69
  dispatch({
40
70
  type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
41
71
  payload: preChatSurveyResponse
@@ -44,26 +74,51 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
44
74
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
45
75
  payload: ConversationState.Prechat
46
76
  });
47
- } else {
48
- dispatch({
49
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
50
- payload: ConversationState.Loading
51
- });
52
- await initStartChat(chatSDK, dispatch, setAdapter);
53
- }
77
+ return;
78
+ } //Initiate start chat
79
+
80
+
81
+ dispatch({
82
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
83
+ payload: ConversationState.Loading
84
+ });
85
+ await initStartChat(chatSDK, authProps, dispatch, setAdapter);
54
86
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
87
 
56
88
 
57
- const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedState) => {
89
+ const initStartChat = async (chatSDK, authProps, dispatch, setAdapter, params, persistedState) => {
58
90
  try {
59
91
  var _newAdapter$activity$, _TelemetryTimers$Widg;
60
92
 
93
+ let isStartChatSuccessful = false; //Check if chat retrieved from cache
94
+
95
+ if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
96
+ var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
97
+
98
+ BroadcastService.postMessage({
99
+ eventName: BroadcastEvent.ChatRetrievedFromCache,
100
+ payload: {
101
+ 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,
102
+ 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
103
+ }
104
+ });
105
+ }
106
+
61
107
  try {
108
+ //Start widget load timer
62
109
  TelemetryTimers.WidgetLoadTimer = createTimer();
63
110
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
64
111
  Event: TelemetryEvent.StartChatSDKCall
65
- });
66
- await chatSDK.startChat(params);
112
+ }); // Set optional params
113
+
114
+ optionalParams = Object.assign({}, params, optionalParams); // set auth token to chat sdk before start chat
115
+
116
+ if (authProps && authProps.setAuthTokenProviderToChatSdk) {
117
+ await authProps.setAuthTokenProviderToChatSdk(chatSDK, authProps.authClientFunction);
118
+ }
119
+
120
+ await chatSDK.startChat(optionalParams);
121
+ isStartChatSuccessful = true;
67
122
  } catch (error) {
68
123
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
69
124
  Event: TelemetryEvent.StartChatMethodException,
@@ -71,43 +126,51 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
71
126
  exception: `Failed to setup startChat: ${error}`
72
127
  }
73
128
  });
74
- }
129
+ isStartChatSuccessful = false; // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
130
+ // TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
131
+
132
+ dispatch({
133
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
134
+ payload: ConversationState.Closed
135
+ });
136
+ return;
137
+ } // New adapter creation
138
+
75
139
 
76
140
  const newAdapter = await createAdapter(chatSDK);
77
141
  setAdapter(newAdapter);
78
142
  const chatToken = await chatSDK.getChatToken();
143
+ dispatch({
144
+ type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
145
+ payload: chatToken
146
+ });
79
147
  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));
80
148
 
81
- if (!persistedState) {
82
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
- if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
84
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
- const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
86
- dispatch({
87
- type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
88
- payload: chatToken
89
- });
90
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
-
92
-
93
- const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
149
+ if (persistedState) {
94
150
  dispatch({
95
- type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
96
- payload: liveChatContext
151
+ type: LiveChatWidgetActionType.SET_WIDGET_STATE,
152
+ payload: persistedState
97
153
  });
98
- await setPostChatContextAndLoadSurvey(chatSDK, dispatch);
99
- await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
154
+ await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
155
+ return;
156
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
157
+
158
+
159
+ const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
160
+ dispatch({
161
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
162
+ payload: liveChatContext
163
+ }); // Set post chat context in state, no survey load
100
164
 
165
+ await setPostChatContextAndLoadSurvey(chatSDK, dispatch); // Updating chat session detail for telemetry
166
+
167
+ await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
168
+
169
+ if (isStartChatSuccessful) {
101
170
  dispatch({
102
171
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
103
172
  payload: ConversationState.Active
104
173
  });
105
- } else {
106
- dispatch({
107
- type: LiveChatWidgetActionType.SET_WIDGET_STATE,
108
- payload: persistedState
109
- });
110
- await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
111
174
  }
112
175
 
113
176
  TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
@@ -134,31 +197,53 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
134
197
  payload: ConversationState.OutOfOffice
135
198
  });
136
199
  }
200
+ } finally {
201
+ optionalParams = {};
137
202
  }
138
203
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
204
 
140
205
 
141
206
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
142
- var _DataStoreManager$cli, _persistedState$domai;
207
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _persistedState$domai6, _persistedState$appSt;
208
+
209
+ // By pass this function in case of popout chat
210
+ if (state.appStates.skipChatButtonRendering === true) {
211
+ return false;
212
+ }
143
213
 
144
- const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(Constants.widgetStateDataKey, "localStorage");
145
- const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
214
+ 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); //Connect to only active chat session
146
215
 
147
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
148
- var _persistedState$domai2;
216
+ 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) {
217
+ var _persistedState$domai7;
149
218
 
150
219
  dispatch({
151
220
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
152
221
  payload: ConversationState.Loading
153
222
  });
154
223
  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
224
+ liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
156
225
  };
157
- await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
226
+ await initStartChat(chatSDK, props.authProps, dispatch, setAdapter, optionalParams, persistedState);
158
227
  return true;
159
228
  } else {
160
229
  return false;
161
230
  }
231
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
232
+
233
+
234
+ const setCustomContextParams = (props, chatSDK) => {
235
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _props$chatConfig, _persistedState$domai8;
236
+
237
+ // Add custom context only for unauthenticated chat
238
+ 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);
239
+
240
+ if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
241
+ var _persistedState$domai9;
242
+
243
+ optionalParams = Object.assign({}, optionalParams, {
244
+ customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
245
+ });
246
+ }
162
247
  };
163
248
 
164
- export { prepareStartChat, initStartChat };
249
+ export { prepareStartChat, initStartChat, setPreChatAndInitiateChat };