@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
@@ -43,6 +43,8 @@ var _createMarkdown = require("./createMarkdown");
43
43
 
44
44
  var _maxMessageSizeValidator = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/maxMessageSizeValidator"));
45
45
 
46
+ var _WebChatLogger = require("../../webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger");
47
+
46
48
  var _defaultAttachmentProps = require("../../webchatcontainerstateful/common/defaultProps/defaultAttachmentProps");
47
49
 
48
50
  var _defaultMiddlewareLocalizedTexts = require("../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts");
@@ -61,11 +63,17 @@ var _preProcessingMiddleware = _interopRequireDefault(require("../../webchatcont
61
63
 
62
64
  var _sanitizationMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware"));
63
65
 
66
+ var _cardActionMiddleware = require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware");
67
+
68
+ var _messageTimestampMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware"));
69
+
70
+ var _Constants = require("../../../common/Constants");
71
+
64
72
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
65
73
 
66
74
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
75
  const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
68
- 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;
76
+ 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;
69
77
 
70
78
  const localizedTexts = { ..._defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts,
71
79
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -99,6 +107,12 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
99
107
 
100
108
  if (isPostChatEnabled === "true") {
101
109
  if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
110
+ _WebChatStoreLoader.WebChatStoreLoader.store = null;
111
+ dispatch({
112
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
113
+ payload: _ConversationState.ConversationState.PostchatLoading
114
+ });
115
+ await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
102
116
  const loadPostChatEvent = {
103
117
  eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
104
118
  };
@@ -121,10 +135,14 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
121
135
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
122
136
  payload: undefined
123
137
  });
138
+ dispatch({
139
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
140
+ payload: undefined
141
+ });
124
142
  };
125
143
 
126
144
  webChatStore = (0, _botframeworkWebchat.createStore)({}, //initial state
127
- _preProcessingMiddleware.default, _attachmentProcessingMiddleware.default, (0, _attachmentUploadValidatorMiddleware.default)((_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.default, (0, _conversationEndMiddleware.default)(conversationEndCallback), (0, _dataMaskingMiddleware.default)((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), _gifUploadMiddleware.default, _htmlPlayerMiddleware.default, _htmlTextMiddleware.default, (0, _maxMessageSizeValidator.default)(localizedTexts), _sanitizationMiddleware.default, // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
+ _preProcessingMiddleware.default, _attachmentProcessingMiddleware.default, (0, _attachmentUploadValidatorMiddleware.default)((_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.default, (0, _conversationEndMiddleware.default)(conversationEndCallback), (0, _dataMaskingMiddleware.default)((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), _messageTimestampMiddleware.default, _gifUploadMiddleware.default, _htmlPlayerMiddleware.default, _htmlTextMiddleware.default, (0, _maxMessageSizeValidator.default)(localizedTexts), _sanitizationMiddleware.default, // eslint-disable-next-line @typescript-eslint/no-explicit-any
128
146
  ...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
129
147
  _WebChatStoreLoader.WebChatStoreLoader.store = webChatStore;
130
148
  } // Initialize the remaining Web Chat props
@@ -141,7 +159,9 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
141
159
  avatarMiddleware: (_props$webChatContain15 = props.webChatContainerProps) !== null && _props$webChatContain15 !== void 0 && (_props$webChatContain16 = _props$webChatContain15.renderingMiddlewareProps) !== null && _props$webChatContain16 !== void 0 && _props$webChatContain16.disableAvatarMiddleware ? undefined : (0, _avatarMiddleware.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),
142
160
  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.defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai2 === void 0 ? void 0 : _defaultWebChatContai2.groupActivitiesMiddleware,
143
161
  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.defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai3 === void 0 ? void 0 : _defaultWebChatContai3.typingIndicatorMiddleware,
144
- ...((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.webChatProps)
162
+ onTelemetry: (0, _WebChatLogger.createWebChatTelemetry)(),
163
+ cardActionMiddleware: (0, _cardActionMiddleware.createCardActionMiddleware)(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
164
+ ...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
145
165
  };
146
166
  return webChatProps;
147
167
  };
@@ -3,13 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.handleUnauthenticatedReconnectChat = exports.getReconnectIdForAuthenticatedChat = void 0;
6
+ exports.startUnauthenticatedReconnectChat = exports.handleUnauthenticatedReconnectChat = exports.handleRedirectUnauthenticatedReconnectChat = exports.getReconnectIdForAuthenticatedChat = exports.getChatReconnectContext = void 0;
7
7
 
8
8
  require("regenerator-runtime/runtime");
9
9
 
10
10
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
11
11
 
12
- var _Constants = require("../../../common/Constants");
12
+ var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
13
13
 
14
14
  var _ConversationState = require("../../../contexts/common/ConversationState");
15
15
 
@@ -41,10 +41,12 @@ const getChatReconnectContext = async (chatSDK, reconnectId) => {
41
41
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
42
 
43
43
 
44
+ exports.getChatReconnectContext = getChatReconnectContext;
45
+
44
46
  const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
45
- var _props$reconnectChatP, _props$reconnectChatP2;
47
+ var _props$reconnectChatP, _props$authProps;
46
48
 
47
- 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
49
+ 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
48
50
 
49
51
  /* && !isLoadWithState() */
50
52
  ) {
@@ -61,33 +63,116 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
61
63
 
62
64
  exports.getReconnectIdForAuthenticatedChat = getReconnectIdForAuthenticatedChat;
63
65
 
64
- const handleUnauthenticatedReconnectChat = async (dispatch, reconnectId, initStartChat) => {
65
- const reconnectAvailabilityResponse = await getChatReconnectContext(reconnectId);
66
+ const handleUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
67
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
66
68
 
67
- if (reconnectAvailabilityResponse && reconnectAvailabilityResponse.redirectURL) {
68
- redirectPage(reconnectAvailabilityResponse.redirectURL);
69
+ if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
70
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow);
69
71
  } else {
70
- const optionalParams = {
71
- reconnectId: reconnectId
72
- };
72
+ await setReconnectIdAndStartChat(chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat);
73
+ }
74
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
+
76
+
77
+ exports.handleUnauthenticatedReconnectChat = handleUnauthenticatedReconnectChat;
78
+
79
+ const startUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat) => {
80
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
81
+
82
+ if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
83
+ await setReconnectIdAndStartChat(chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat);
84
+ }
85
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
+
87
+
88
+ exports.startUnauthenticatedReconnectChat = startUnauthenticatedReconnectChat;
89
+
90
+ const setReconnectIdAndStartChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat) => {
91
+ const startUnauthenticatedReconnectChat = {
92
+ eventName: _TelemetryConstants.BroadcastEvent.StartUnauthenticatedReconnectChat
93
+ };
94
+
95
+ _omnichannelChatComponents.BroadcastService.postMessage(startUnauthenticatedReconnectChat);
96
+
97
+ const optionalParams = {
98
+ reconnectId: reconnectId
99
+ };
100
+ dispatch({
101
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_RECONNECT_ID,
102
+ payload: reconnectId
103
+ });
104
+ dispatch({
105
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
106
+ payload: _ConversationState.ConversationState.Loading
107
+ });
108
+ await initStartChat(chatSDK, authProps, dispatch, setAdapter, optionalParams);
109
+ };
110
+
111
+ const redirectPage = (redirectURL, redirectInSameWindow) => {
112
+ const redirectPageRequest = {
113
+ eventName: _TelemetryConstants.BroadcastEvent.RedirectPageRequest,
114
+ payload: {
115
+ redirectURL: redirectURL
116
+ }
117
+ };
118
+
119
+ _omnichannelChatComponents.BroadcastService.postMessage(redirectPageRequest);
120
+
121
+ if (redirectInSameWindow) {
122
+ window.location.href = redirectURL;
123
+ }
124
+ };
125
+
126
+ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
127
+ return reconnectAvailabilityResponse && !reconnectAvailabilityResponse.reconnectId;
128
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
+
130
+
131
+ const startNewChatEmptyRedirectionUrl = async (chatSDK, authProps, dispatch, setAdapter, initStartChat) => {
132
+ const startUnauthenticatedReconnectChat = {
133
+ eventName: _TelemetryConstants.BroadcastEvent.StartUnauthenticatedReconnectChat
134
+ };
135
+
136
+ _omnichannelChatComponents.BroadcastService.postMessage(startUnauthenticatedReconnectChat); // Getting PreChat Survey Context
137
+
138
+
139
+ const parseToJson = false;
140
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
141
+
142
+ if (preChatSurveyResponse) {
143
+ dispatch({
144
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
145
+ payload: preChatSurveyResponse
146
+ });
73
147
  dispatch({
74
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_RECONNECT_ID,
75
- payload: reconnectId
148
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
149
+ payload: _ConversationState.ConversationState.Prechat
76
150
  });
151
+ } else {
77
152
  dispatch({
78
153
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
79
154
  payload: _ConversationState.ConversationState.Loading
80
155
  });
81
- await initStartChat(optionalParams);
156
+ await initStartChat(chatSDK, authProps, dispatch, setAdapter);
82
157
  }
83
- };
158
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
159
 
85
- exports.handleUnauthenticatedReconnectChat = handleUnauthenticatedReconnectChat;
86
160
 
87
- const redirectPage = newUrl => {
88
- const data = {
89
- messageName: _Constants.Constants.redirectPageRequest,
90
- newUrl: newUrl
91
- };
92
- window.parent.postMessage(data, "*");
161
+ const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
162
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
163
+
164
+ if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
165
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow);
166
+ }
167
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
+
169
+
170
+ exports.handleRedirectUnauthenticatedReconnectChat = handleRedirectUnauthenticatedReconnectChat;
171
+
172
+ const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
173
+ if (reconnectAvailabilityResponse.redirectURL) {
174
+ redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
175
+ } else {
176
+ await startNewChatEmptyRedirectionUrl(chatSDK, authProps, dispatch, setAdapter, initStartChat);
177
+ }
93
178
  };
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.registerTelemetryLoggers = void 0;
7
7
 
8
- var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
9
-
10
8
  var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
11
9
 
10
+ var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
11
+
12
12
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
13
13
 
14
14
  var _defaultAriaConfig = require("../../../common/telemetry/defaultConfigs/defaultAriaConfig");
@@ -17,21 +17,9 @@ var _defaultTelemetryInternalData = require("../../../common/telemetry/defaultCo
17
17
 
18
18
  var _defaultTelemetryConfiguration = require("../../../common/telemetry/defaultConfigs/defaultTelemetryConfiguration");
19
19
 
20
- var _package = require("@microsoft/omnichannel-chat-components/package.json");
21
-
22
- var _package2 = require("@microsoft/omnichannel-chat-sdk/package.json");
23
-
24
20
  const registerTelemetryLoggers = (props, dispatch) => {
25
21
  var _props$liveChatContex, _props$liveChatContex2;
26
22
 
27
- let widgetPackageInfo;
28
-
29
- try {
30
- widgetPackageInfo = require("@microsoft/omnichannel-chat-widget/package.json");
31
- } catch (error) {
32
- widgetPackageInfo = "0.0.0-0";
33
- }
34
-
35
23
  const telemetryConfig = { ..._defaultTelemetryConfiguration.defaultTelemetryConfiguration,
36
24
  ...props.telemetryConfig
37
25
  };
@@ -53,12 +41,13 @@ const registerTelemetryLoggers = (props, dispatch) => {
53
41
  }
54
42
 
55
43
  telemetryData = _TelemetryHelper.TelemetryHelper.addWidgetDataToTelemetry(telemetryConfig, telemetryData);
56
- telemetryData.OCChatSDKVersion = _package2.version;
57
- telemetryData.chatComponentVersion = _package.version;
58
- telemetryData.chatWidgetVersion = widgetPackageInfo;
44
+ telemetryData.OCChatSDKVersion = telemetryConfig.OCChatSDKVersion ?? "0.0.0-0";
45
+ telemetryData.chatComponentVersion = telemetryConfig.chatComponentVersion ?? "0.0.0-0";
46
+ telemetryData.chatWidgetVersion = telemetryConfig.chatWidgetVersion ?? "0.0.0-0";
59
47
  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;
60
48
  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;
61
49
  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;
50
+ _TelemetryManager.TelemetryManager.InternalTelemetryData = telemetryData;
62
51
  dispatch({
63
52
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_TELEMETRY_DATA,
64
53
  payload: telemetryData
@@ -43,10 +43,6 @@ const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat)
43
43
 
44
44
 
45
45
  _omnichannelChatComponents.BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
46
- dispatch({
47
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
48
- payload: _ConversationState.ConversationState.Loading
49
- });
50
46
  dispatch({
51
47
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
52
48
  payload: _ConversationState.ConversationState.Postchat
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shareObservable = shareObservable;
7
+
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ function shareObservable(observable) {
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ let observers = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+
13
+ let subscription; // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+
15
+ return new window.Observable(observer => {
16
+ if (!subscription) {
17
+ subscription = observable.subscribe({
18
+ complete() {
19
+ observers.forEach(observer => observer.complete());
20
+ },
21
+
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ error(err) {
24
+ observers.forEach(observer => observer.error(err));
25
+ },
26
+
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ next(value) {
29
+ observers.forEach(observer => observer.next(value));
30
+ }
31
+
32
+ });
33
+ }
34
+
35
+ observers.push(observer);
36
+ return () => {
37
+ observers = observers.filter(o => o !== observer);
38
+
39
+ if (!observers.length) {
40
+ subscription.unsubscribe();
41
+ subscription = null;
42
+ }
43
+ };
44
+ });
45
+ }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.prepareStartChat = exports.initStartChat = void 0;
6
+ exports.setPreChatAndInitiateChat = exports.prepareStartChat = exports.initStartChat = void 0;
7
7
 
8
8
  var _Constants = require("../../../common/Constants");
9
9
 
@@ -11,8 +11,6 @@ var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants"
11
11
 
12
12
  var _ConversationState = require("../../../contexts/common/ConversationState");
13
13
 
14
- var _DataStoreManager = require("../../../common/contextDataStore/DataStoreManager");
15
-
16
14
  var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
17
15
 
18
16
  var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
@@ -35,16 +33,29 @@ var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurve
35
33
 
36
34
  var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
37
35
 
36
+ var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
37
+
38
38
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+
39
41
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
42
+ var _props$reconnectChatP;
43
+
44
+ optionalParams = {}; //Resetting to ensure no stale values
45
+ // Can connect to existing chat session
46
+
40
47
  if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
41
48
  return;
42
- } // Getting PreChat Survey Context
49
+ } // Redirecting if unauthenticated reconnect chat expired
43
50
 
44
51
 
45
- const parseToJson = false;
46
- const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
47
- const showPrechat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
52
+ if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
53
+ var _props$reconnectChatP2, _props$reconnectChatP3;
54
+
55
+ await (0, _reconnectChatHelper.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);
56
+ return;
57
+ } // Getting reconnectId for authenticated chat
58
+
48
59
 
49
60
  const reconnectId = await (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK);
50
61
 
@@ -57,7 +68,28 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
57
68
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
58
69
  payload: _ConversationState.ConversationState.ReconnectChat
59
70
  });
60
- } else if (showPrechat) {
71
+ return;
72
+ } // Set custom context params
73
+
74
+
75
+ setCustomContextParams(props, chatSDK); // Setting Proactive chat settings
76
+
77
+ const isProactiveChat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat;
78
+ const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
79
+
80
+ setPreChatAndInitiateChat(chatSDK, props.authProps, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
81
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+
83
+
84
+ exports.prepareStartChat = prepareStartChat;
85
+
86
+ const setPreChatAndInitiateChat = async (chatSDK, authProps, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
87
+ // Getting prechat Survey Context
88
+ const parseToJson = false;
89
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
90
+ const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
91
+
92
+ if (showPrechat) {
61
93
  dispatch({
62
94
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
63
95
  payload: preChatSurveyResponse
@@ -66,30 +98,55 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
66
98
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
67
99
  payload: _ConversationState.ConversationState.Prechat
68
100
  });
69
- } else {
70
- dispatch({
71
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
72
- payload: _ConversationState.ConversationState.Loading
73
- });
74
- await initStartChat(chatSDK, dispatch, setAdapter);
75
- }
101
+ return;
102
+ } //Initiate start chat
103
+
104
+
105
+ dispatch({
106
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
107
+ payload: _ConversationState.ConversationState.Loading
108
+ });
109
+ await initStartChat(chatSDK, authProps, dispatch, setAdapter);
76
110
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
111
 
78
112
 
79
- exports.prepareStartChat = prepareStartChat;
113
+ exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
80
114
 
81
- const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedState) => {
115
+ const initStartChat = async (chatSDK, authProps, dispatch, setAdapter, params, persistedState) => {
82
116
  try {
83
117
  var _newAdapter$activity$, _TelemetryTimers$Widg;
84
118
 
119
+ let isStartChatSuccessful = false; //Check if chat retrieved from cache
120
+
121
+ if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
122
+ var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
123
+
124
+ _omnichannelChatComponents.BroadcastService.postMessage({
125
+ eventName: _TelemetryConstants.BroadcastEvent.ChatRetrievedFromCache,
126
+ payload: {
127
+ 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,
128
+ 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
129
+ }
130
+ });
131
+ }
132
+
85
133
  try {
134
+ //Start widget load timer
86
135
  _TelemetryManager.TelemetryTimers.WidgetLoadTimer = (0, _utils.createTimer)();
87
136
 
88
137
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
89
138
  Event: _TelemetryConstants.TelemetryEvent.StartChatSDKCall
90
- });
139
+ }); // Set optional params
91
140
 
92
- await chatSDK.startChat(params);
141
+
142
+ optionalParams = Object.assign({}, params, optionalParams); // set auth token to chat sdk before start chat
143
+
144
+ if (authProps && authProps.setAuthTokenProviderToChatSdk) {
145
+ await authProps.setAuthTokenProviderToChatSdk(chatSDK, authProps.authClientFunction);
146
+ }
147
+
148
+ await chatSDK.startChat(optionalParams);
149
+ isStartChatSuccessful = true;
93
150
  } catch (error) {
94
151
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
95
152
  Event: _TelemetryConstants.TelemetryEvent.StartChatMethodException,
@@ -97,43 +154,52 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
97
154
  exception: `Failed to setup startChat: ${error}`
98
155
  }
99
156
  });
