@microsoft/omnichannel-chat-widget 0.1.0-main.fb426ed → 0.1.0-main.fdf1fdf

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 (117) hide show
  1. package/README.md +32 -0
  2. package/lib/cjs/common/Constants.js +18 -2
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +21 -3
  4. package/lib/cjs/common/utils.js +75 -2
  5. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +19 -3
  6. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  7. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +10 -1
  8. package/lib/cjs/components/headerstateful/HeaderStateful.js +4 -3
  9. package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
  10. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  11. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  12. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
  13. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  14. package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
  15. package/lib/cjs/components/livechatwidget/common/authHelper.js +52 -0
  16. package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
  17. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  18. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +13 -3
  19. package/lib/cjs/components/livechatwidget/common/endChat.js +68 -22
  20. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +20 -3
  21. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +55 -35
  22. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  23. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  24. package/lib/cjs/components/livechatwidget/common/startChat.js +163 -80
  25. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +231 -91
  26. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -7
  27. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  28. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +91 -0
  29. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +4 -1
  30. package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +11 -0
  31. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  32. package/lib/cjs/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
  33. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  34. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  35. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  36. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  37. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  38. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  39. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  40. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +3 -0
  41. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
  42. package/lib/cjs/contexts/createReducer.js +16 -0
  43. package/lib/cjs/controller/componentController.js +3 -3
  44. package/lib/esm/common/Constants.js +18 -2
  45. package/lib/esm/common/telemetry/TelemetryConstants.js +21 -3
  46. package/lib/esm/common/utils.js +52 -0
  47. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +21 -6
  48. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  49. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -2
  50. package/lib/esm/components/headerstateful/HeaderStateful.js +4 -3
  51. package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
  52. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  53. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  54. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
  55. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  56. package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
  57. package/lib/esm/components/livechatwidget/common/authHelper.js +39 -0
  58. package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
  59. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  60. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +13 -3
  61. package/lib/esm/components/livechatwidget/common/endChat.js +65 -22
  62. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +19 -5
  63. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +56 -37
  64. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  65. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  66. package/lib/esm/components/livechatwidget/common/startChat.js +157 -82
  67. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +223 -94
  68. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +6 -8
  69. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  70. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +82 -0
  71. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +3 -1
  72. package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +4 -0
  73. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  74. package/lib/esm/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
  75. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  76. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  77. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  78. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  79. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  80. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  81. package/lib/esm/contexts/common/ConversationState.js +3 -2
  82. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +3 -0
  83. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
  84. package/lib/esm/contexts/createReducer.js +16 -0
  85. package/lib/esm/controller/componentController.js +3 -3
  86. package/lib/types/common/Constants.d.ts +9 -1
  87. package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
  88. package/lib/types/common/telemetry/TelemetryConstants.d.ts +21 -4
  89. package/lib/types/common/utils.d.ts +7 -1
  90. package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
  91. package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
  92. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  93. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  94. package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
  95. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  96. package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
  97. package/lib/types/components/livechatwidget/common/authHelper.d.ts +4 -0
  98. package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
  99. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -4
  100. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  101. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  102. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
  103. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -0
  104. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
  105. package/lib/types/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.d.ts +2 -0
  106. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  107. package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +4 -0
  108. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  109. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +4 -0
  110. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  111. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  112. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  113. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  114. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  115. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
  116. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +4 -1
  117. package/package.json +4 -3
@@ -7,21 +7,38 @@ import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontro
7
7
  import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
8
8
  import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
9
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
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
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;
13
+ var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
14
14
 
15
15
  const isPostChatEnabled = (_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable;
16
- const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode;
17
- const conversationDetails = await chatSDK.getConversationDetails();
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
18
17
 
19
- if (isPostChatEnabled === "true" && (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === Constants.truePascal) {
18
+ let conversationDetails = undefined;
19
+
20
+ try {
21
+ conversationDetails = await chatSDK.getConversationDetails();
22
+ } catch (erorr) {
23
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
24
+ Event: TelemetryEvent.GetConversationDetailsException,
25
+ ExceptionDetails: {
26
+ exception: `Failed to get conversation details: ${erorr}`
27
+ }
28
+ });
29
+ }
30
+
31
+ if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === Constants.truePascal) {
20
32
  const skipEndChatSDK = false;
21
33
  const skipCloseChat = true;
22
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
34
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, false);
23
35
 
