@microsoft/omnichannel-chat-widget 0.1.0-main.1a61ea0 → 0.1.0-main.24bd1e6

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 (183) hide show
  1. package/README.md +259 -0
  2. package/lib/cjs/assets/Audios.js +8 -0
  3. package/lib/cjs/assets/Icons.js +28 -0
  4. package/lib/cjs/common/Constants.js +52 -4
  5. package/lib/cjs/common/contextDataStore/DataStoreManager.js +14 -0
  6. package/lib/cjs/{assets/assets.d.js → common/interfaces/IContextDataStore.js} +0 -0
  7. package/lib/cjs/common/telemetry/TelemetryConstants.js +59 -4
  8. package/lib/cjs/common/telemetry/TelemetryHelper.js +22 -4
  9. package/lib/cjs/common/telemetry/TelemetryManager.js +28 -9
  10. package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +3 -3
  11. package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  12. package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +48 -15
  13. package/lib/cjs/common/telemetry/loggers/consoleLogger.js +9 -5
  14. package/lib/cjs/common/utils.js +76 -2
  15. package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  16. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +20 -4
  17. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -54
  18. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +2 -2
  19. package/lib/cjs/components/footerstateful/FooterStateful.js +4 -5
  20. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
  21. package/lib/cjs/components/headerstateful/HeaderStateful.js +11 -8
  22. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +3 -4
  23. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +49 -47
  24. package/lib/cjs/components/livechatwidget/common/disposeTelemetryLoggers.js +14 -0
  25. package/lib/cjs/components/livechatwidget/common/endChat.js +142 -43
  26. package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +5 -0
  27. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +49 -11
  28. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +105 -20
  29. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +11 -7
  30. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +22 -24
  31. package/lib/cjs/components/livechatwidget/common/startChat.js +174 -41
  32. package/lib/cjs/components/livechatwidget/common/startProactiveChat.js +3 -3
  33. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +249 -67
  34. package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +1 -1
  35. package/lib/cjs/components/ooohpanestateful/OOOHPaneStateful.js +8 -0
  36. package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
  37. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +22 -10
  38. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +27 -5
  39. package/lib/cjs/components/proactivechatpanestateful/interfaces/IProactiveChatNotificationConfig.js +1 -0
  40. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  41. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +4 -0
  42. package/lib/cjs/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +51 -73
  43. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  44. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  45. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +25 -48
  46. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +3 -1
  47. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  48. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  49. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  50. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +6 -6
  51. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +45 -0
  52. package/lib/cjs/contexts/common/ConversationState.js +4 -2
  53. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +12 -7
  54. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +11 -4
  55. package/lib/cjs/contexts/createReducer.js +36 -10
  56. package/lib/cjs/controller/componentController.js +5 -5
  57. package/lib/cjs/plugins/newMessageEventHandler.js +99 -0
  58. package/lib/esm/assets/Audios.js +1 -0
  59. package/lib/esm/assets/Icons.js +11 -0
  60. package/lib/esm/common/Constants.js +48 -3
  61. package/lib/esm/common/contextDataStore/DataStoreManager.js +5 -0
  62. package/lib/esm/common/interfaces/IContextDataStore.js +1 -0
  63. package/lib/esm/common/telemetry/TelemetryConstants.js +55 -3
  64. package/lib/esm/common/telemetry/TelemetryHelper.js +22 -5
  65. package/lib/esm/common/telemetry/TelemetryManager.js +22 -9
  66. package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +3 -3
  67. package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  68. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +50 -15
  69. package/lib/esm/common/telemetry/loggers/consoleLogger.js +9 -5
  70. package/lib/esm/common/utils.js +55 -1
  71. package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  72. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
  73. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -50
  74. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +2 -2
  75. package/lib/esm/components/footerstateful/FooterStateful.js +4 -5
  76. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
  77. package/lib/esm/components/headerstateful/HeaderStateful.js +12 -9
  78. package/lib/esm/components/livechatwidget/common/createMarkdown.js +3 -3
  79. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +47 -48
  80. package/lib/esm/components/livechatwidget/common/disposeTelemetryLoggers.js +4 -0
  81. package/lib/esm/components/livechatwidget/common/endChat.js +139 -42
  82. package/lib/esm/components/livechatwidget/common/initCallingSdk.js +3 -0
  83. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +43 -12
  84. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +94 -20
  85. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +10 -3
  86. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +19 -22
  87. package/lib/esm/components/livechatwidget/common/startChat.js +167 -39
  88. package/lib/esm/components/livechatwidget/common/startProactiveChat.js +5 -5
  89. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +235 -71
  90. package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +1 -1
  91. package/lib/esm/components/ooohpanestateful/OOOHPaneStateful.js +6 -0
  92. package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
  93. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +22 -10
  94. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +26 -6
  95. package/lib/esm/components/proactivechatpanestateful/interfaces/IProactiveChatNotificationConfig.js +1 -0
  96. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  97. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +4 -0
  98. package/lib/esm/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +2 -12
  99. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  100. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  101. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +23 -46
  102. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
  103. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  104. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  105. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  106. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +6 -6
  107. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
  108. package/lib/esm/contexts/common/ConversationState.js +4 -2
  109. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +12 -7
  110. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +11 -4
  111. package/lib/esm/contexts/createReducer.js +36 -9
  112. package/lib/esm/controller/componentController.js +5 -5
  113. package/lib/esm/plugins/newMessageEventHandler.js +82 -0
  114. package/lib/types/assets/Audios.d.ts +1 -0
  115. package/lib/types/assets/Icons.d.ts +11 -0
  116. package/lib/types/common/Constants.d.ts +26 -1
  117. package/lib/types/common/contextDataStore/DataStoreManager.d.ts +4 -0
  118. package/lib/types/common/interfaces/IContextDataStore.d.ts +14 -0
  119. package/lib/types/common/telemetry/TelemetryConstants.d.ts +43 -2
  120. package/lib/types/common/telemetry/TelemetryHelper.d.ts +3 -1
  121. package/lib/types/common/telemetry/TelemetryManager.d.ts +1 -0
  122. package/lib/types/common/telemetry/definitions/Contracts.d.ts +3 -0
  123. package/lib/types/common/telemetry/definitions/Payload.d.ts +15 -9
  124. package/lib/types/common/telemetry/interfaces/IChatSDKLogger.d.ts +1 -0
  125. package/lib/types/common/telemetry/interfaces/IInternalTelemetryData.d.ts +2 -0
  126. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +12 -0
  127. package/lib/types/common/utils.d.ts +6 -0
  128. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +5 -2
  129. package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
  130. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  131. package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +4 -1
  132. package/lib/types/components/livechatwidget/common/disposeTelemetryLoggers.d.ts +1 -0
  133. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
  134. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -2
  135. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  136. package/lib/types/components/livechatwidget/common/startChat.d.ts +3 -2
  137. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +2 -1
  138. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  139. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +3 -1
  140. package/lib/types/components/prechatsurveypanestateful/interfaces/IPreChatSurveyPaneStatefulParams.d.ts +1 -1
  141. package/lib/types/components/proactivechatpanestateful/interfaces/IProactiveChatNotificationConfig.d.ts +3 -0
  142. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -0
  143. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  144. package/lib/types/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.d.ts +1 -1
  145. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  146. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  147. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  148. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -2
  149. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  150. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  151. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  152. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  153. package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
  154. package/lib/types/contexts/common/ConversationState.d.ts +4 -2
  155. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +4 -1
  156. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +13 -8
  157. package/lib/types/plugins/newMessageEventHandler.d.ts +2 -0
  158. package/package.json +11 -11
  159. package/lib/cjs/assets/audios/newMessageNotification.mp3 +0 -0
  160. package/lib/cjs/assets/icons/archiveIcon.svg +0 -3
  161. package/lib/cjs/assets/icons/audioIcon.svg +0 -6
  162. package/lib/cjs/assets/icons/blankIcon.svg +0 -6
  163. package/lib/cjs/assets/icons/excelIcon.svg +0 -6
  164. package/lib/cjs/assets/icons/imageIcon.svg +0 -6
  165. package/lib/cjs/assets/icons/oneNoteIcon.svg +0 -6
  166. package/lib/cjs/assets/icons/pdfIcon.svg +0 -6
  167. package/lib/cjs/assets/icons/powerpointIcon.svg +0 -6
  168. package/lib/cjs/assets/icons/videoIcon.svg +0 -6
  169. package/lib/cjs/assets/icons/visioIcon.svg +0 -6
  170. package/lib/cjs/assets/icons/wordIcon.svg +0 -6
  171. package/lib/esm/assets/assets.d.js +0 -0
  172. package/lib/esm/assets/audios/newMessageNotification.mp3 +0 -0
  173. package/lib/esm/assets/icons/archiveIcon.svg +0 -3
  174. package/lib/esm/assets/icons/audioIcon.svg +0 -6
  175. package/lib/esm/assets/icons/blankIcon.svg +0 -6
  176. package/lib/esm/assets/icons/excelIcon.svg +0 -6
  177. package/lib/esm/assets/icons/imageIcon.svg +0 -6
  178. package/lib/esm/assets/icons/oneNoteIcon.svg +0 -6
  179. package/lib/esm/assets/icons/pdfIcon.svg +0 -6
  180. package/lib/esm/assets/icons/powerpointIcon.svg +0 -6
  181. package/lib/esm/assets/icons/videoIcon.svg +0 -6
  182. package/lib/esm/assets/icons/visioIcon.svg +0 -6
  183. package/lib/esm/assets/icons/wordIcon.svg +0 -6