100
- }
157
+
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.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
163
+ payload: _ConversationState.ConversationState.Closed
164
+ });
165
+ return;
166
+ } // New adapter creation
167
+
101
168
 
102
169
  const newAdapter = await (0, _createAdapter.createAdapter)(chatSDK);
103
170
  setAdapter(newAdapter);
104
171
  const chatToken = await chatSDK.getChatToken();
172
+ dispatch({
173
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
174
+ payload: chatToken
175
+ });
105
176
  newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe((0, _newMessageEventHandler.createOnNewAdapterActivityHandler)(chatToken === null || chatToken === void 0 ? void 0 : chatToken.chatId, chatToken === null || chatToken === void 0 ? void 0 : chatToken.visitorId));
106
177
 
107
- if (!persistedState) {
108
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
109
- if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
110
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
- const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
112
- dispatch({
113
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
114
- payload: chatToken
115
- });
116
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
-
118
-
119
- const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
178
+ if (persistedState) {
120
179
  dispatch({
121
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
122
- payload: liveChatContext
180
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
181
+ payload: persistedState
123
182
  });
124
- await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
125
- await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
183
+ await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
184
+ return;
185
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
186
 
187
+
188
+ const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
189
+ dispatch({
190
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
191
+ payload: liveChatContext
192
+ }); // Set post chat context in state, no survey load
193
+
194
+ await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch); // Updating chat session detail for telemetry
195
+
196
+ await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
197
+
198
+ if (isStartChatSuccessful) {
127
199
  dispatch({
128
200
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
129
201
  payload: _ConversationState.ConversationState.Active
130
202
  });
131
- } else {
132
- dispatch({
133
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
134
- payload: persistedState
135
- });
136
- await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
137
203
  }
138
204
 
139
205
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -162,6 +228,8 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
162
228
  payload: _ConversationState.ConversationState.OutOfOffice
163
229
  });