24
36
  if (postChatSurveyMode === PostChatSurveyMode.Embed) {
37
+ dispatch({
38
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
39
+ payload: ConversationState.PostchatLoading
40
+ });
41
+ await addDelayInMs(Constants.PostChatLoadingDurationInMs);
25
42
  const loadPostChatEvent = {
26
43
  eventName: BroadcastEvent.LoadPostChatSurvey
27
44
  };
@@ -32,28 +49,21 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
32
49
  payload: ConversationState.InActive
33
50
  });
34
51
  }
35
- } else {
36
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
52
+
53
+ return;
37
54
  }
55
+
56
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
38
57
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
58
 
40
59
 
41
- const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat) => {
60
+ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => {
42
61
  if (!skipEndChatSDK) {
43
62
  try {
44
63
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
45
64
  Event: TelemetryEvent.EndChatSDKCall
46
65
  });
47
- await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat()); // Need to clear these states immediately when chat ended from OC.
48
-
49
- dispatch({
50
- type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
51
- payload: undefined
52
- });
53
- dispatch({
54
- type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
55
- payload: undefined
56
- });
66
+ await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
57
67
  } catch (ex) {
58
68
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
59
69
  Event: TelemetryEvent.EndChatSDKCallFailed,
@@ -61,8 +71,23 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
61
71
  exception: ex
62
72
  }
63
73
  });
74
+ postMessageToOtherTab = false;
64
75
  }
65
- }
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
+ });
66
91
 
67
92
  if (!skipCloseChat) {
68
93
  try {
@@ -90,9 +115,27 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
90
115
  type: LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
91
116
  payload: null
92
117
  });
93
- BroadcastService.postMessage({
94
- eventName: BroadcastEvent.EndChat
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
+ }
95
129
  });