@@ -1,53 +1,150 @@
1
- import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
1
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
2
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
2
3
  import { ConversationState } from "../../../contexts/common/ConversationState";
3
4
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
4
- import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
5
- import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
6
5
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
7
6
  import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
8
7
  import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
9
- import { BroadcastService } from "@microsoft/omnichannel-chat-components"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
9
+ import { Constants } from "../../../common/Constants";
10
+ import { addDelayInMs, getWidgetEndChatEventName } from "../../../common/utils"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
11
 
11
- export const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter) => {
12
- try {
13
- var _props$webChatContain;
12
+ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
13
+ var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
14
14
 
15
- TelemetryHelper.logConfigDataEvent(LogLevel.INFO, {
16
- Event: TelemetryEvent.EndChatSDKCall
17
- });
18
- await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
19
- adapter === null || adapter === void 0 ? void 0 : adapter.end();
20
- setAdapter(undefined);
21
- setWebChatStyles({ ...defaultWebChatContainerStatefulProps.webChatStyles,
22
- ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
23
- });
24
- WebChatStoreLoader.store = null;
25
- dispatch({
26
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
27
- payload: ConversationState.Closed
28
- });
29
- dispatch({
30
- type: LiveChatWidgetActionType.SET_RECONNECT_ID,
31
- payload: undefined
32
- });
33
- dispatch({
34
- type: LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
35
- payload: null
36
- });
37
- dispatch({
38
- type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
39
- payload: undefined
40
- });
41
- BroadcastService.postMessage({
42
- eventName: "EndChat"
43
- });
44
- } catch (ex) {
45
- TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
46
- Event: TelemetryEvent.EndChatSDKCallFailed,
15
+ const isPostChatEnabled = (_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable;
16
+ const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode; // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+
18
+ let conversationDetails = undefined;
19
+
20
+ try {
21
+ conversationDetails = await chatSDK.getConversationDetails();
22
+ } catch (erorr) {
23
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
24
+ Event: TelemetryEvent.GetConversationDetailsException,
47
25
  ExceptionDetails: {
48
- exception: ex
26
+ exception: `Failed to get conversation details: ${erorr}`
49
27
  }
50
28
  });
51
- NotificationHandler.notifyError(NotificationScenarios.Connection, "End Chat Call Failed: " + ex);
52
29
  }
53
- };
30
+
31
+ if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === Constants.truePascal) {
32
+ const skipEndChatSDK = false;
33
+ const skipCloseChat = true;
34
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, true);
35
+
36
+ if (postChatSurveyMode === PostChatSurveyMode.Embed) {
37
+ dispatch({
38
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
39
+ payload: ConversationState.PostchatLoading
40
+ });
41
+ await addDelayInMs(Constants.PostChatLoadingDurationInMs);
42
+ const loadPostChatEvent = {
43
+ eventName: BroadcastEvent.LoadPostChatSurvey
44
+ };
45
+ BroadcastService.postMessage(loadPostChatEvent);
46
+ } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
47
+ dispatch({
48
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
49
+ payload: ConversationState.InActive
50
+ });
51
+ }
52
+
53
+ return;
54
+ }
55
+
56
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
57
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
+
59
+
60
+ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => {
61
+ if (!skipEndChatSDK) {
62
+ try {
63
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
64
+ Event: TelemetryEvent.EndChatSDKCall
65
+ });
66
+ await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
67
+ } catch (ex) {
68
+ TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
69
+ Event: TelemetryEvent.EndChatSDKCallFailed,
70
+ ExceptionDetails: {
71
+ exception: ex
72
+ }
73
+ });
74
+ postMessageToOtherTab = false;
75
+ }
76
+ } // Need to clear these states immediately when chat ended from OC.
77
+
78
+
79
+ dispatch({
80
+ type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
81
+ payload: undefined
82
+ });
83
+ dispatch({
84
+ type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
85
+ payload: undefined
86
+ });
87
+ dispatch({
88
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
89
+ payload: undefined
90
+ });
91
+
92
+ if (!skipCloseChat) {
93
+ try {
94
+ var _props$webChatContain;
95
+
96
+ adapter === null || adapter === void 0 ? void 0 : adapter.end();
97
+ setAdapter(undefined);
98
+ setWebChatStyles({ ...defaultWebChatContainerStatefulProps.webChatStyles,
99
+ ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
100
+ });
101
+ WebChatStoreLoader.store = null;
102
+ dispatch({
103
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
104
+ payload: ConversationState.Closed
105
+ });
106
+ dispatch({
107
+ type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
108
+ payload: false
109
+ });
110
+ dispatch({
111
+ type: LiveChatWidgetActionType.SET_RECONNECT_ID,
112
+ payload: undefined
113
+ });
114
+ dispatch({
115
+ type: LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
116
+ payload: null
117
+ });
118
+ dispatch({
119
+ type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
120
+ payload: 0
121
+ });
122
+ dispatch({
123
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
124
+ payload: {
125
+ proactiveChatBodyTitle: "",
126
+ proactiveChatEnablePrechat: false,
127
+ proactiveChatInNewWindow: false
128
+ }
129
+ });
130
+
131
+ if (postMessageToOtherTab) {
132
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
133
+
134
+ const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId);
135
+ BroadcastService.postMessage({
136
+ eventName: endChatEventName
137
+ });
138
+ }
139
+ } catch (error) {
140
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
141
+ Event: TelemetryEvent.CloseChatMethodException,
142
+ ExceptionDetails: {
143
+ exception: `Failed to endChat: ${error}`
144
+ }
145
+ });
146
+ }
147
+ }
148
+ };
149
+
150
+ export { prepareEndChat, endChat };
@@ -8,6 +8,9 @@ export const initCallingSdk = async (chatSDK, setVoiceVideoCallingSDK) => {
8
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
9
  const callingSDK = await chatSDK.getVoiceVideoCalling();
10
10
  setVoiceVideoCallingSDK(callingSDK);
11
+ TelemetryHelper.logCallingEvent(LogLevel.INFO, {
12
+ Event: TelemetryEvent.CallingSDKLoadSuccess
13
+ });
11
14
  return true;
12
15
  }