164
230
  }
231
+ } finally {
232
+ optionalParams = {};
165
233
  }
166
234
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
167
235
 
@@ -169,24 +237,44 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
169
237
  exports.initStartChat = initStartChat;
170
238
 
171
239
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
172
- var _DataStoreManager$cli, _persistedState$domai;
240
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _persistedState$domai6, _persistedState$appSt;
173
241
 
174
- const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(_Constants.Constants.widgetStateDataKey, "localStorage");
175
- const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
242
+ // By pass this function in case of popout chat
243
+ if (state.appStates.skipChatButtonRendering === true) {
244
+ return false;
245
+ }
176
246
 
177
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
178
- var _persistedState$domai2;
247
+ const persistedState = (0, _utils.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
248
+
249
+ if (persistedState && !(0, _utils.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.ConversationState.Active) {
250
+ var _persistedState$domai7;
179
251
 
180
252
  dispatch({
181
253
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
182
254
  payload: _ConversationState.ConversationState.Loading
183
255
  });
184
256
  const optionalParams = {
185
- liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai2 = persistedState.domainStates) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.liveChatContext
257
+ liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
186
258
  };
187
- await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
259
+ await initStartChat(chatSDK, props.authProps, dispatch, setAdapter, optionalParams, persistedState);
188
260
  return true;
189
261
  } else {
190
262
  return false;
191
263
  }
264
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
265
+
266
+
267
+ const setCustomContextParams = (props, chatSDK) => {
268
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _props$chatConfig, _persistedState$domai8;
269
+
270
+ // Add custom context only for unauthenticated chat
271
+ const persistedState = (0, _utils.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);
272
+
273
+ if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
274
+ var _persistedState$domai9;
275
+
276
+ optionalParams = Object.assign({}, optionalParams, {
277
+ customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
278
+ });
279
+ }
192
280
  };