130
+
131
+ if (postMessageToOtherTab) {
132
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps;
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, (props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId) ?? "");
135
+ BroadcastService.postMessage({
136
+ eventName: endChatEventName
137
+ });
138
+ }
96
139
  } catch (error) {
97
140
  TelemetryHelper.logActionEvent(LogLevel.ERROR, {
98
141
  Event: TelemetryEvent.CloseChatMethodException,
@@ -7,7 +7,7 @@ import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostC
7
7
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
8
8
  import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
9
9
  import attachmentProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware";
10
- import { changeLanguageCodeFormatForWebChat } from "../../../common/utils";
10
+ import { addDelayInMs, changeLanguageCodeFormatForWebChat } from "../../../common/utils";
11
11
  import channelDataMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware";
12
12
  import { createActivityMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware";
13
13
  import createAttachmentMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware";
@@ -26,10 +26,13 @@ import gifUploadMiddleware from "../../webchatcontainerstateful/webchatcontrolle
26
26
  import htmlPlayerMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlPlayerMiddleware";
27
27
  import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware";
28
28
  import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
29
- import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
30
+ import { createCardActionMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware";
31
+ import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware";
32
+ import { Constants } from "../../../common/Constants"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
33
 
31
34
  export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
32
- var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21;
35
+ var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
33
36
 
34
37
  const localizedTexts = { ...defaultMiddlewareLocalizedTexts,
35
38
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -63,6 +66,12 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
63
66
 
64
67
  if (isPostChatEnabled === "true") {
65
68
  if (postChatSurveyMode === PostChatSurveyMode.Embed) {
69
+ WebChatStoreLoader.store = null;
70
+ dispatch({
71
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
72
+ payload: ConversationState.PostchatLoading
73
+ });
74
+ await addDelayInMs(Constants.PostChatLoadingDurationInMs);
66
75
  const loadPostChatEvent = {
67
76
  eventName: BroadcastEvent.LoadPostChatSurvey
68
77
  };
@@ -74,6 +83,10 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
74
83
  });
75
84
  }
76
85
  } else {
86
+ dispatch({
87
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
88
+ payload: ConversationState.InActive
89
+ });
77
90
  dispatch({
78
91
  type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
79
92
  payload: true
@@ -91,7 +104,7 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
91
104
  };
92
105
 
93
106
  webChatStore = createStore({}, //initial state
94
- preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.allowedFileExtensions, (_state$domainStates$l6 = state.domainStates.liveChatConfig) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware, // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
+ preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.allowedFileExtensions, (_state$domainStates$l6 = state.domainStates.liveChatConfig) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), createMessageTimeStampMiddleware, gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware, // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
108
  ...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
96
109
  WebChatStoreLoader.store = webChatStore;
97
110
  } // Initialize the remaining Web Chat props
@@ -109,7 +122,8 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
109
122
  groupActivitiesMiddleware: (_props$webChatContain17 = props.webChatContainerProps) !== null && _props$webChatContain17 !== void 0 && (_props$webChatContain18 = _props$webChatContain17.renderingMiddlewareProps) !== null && _props$webChatContain18 !== void 0 && _props$webChatContain18.disableGroupActivitiesMiddleware ? undefined : (_defaultWebChatContai2 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai2 === void 0 ? void 0 : _defaultWebChatContai2.groupActivitiesMiddleware,
110
123
  typingIndicatorMiddleware: (_props$webChatContain19 = props.webChatContainerProps) !== null && _props$webChatContain19 !== void 0 && (_props$webChatContain20 = _props$webChatContain19.renderingMiddlewareProps) !== null && _props$webChatContain20 !== void 0 && _props$webChatContain20.disableTypingIndicatorMiddleware ? undefined : (_defaultWebChatContai3 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai3 === void 0 ? void 0 : _defaultWebChatContai3.typingIndicatorMiddleware,
111
124
  onTelemetry: createWebChatTelemetry(),
112
- ...((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.webChatProps)
125
+ cardActionMiddleware: createCardActionMiddleware(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
126
+ ...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
113
127
  };
114
128
  return webChatProps;
115
129
  };
@@ -3,25 +3,34 @@ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/teleme
3
3
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
4
4
  import { ConversationState } from "../../../contexts/common/ConversationState";
5
5
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
6
- import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
-
8
- const getChatReconnectContext = async (chatSDK, reconnectId) => {
9
- try {
10
- if (reconnectId) {
11
- const chatReconnectOptionalParams = {
12
- reconnectId: reconnectId
13
- };
14
- return await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext(chatReconnectOptionalParams));
15
- } else {
16
- return await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext());
17
- }
18
- } catch (ex) {
19
- TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
20
- Event: TelemetryEvent.GetChatReconnectContextSDKCallFailed,
21
- ExceptionDetails: {
22
- exception: ex
6
+ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
7
+ import { handleAuthentication, removeAuthTokenProvider } from "./authHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+
9
+ const getChatReconnectContext = async (chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId) => {
10
+ if (isReconnectEnabled) {
11
+ try {
12
+ if (reconnectId) {
13
+ const chatReconnectOptionalParams = {
14
+ reconnectId: reconnectId
15
+ };
16
+ return await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext(chatReconnectOptionalParams));
17
+ } else {
18
+ // set auth token to chat sdk to get reconnectId for auth chat
19
+ await handleAuthentication(chatSDK, chatConfig, getAuthToken);
20
+ const reconnectChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext()); // remove auth token after reconnectId is fetched
21
+ // this will be reset later at start chat
22
+
23
+ removeAuthTokenProvider(chatSDK);
24
+ return reconnectChatContext;
23
25
  }
24
- });
26
+ } catch (ex) {
27
+ TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
28
+ Event: TelemetryEvent.GetChatReconnectContextSDKCallFailed,
29
+ ExceptionDetails: {
30
+ exception: ex
31
+ }
32
+ });
33
+ }
25
34
  }
26
35
 
27
36
  return null;
@@ -29,13 +38,23 @@ const getChatReconnectContext = async (chatSDK, reconnectId) => {
29
38
 
30
39
 
31
40
  const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
32
- var _props$reconnectChatP, _props$reconnectChatP2;
41
+ var _props$chatConfig, _props$reconnectChatP;
42
+
43
+ let authClientFunction = undefined;
33
44
 
34
- if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && (_props$reconnectChatP2 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP2 !== void 0 && _props$reconnectChatP2.authClientFunction // TODO: Implement this after storage is in place
45
+ if ((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) {
46
+ var _props$chatConfig2, _props$chatConfig2$Li;
47
+
48
+ authClientFunction = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveChatConfigAuthSettings) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_javascriptclientfunction) ?? undefined;
49
+ }
50
+
51
+ if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && authClientFunction // TODO: Implement this after storage is in place
35
52
 
36
53
  /* && !isLoadWithState() */
37
54
  ) {
38
- const previousActiveSessionResponse = await getChatReconnectContext(chatSDK);
55
+ var _props$reconnectChatP2;
56
+
57
+ const previousActiveSessionResponse = await getChatReconnectContext(chatSDK, props.chatConfig, props.getAuthToken, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.isReconnectEnabled);
39
58
 
40
59
  if (previousActiveSessionResponse && previousActiveSessionResponse.reconnectId) {
41
60
  return previousActiveSessionResponse.reconnectId;
@@ -46,27 +65,27 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
46
65
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
66
 
48
67
 
49
- const handleUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
50
- const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
68
+ const handleUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isReconnectEnabled, reconnectId, initStartChat, redirectInSameWindow) => {
69
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId);
51
70
 
52
71
  if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
53
- await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
72
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
54
73
  } else {
55
- await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
74
+ await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
56
75
  }
57
76
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
77
 
59
78
 
60
- const startUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
61
- const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
79
+ const startUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isReconnectEnabled, reconnectId, initStartChat) => {
80
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId);
62
81
 
63
82
  if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
64
- await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
83
+ await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
65
84
  }
66
85
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
86
 
68
87
 
69
- const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
88
+ const setReconnectIdAndStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat) => {
70
89
  const startUnauthenticatedReconnectChat = {
71
90
  eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
72
91
  };
@@ -82,7 +101,7 @@ const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconne
82
101
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
83
102
  payload: ConversationState.Loading
84
103
  });