13
16
 
@@ -1,10 +1,13 @@
1
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
1
2
  import { createStore } from "botframework-webchat";
3
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
2
4
  import { ConversationState } from "../../../contexts/common/ConversationState";
3
5
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
4
6
  import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
7
+ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
5
8
  import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
6
9
  import attachmentProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware";
7
- import { changeLanguageCodeFormatForWebChat } from "../../../common/utils";
10
+ import { addDelayInMs, changeLanguageCodeFormatForWebChat } from "../../../common/utils";
8
11
  import channelDataMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware";
9
12
  import { createActivityMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware";
10
13
  import createAttachmentMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware";
@@ -14,6 +17,7 @@ import createConversationEndMiddleware from "../../webchatcontainerstateful/webc
14
17
  import createDataMaskingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/dataMaskingMiddleware";
15
18
  import { createMarkdown } from "./createMarkdown";
16
19
  import createMaxMessageSizeValidator from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/maxMessageSizeValidator";
20
+ import { createWebChatTelemetry } from "../../webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger";
17
21
  import { defaultAttachmentProps } from "../../webchatcontainerstateful/common/defaultProps/defaultAttachmentProps";
18
22
  import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
19
23
  import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
@@ -23,10 +27,12 @@ import htmlPlayerMiddleware from "../../webchatcontainerstateful/webchatcontroll
23
27
  import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware";
24
28
  import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
25
29
  import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
26
- import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
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
27
33
 
28
34
  export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
29
- 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;
30
36
 
31
37
  const localizedTexts = { ...defaultMiddlewareLocalizedTexts,
32
38
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -45,6 +51,11 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
45
51
  const conversationEndCallback = async () => {
46
52
  var _props$webChatContain4, _props$webChatContain5;
47
53
 
54
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
55
+ Event: TelemetryEvent.ConversationEndedThreadEventReceived,
56
+ Description: "Conversation is ended by agent side or by timeout."
57
+ });
58
+
48
59
  if ((props === null || props === void 0 ? void 0 : (_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : (_props$webChatContain5 = _props$webChatContain4.renderingMiddlewareProps) === null || _props$webChatContain5 === void 0 ? void 0 : _props$webChatContain5.hideSendboxOnConversationEnd) !== false) {
49
60
  setWebChatStyles(styles => {
50
61
  return { ...styles,
@@ -53,26 +64,44 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
53
64
  });
54
65
  }
55
66
 
56
- if (isPostChatEnabled === "true" && postChatSurveyMode === PostChatSurveyMode.Embed) {
67
+ WebChatStoreLoader.store = null;
68
+
69
+ if (isPostChatEnabled === "true") {
70
+ if (postChatSurveyMode === PostChatSurveyMode.Embed) {
71
+ dispatch({
72
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
73
+ payload: ConversationState.PostchatLoading
74
+ });
75
+ await addDelayInMs(Constants.PostChatLoadingDurationInMs);
76
+ const loadPostChatEvent = {
77
+ eventName: BroadcastEvent.LoadPostChatSurvey
78
+ };
79
+ BroadcastService.postMessage(loadPostChatEvent);
80
+ } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
81
+ dispatch({
82
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
83
+ payload: ConversationState.InActive
84
+ });
85
+ }
86
+ } else {
57
87
  dispatch({
58
- type: LiveChatWidgetActionType.SET_SHOULD_SHOW_POST_CHAT,
88
+ type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
59
89
  payload: true
60
90
  });
61
- dispatch({
62
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
63
- payload: ConversationState.Loading
64
- });
65
- await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
66
91
  }
67
92
 
68
93
  dispatch({
69
94
  type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
70
95
  payload: undefined
71
96
  });
97
+ dispatch({
98
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
99
+ payload: undefined
100
+ });
72
101
  };
73
102
 
74
103
  webChatStore = createStore({}, //initial state
75
- 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
104
+ 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
76
105
  ...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
77
106
  WebChatStoreLoader.store = webChatStore;
78
107
  } // Initialize the remaining Web Chat props
@@ -89,7 +118,9 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
89
118
  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),
90
119
  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,
91
120
  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,
92
- ...((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.webChatProps)
121
+ onTelemetry: createWebChatTelemetry(),
122
+ cardActionMiddleware: createCardActionMiddleware(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
123
+ ...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
93
124
  };
94
125
  return webChatProps;
95
126
  };
@@ -1,6 +1,6 @@
1
1
  import "regenerator-runtime/runtime";
2
- import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
- import { Constants } from "../../../common/Constants";
2
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
4
4
  import { ConversationState } from "../../../contexts/common/ConversationState";
5
5
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
6
6
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -46,33 +46,107 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
46
46
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
47
 
48
48
 
49
- const handleUnauthenticatedReconnectChat = async (dispatch, reconnectId, initStartChat) => {
50
- const reconnectAvailabilityResponse = await getChatReconnectContext(reconnectId);
49
+ const handleUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
50
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
51
51
 
52
- if (reconnectAvailabilityResponse && reconnectAvailabilityResponse.redirectURL) {
53
- redirectPage(reconnectAvailabilityResponse.redirectURL);
52
+ if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
53
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
54
54
  } else {
55
- const optionalParams = {
56
- reconnectId: reconnectId
57
- };
55
+ await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
56
+ }
57
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
+
59
+
60
+ const startUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
61
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
62
+
63
+ if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
64
+ await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
65
+ }
66
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+
68
+
69
+ const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
70
+ const startUnauthenticatedReconnectChat = {
71
+ eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
72
+ };
73
+ BroadcastService.postMessage(startUnauthenticatedReconnectChat);
74
+ const optionalParams = {
75
+ reconnectId: reconnectId
76
+ };
77
+ dispatch({
78
+ type: LiveChatWidgetActionType.SET_RECONNECT_ID,
79
+ payload: reconnectId
80
+ });
81
+ dispatch({
82
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
83
+ payload: ConversationState.Loading
84
+ });
85
+ await initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
86
+ };
87
+
88
+ const redirectPage = (redirectURL, redirectInSameWindow) => {
89
+ const redirectPageRequest = {
90
+ eventName: BroadcastEvent.RedirectPageRequest,
91
+ payload: {
92
+ redirectURL: redirectURL
93
+ }
94
+ };
95
+ BroadcastService.postMessage(redirectPageRequest);
96
+
97
+ if (redirectInSameWindow) {
98
+ window.location.href = redirectURL;
99
+ }
100
+ };
101
+
102
+ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
103
+ return reconnectAvailabilityResponse && !reconnectAvailabilityResponse.reconnectId;
104
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
+
106
+
107
+ const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, initStartChat) => {
108
+ const startUnauthenticatedReconnectChat = {
109
+ eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
110
+ };
111
+ BroadcastService.postMessage(startUnauthenticatedReconnectChat); // Getting PreChat Survey Context
112
+
113
+ const parseToJson = false;
114
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
115
+
116
+ if (preChatSurveyResponse) {
58
117
  dispatch({
59
- type: LiveChatWidgetActionType.SET_RECONNECT_ID,
60
- payload: reconnectId
118
+ type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
119
+ payload: preChatSurveyResponse
61
120
  });
121
+ dispatch({
122
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
123
+ payload: ConversationState.Prechat
124
+ });
125
+ } else {
62
126
  dispatch({
63
127
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
64
128
  payload: ConversationState.Loading
65
129
  });
66
- await initStartChat(optionalParams);
130
+ await initStartChat(chatSDK, dispatch, setAdapter);
67
131
  }
68
- };
132
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
133
 