85
- await initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
104
+ await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, optionalParams);
86
105
  };
87
106
 
88
107
  const redirectPage = (redirectURL, redirectInSameWindow) => {
@@ -104,7 +123,7 @@ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
104
123
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
124
 
106
125
 
107
- const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, initStartChat) => {
126
+ const startNewChatEmptyRedirectionUrl = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat) => {
108
127
  const startUnauthenticatedReconnectChat = {
109
128
  eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
110
129
  };
@@ -127,25 +146,25 @@ const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, in
127
146
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
128
147
  payload: ConversationState.Loading
129
148
  });
130
- await initStartChat(chatSDK, dispatch, setAdapter);
149
+ await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
131
150
  }
132
151
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
152
 
134
153
 
135
- const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
136
- const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
154
+ const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, isReconnectEnabled, reconnectId, redirectInSameWindow) => {
155
+ const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId);
137
156
 
138
157
  if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
139
- await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
158
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
140
159
  }
141
160
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
161
 
143
162
 
144
- const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
163
+ const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
145
164
  if (reconnectAvailabilityResponse.redirectURL) {
146
165
  redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
147
166
  } else {
148
- await startNewChatEmptyRedirectionUrl(chatSDK, dispatch, setAdapter, initStartChat);
167
+ await startNewChatEmptyRedirectionUrl(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat);
149
168
  }
150
169
  };
151
170
 
@@ -29,10 +29,6 @@ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persist
29
29
 
30
30
 
31
31
  BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
32
- dispatch({
33
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
34
- payload: ConversationState.Loading
35
- });
36
32
  dispatch({
37
33
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
38
34
  payload: ConversationState.Postchat
@@ -0,0 +1,38 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export function shareObservable(observable) {
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ let observers = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+
6
+ let subscription; // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+
8
+ return new window.Observable(observer => {
9
+ if (!subscription) {
10
+ subscription = observable.subscribe({
11
+ complete() {
12
+ observers.forEach(observer => observer.complete());
13
+ },
14
+
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ error(err) {
17
+ observers.forEach(observer => observer.error(err));
18
+ },
19
+
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ next(value) {
22
+ observers.forEach(observer => observer.next(value));
23
+ }
24
+
25
+ });
26
+ }
27
+
28
+ observers.push(observer);
29
+ return () => {
30
+ observers = observers.filter(o => o !== observer);
31
+
32
+ if (!observers.length) {
33
+ subscription.unsubscribe();
34
+ subscription = null;
35
+ }
36
+ };
37
+ });
38
+ }