70
- const redirectPage = newUrl => {
71
- const data = {
72
- messageName: Constants.redirectPageRequest,
73
- newUrl: newUrl
74
- };
75
- window.parent.postMessage(data, "*");
134
+
135
+ const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
136
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
137
+
138
+ if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
139
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
140
+ }
141
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
+
143
+
144
+ const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
145
+ if (reconnectAvailabilityResponse.redirectURL) {
146
+ redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
147
+ } else {
148
+ await startNewChatEmptyRedirectionUrl(chatSDK, dispatch, setAdapter, initStartChat);
149
+ }
76
150
  };
77
151
 
78
- export { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat };
152
+ export { getChatReconnectContext, getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat, startUnauthenticatedReconnectChat, handleRedirectUnauthenticatedReconnectChat };
@@ -1,10 +1,9 @@
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 packageInfo from "@microsoft/omnichannel-chat-sdk/package.json";
8
7
  export const registerTelemetryLoggers = (props, dispatch) => {
9
8
  var _props$liveChatContex, _props$liveChatContex2;
10
9
 
@@ -17,6 +16,8 @@ export const registerTelemetryLoggers = (props, dispatch) => {
17
16
 
18
17
  TelemetryManager.InternalTelemetryData = (_props$liveChatContex3 = props.liveChatContextFromCache) === null || _props$liveChatContex3 === void 0 ? void 0 : (_props$liveChatContex4 = _props$liveChatContex3.domainStates) === null || _props$liveChatContex4 === void 0 ? void 0 : _props$liveChatContex4.telemetryInternalData;
19
18
  } else {
19
+ var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic, _props$chatSDK3, _props$chatSDK3$omnic;
20
+
20
21
  let telemetryData = { ...defaultInternalTelemetryData,
21
22
  telemetryConfig: Object.assign({}, defaultTelemetryConfiguration, telemetryConfig),
22
23
  ariaConfig: Object.assign({}, defaultAriaConfig, telemetryConfig === null || telemetryConfig === void 0 ? void 0 : telemetryConfig.ariaConfigurations)
@@ -27,7 +28,13 @@ export const registerTelemetryLoggers = (props, dispatch) => {
27
28
  }
28
29
 
29
30
  telemetryData = TelemetryHelper.addWidgetDataToTelemetry(telemetryConfig, telemetryData);
30
- telemetryData.OCChatSDKVersion = packageInfo.version;
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";
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;
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;
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;
31
38
  dispatch({
32
39
  type: LiveChatWidgetActionType.SET_TELEMETRY_DATA,
33
40
  payload: telemetryData
@@ -1,20 +1,23 @@
1
1
  import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
2
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
3
+ import { ConversationState } from "../../../contexts/common/ConversationState";
2
4
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
3
- import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
4
- import { ConversationState } from "../../../contexts/common/ConversationState"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
6
 
6
- export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, loadSurvey) => {
7
+ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat) => {
7
8
  try {
8
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
- const context = await chatSDK.getPostChatSurveyContext();
10
- TelemetryHelper.logSDKEvent(LogLevel.INFO, {
11
- Event: TelemetryEvent.PostChatContextCallSucceed,
12
- Description: "Postchat context call succeed."
13
- });
14
- dispatch({
15
- type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
16
- payload: context
17
- });
9
+ if (!persistedChat) {
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ const context = await chatSDK.getPostChatSurveyContext();
12
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
13
+ Event: TelemetryEvent.PostChatContextCallSucceed,
14
+ Description: "Postchat context call succeed."
15
+ });
16
+ dispatch({
17
+ type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
18
+ payload: context
19
+ });
20
+ }
18
21
  } catch (ex) {
19
22
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
20
23
  Event: TelemetryEvent.PostChatContextCallFailed,
@@ -22,19 +25,13 @@ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, loadSur
22
25
  exception: ex
23
26
  }
24
27
  });
25
- }
26
- /* -true: setPostChatContextAndLoadSurvey is called after passing all checks from ConfirmationPane and endChatMiddleware in usual scenario.
27
- -false: Below if condition is needed for multi-tab scenarios. So when agent ends a chat and customer has opened chat in multiple tabs,
28
- all tabs should show post chat survey as per existing functionality. But when an agent end a conversation, Omnichannel SDK
29
- getPostChatSurveyContext returns as invalid conversation. To avoid that, caching the survey url is needed after chat starts and
30
- in this case loadSurvey is false
31
- */
28
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
29
 
33
30
 
34
- if (loadSurvey) {
31
+ BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
35
32
  dispatch({
36
33
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
37
34
  payload: ConversationState.Postchat
38
35
  });
39
- }
36
+ });
40
37
  };