@microsoft/omnichannel-chat-widget 0.1.0-main.47ede4d → 0.1.0-main.72620c9

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 (58) hide show
  1. package/lib/cjs/common/Constants.js +32 -4
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +13 -1
  3. package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
  4. package/lib/cjs/common/telemetry/TelemetryManager.js +4 -1
  5. package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  6. package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +31 -10
  7. package/lib/cjs/common/utils.js +15 -2
  8. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +4 -39
  9. package/lib/cjs/components/footerstateful/FooterStateful.js +1 -2
  10. package/lib/cjs/components/headerstateful/HeaderStateful.js +1 -7
  11. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +5 -2
  12. package/lib/cjs/components/livechatwidget/common/endChat.js +37 -1
  13. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +3 -0
  14. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +105 -20
  15. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +3 -15
  16. package/lib/cjs/components/livechatwidget/common/startChat.js +38 -29
  17. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +57 -15
  18. package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
  19. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +44 -0
  20. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +15 -16
  21. package/lib/cjs/contexts/createReducer.js +0 -7
  22. package/lib/esm/common/Constants.js +28 -3
  23. package/lib/esm/common/telemetry/TelemetryConstants.js +13 -1
  24. package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
  25. package/lib/esm/common/telemetry/TelemetryManager.js +4 -1
  26. package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  27. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +33 -13
  28. package/lib/esm/common/utils.js +11 -1
  29. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -37
  30. package/lib/esm/components/footerstateful/FooterStateful.js +1 -2
  31. package/lib/esm/components/headerstateful/HeaderStateful.js +1 -7
  32. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +5 -3
  33. package/lib/esm/components/livechatwidget/common/endChat.js +37 -3
  34. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +2 -0
  35. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +94 -20
  36. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +3 -13
  37. package/lib/esm/components/livechatwidget/common/startChat.js +39 -30
  38. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +55 -17
  39. package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
  40. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +31 -0
  41. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +15 -16
  42. package/lib/esm/contexts/createReducer.js +0 -7
  43. package/lib/types/common/Constants.d.ts +16 -1
  44. package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
  45. package/lib/types/common/telemetry/TelemetryConstants.d.ts +9 -2
  46. package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -0
  47. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
  48. package/lib/types/common/utils.d.ts +1 -0
  49. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
  50. package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
  51. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
  52. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -2
  53. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  54. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -1
  55. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -0
  56. package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
  57. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +15 -16
  58. package/package.json +6 -7
@@ -1,9 +1,10 @@
1
- import { isNullOrEmptyString, isNullOrUndefined } from "../../utils";
1
+ import { getDomain, isNullOrEmptyString, isNullOrUndefined } from "../../utils";
2
2
  import AWTEventProperties from "@microsoft/omnichannel-chat-sdk/lib/external/aria/webjs/AWTEventProperties";
3
3
  import AWTLogManager from "@microsoft/omnichannel-chat-sdk/lib/external/aria/webjs/AWTLogManager";
4
4
  import { AWTPiiKind } from "@microsoft/omnichannel-chat-sdk/lib/external/aria/common/Enums";
5
- import { Constants } from "../../Constants";
5
+ import { Constants, AriaTelemetryConstants, EnvironmentVersion } from "../../Constants";
6
6
  import { TelemetryHelper } from "../TelemetryHelper";
7
+ import { TelemetryManager } from "../TelemetryManager";
7
8
  export const ariaTelemetryLogger = (ariaTelemetryKey, disabledCookieUsage, collectiorUriForTelemetry, ariaTelemetryApplicationName) => {
8
9
  let _logger;
9
10
 
@@ -15,6 +16,21 @@ export const ariaTelemetryLogger = (ariaTelemetryKey, disabledCookieUsage, colle
15
16
 
16
17
  if (!isNullOrEmptyString(collectiorUriForTelemetry)) {
17
18
  configuration.collectorUri = collectiorUriForTelemetry;
19
+ } else {
20
+ if (TelemetryManager.InternalTelemetryData.environmentVersion == EnvironmentVersion.prod) {
21
+ var _TelemetryManager$Int;
22
+
23
+ const orgUrl = (_TelemetryManager$Int = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int === void 0 ? void 0 : _TelemetryManager$Int.orgUrl;
24
+
25
+ if (!isNullOrUndefined(orgUrl)) {
26
+ // If the given org is a Production EU org, modify the Aria collector uri
27
+ const region = getDomain(orgUrl);
28
+
29
+ if (region === AriaTelemetryConstants.EU) {
30
+ configuration.collectorUri = AriaTelemetryConstants.EUROPE_ENDPOINT;
31
+ }
32
+ }
33
+ }
18
34
  }
19
35
 
20
36
  try {
@@ -33,18 +49,22 @@ export const ariaTelemetryLogger = (ariaTelemetryKey, disabledCookieUsage, colle
33
49
 
34
50
  const ariaLogger = {
35
51
  log: (logLevel, telemetryInput) => {
36
- let property;
37
- const eventProperties = new AWTEventProperties();
38
- const event = TelemetryHelper.buildTelemetryEvent(logLevel, telemetryInput);
39
- eventProperties.setName(telemetryInput.scenarioType);
40
-
41
- for (const key of Object.keys(event)) {
42
- property = typeof event[key] === "object" ? JSON.stringify(event[key]) : event[key];
43
- eventProperties.setProperty(key, property);
44
- }
52
+ try {
53
+ let property;
54
+ const eventProperties = new AWTEventProperties();
55
+ const event = TelemetryHelper.buildTelemetryEvent(logLevel, telemetryInput);
56
+ eventProperties.setName(telemetryInput.scenarioType);
57
+
58
+ for (const key of Object.keys(event)) {
59
+ property = typeof event[key] === "object" ? JSON.stringify(event[key]) : event[key];
60
+ eventProperties.setProperty(key, property);
61
+ }
45
62
 
46
- eventProperties.setPropertyWithPii(ariaTelemetryApplicationName, Constants.LiveChatWidget, AWTPiiKind.GenericData);
47
- logger() ? logger().logEvent(eventProperties) : console.log("Unable to initialize aria logger");
63
+ eventProperties.setPropertyWithPii(ariaTelemetryApplicationName, Constants.LiveChatWidget, AWTPiiKind.GenericData);
64
+ logger() ? logger().logEvent(eventProperties) : console.log("Unable to initialize aria logger");
65
+ } catch (error) {
66
+ console.error("Error in logging telemetry to Aria logger:" + error);
67
+ }
48
68
  },
49
69
  dispose: () => {
50
70
  AWTLogManager.flush(function () {
@@ -1,4 +1,4 @@
1
- import { Constants, LocaleConstants } from "./Constants";
1
+ import { AriaTelemetryConstants, Constants, LocaleConstants } from "./Constants";
2
2
  import { KeyCodes } from "./KeyCodes";
3
3
 
4
4
  const getElementBySelector = selector => {
@@ -276,4 +276,14 @@ export const createTimer = () => {
276
276
  }
277
277
 
278
278
  };
279
+ }; // Returns the domain of the org
280
+
281
+ export const getDomain = hostValue => {
282
+ for (let i = 0; i < AriaTelemetryConstants.lcwEUDomainNames.length; i++) {
283
+ if (hostValue.endsWith(AriaTelemetryConstants.lcwEUDomainNames[i])) {
284
+ return AriaTelemetryConstants.EU;
285
+ }
286
+ }
287
+
288
+ return AriaTelemetryConstants.Public;
279
289
  };
@@ -1,35 +1,25 @@
1
- import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
2
- import { BroadcastService, ConfirmationPane } from "@microsoft/omnichannel-chat-components";
1
+ import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
2
+ import { ConfirmationPane } from "@microsoft/omnichannel-chat-components";
3
3
  import React, { useEffect } from "react";
4
4
  import { findAllFocusableElement, findParentFocusableElementsWithoutChildContainer, preventFocusToMoveOutOfElement, setFocusOnElement, setFocusOnSendBox, setTabIndices } from "../../common/utils";
5
- import { Constants } from "../../common/Constants";
6
- import { ConversationState } from "../../contexts/common/ConversationState";
7
5
  import { DimLayer } from "../dimlayer/DimLayer";
8
6
  import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
9
7
  import { NotificationHandler } from "../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
10
8
  import { NotificationScenarios } from "../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
11
- import { PostChatSurveyMode } from "../postchatsurveypanestateful/enums/PostChatSurveyMode";
12
9
  import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
13
10
  import useChatAdapterStore from "../../hooks/useChatAdapterStore";
14
- import useChatContextStore from "../../hooks/useChatContextStore";
15
- import useChatSDKStore from "../../hooks/useChatSDKStore"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ import useChatContextStore from "../../hooks/useChatContextStore"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
12
 
17
13
  export const ConfirmationPaneStateful = props => {
18
- var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4;
19
-
20
14
  const initialTabIndexMap = new Map();
21
- let elements = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
-
23
- const chatSDK = useChatSDKStore();
15
+ let elements = [];
24
16
  const [state, dispatch] = useChatContextStore();
25
17
  const {
26
- endChat
18
+ prepareEndChat
27
19
  } = props; // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
21
 
30
22
  const [adapter] = useChatAdapterStore();
31
- 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;
32
- 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;
33
23
  const controlProps = {
34
24
  id: "oc-lcw-confirmation-pane",
35
25
  dir: state.domainStates.globalDir,
@@ -44,28 +34,8 @@ export const ConfirmationPaneStateful = props => {
44
34
  });
45
35
 
46
36
  try {
47
- // check agent has joined conversation
48
- const conversationDetails = await chatSDK.getConversationDetails();
49
-
50
- if (isPostChatEnabled === "true" && (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === Constants.truePascal) {
51
- if (postChatSurveyMode === PostChatSurveyMode.Embed) {
52
- const loadPostChatEvent = {
53
- eventName: BroadcastEvent.LoadPostChatSurvey
54
- };
55
- BroadcastService.postMessage(loadPostChatEvent);
56
- } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
57
- const skipEndChatSDK = false;
58
- const skipCloseChat = true;
59
- await endChat(adapter, skipEndChatSDK, skipCloseChat);
60
- dispatch({
61
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
62
- payload: ConversationState.InActive
63
- });
64
- }
65
- } else {
66
- setTabIndices(elements, initialTabIndexMap, true);
67
- await endChat(adapter);
68
- }
37
+ setTabIndices(elements, initialTabIndexMap, true);
38
+ await prepareEndChat(adapter, state);
69
39
  } catch (ex) {
70
40
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
71
41
  Event: TelemetryEvent.GetConversationDetailsCallFailed,
@@ -97,8 +97,7 @@ export const FooterStateful = props => {
97
97
  styleProps: footerProps === null || footerProps === void 0 ? void 0 : footerProps.styleProps
98
98
  }), /*#__PURE__*/React.createElement(AudioNotificationStateful, {
99
99
  audioSrc: (audioNotificationProps === null || audioNotificationProps === void 0 ? void 0 : audioNotificationProps.audioSrc) ?? NewMessageNotificationSoundBase64,
100
- hideAudioNotificationButton: (footerProps === null || footerProps === void 0 ? void 0 : (_footerProps$controlP4 = footerProps.controlProps) === null || _footerProps$controlP4 === void 0 ? void 0 : _footerProps$controlP4.hideAudioNotificationButton) ?? false,
101
- isAudioMuted: state.appStates.isAudioMuted ?? false
100
+ isAudioMuted: state.appStates.isAudioMuted === null ? (footerProps === null || footerProps === void 0 ? void 0 : (_footerProps$controlP4 = footerProps.controlProps) === null || _footerProps$controlP4 === void 0 ? void 0 : _footerProps$controlP4.hideAudioNotificationButton) ?? false : state.appStates.isAudioMuted ?? false
102
101
  }));
103
102
  };
104
103
  export default FooterStateful;
@@ -46,13 +46,7 @@ export const HeaderStateful = props => {
46
46
  type: LiveChatWidgetActionType.SET_SHOW_CONFIRMATION,
47
47
  payload: true
48
48
  });
49
- } else if (conversationState.current === ConversationState.Postchat) {
50
- dispatch({
51
- type: LiveChatWidgetActionType.SET_SHOULD_SHOW_POST_CHAT,
52
- payload: false
53
- });
54
- await endChat(adapter);
55
- } else if (conversationState.current === ConversationState.InActive) {
49
+ } else {
56
50
  const skipEndChatSDK = true;
57
51
  const skipCloseChat = false;
58
52
  await endChat(adapter, skipEndChatSDK, skipCloseChat);
@@ -9,7 +9,8 @@ import createAttachmentMiddleware from "../../../webchatcontainerstateful/webcha
9
9
  import { createAvatarMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware";
10
10
  import { createMarkdown } from "../createMarkdown";
11
11
  import { groupActivitiesMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/groupActivitiesMiddleware";
12
- import { typingIndicatorMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware"; // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ import { typingIndicatorMiddleware } from "../../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware";
13
+ import { createWebChatTelemetry } from "../../../webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger"; // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
14
 
14
15
  export const dummyDefaultProps = {
15
16
  audioNotificationProps: {
@@ -1424,7 +1425,8 @@ export const dummyDefaultProps = {
1424
1425
  },
1425
1426
  authClientFunction: undefined,
1426
1427
  isReconnectEnabled: undefined,
1427
- reconnectId: undefined
1428
+ reconnectId: undefined,
1429
+ redirectInSameWindow: undefined
1428
1430
  },
1429
1431
  styleProps: {
1430
1432
  generalStyles: {
@@ -1496,7 +1498,7 @@ export const dummyDefaultProps = {
1496
1498
  internalErrorBoxClass: undefined,
1497
1499
  internalRenderErrorBox: undefined,
1498
1500
  locale: "en-US",
1499
- onTelemetry: undefined,
1501
+ onTelemetry: createWebChatTelemetry(),
1500
1502
  overrideLocalizedStrings: undefined,
1501
1503
  renderMarkdown: createMarkdown(false, false),
1502
1504
  scrollToEndButtonMiddleware: undefined,
@@ -4,9 +4,41 @@ import { ConversationState } from "../../../contexts/common/ConversationState";
4
4
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
5
5
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
6
6
  import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
7
- import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
8
+ import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
9
+ import { Constants } from "../../../common/Constants";
8
10
 
9
- export const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat) => {
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
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;
14
+
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();
18
+
19
+ if (isPostChatEnabled === "true" && (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === Constants.truePascal) {
20
+ const skipEndChatSDK = false;
21
+ const skipCloseChat = true;
22
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
23
+
24
+ if (postChatSurveyMode === PostChatSurveyMode.Embed) {
25
+ const loadPostChatEvent = {
26
+ eventName: BroadcastEvent.LoadPostChatSurvey
27
+ };
28
+ BroadcastService.postMessage(loadPostChatEvent);
29
+ } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
30
+ dispatch({
31
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
32
+ payload: ConversationState.InActive
33
+ });
34
+ }
35
+ } else {
36
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
37
+ }
38
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+
40
+
41
+ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat) => {
10
42
  if (!skipEndChatSDK) {
11
43
  try {
12
44
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
@@ -69,4 +101,6 @@ export const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
69
101
  });
70
102
  }
71
103
  }
72
- };
104
+ };
105
+
106
+ export { prepareEndChat, endChat };
@@ -17,6 +17,7 @@ import createConversationEndMiddleware from "../../webchatcontainerstateful/webc
17
17
  import createDataMaskingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/dataMaskingMiddleware";
18
18
  import { createMarkdown } from "./createMarkdown";
19
19
  import createMaxMessageSizeValidator from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/maxMessageSizeValidator";
20
+ import { createWebChatTelemetry } from "../../webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger";
20
21
  import { defaultAttachmentProps } from "../../webchatcontainerstateful/common/defaultProps/defaultAttachmentProps";
21
22
  import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
22
23
  import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
@@ -103,6 +104,7 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
103
104
  avatarMiddleware: (_props$webChatContain15 = props.webChatContainerProps) !== null && _props$webChatContain15 !== void 0 && (_props$webChatContain16 = _props$webChatContain15.renderingMiddlewareProps) !== null && _props$webChatContain16 !== void 0 && _props$webChatContain16.disableAvatarMiddleware ? undefined : createAvatarMiddleware((_state$domainStates$r5 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r5 === void 0 ? void 0 : _state$domainStates$r5.avatarStyleProps, (_state$domainStates$r6 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r6 === void 0 ? void 0 : _state$domainStates$r6.avatarTextStyleProps),
104
105
  groupActivitiesMiddleware: (_props$webChatContain17 = props.webChatContainerProps) !== null && _props$webChatContain17 !== void 0 && (_props$webChatContain18 = _props$webChatContain17.renderingMiddlewareProps) !== null && _props$webChatContain18 !== void 0 && _props$webChatContain18.disableGroupActivitiesMiddleware ? undefined : (_defaultWebChatContai2 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai2 === void 0 ? void 0 : _defaultWebChatContai2.groupActivitiesMiddleware,
105
106
  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,
107
+ onTelemetry: createWebChatTelemetry(),
106
108
  ...((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.webChatProps)
107
109
  };
108
110
  return webChatProps;
@@ -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,22 +1,12 @@
1
1
  import { RegisterLoggers, TelemetryManager } from "../../../common/telemetry/TelemetryManager";
2
2
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
3
3
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
4
- import { version as chatComponentVersion } from "@microsoft/omnichannel-chat-components/package.json";
5
- import { version as chatSdkVersion } from "@microsoft/omnichannel-chat-sdk/package.json";
6
4
  import { defaultAriaConfig } from "../../../common/telemetry/defaultConfigs/defaultAriaConfig";
7
5
  import { defaultInternalTelemetryData } from "../../../common/telemetry/defaultConfigs/defaultTelemetryInternalData";
8
6
  import { defaultTelemetryConfiguration } from "../../../common/telemetry/defaultConfigs/defaultTelemetryConfiguration";
9
7
  export const registerTelemetryLoggers = (props, dispatch) => {
10
8
  var _props$liveChatContex, _props$liveChatContex2;
11
9
 
12
- let widgetPackageInfo;
13
-
14
- try {
15
- widgetPackageInfo = require("@microsoft/omnichannel-chat-widget/package.json");
16
- } catch (error) {
17
- widgetPackageInfo = "0.0.0-0";
18
- }
19
-
20
10
  const telemetryConfig = { ...defaultTelemetryConfiguration,
21
11
  ...props.telemetryConfig
22
12
  };
@@ -38,9 +28,9 @@ export const registerTelemetryLoggers = (props, dispatch) => {
38
28
  }
39
29
 
40
30
  telemetryData = TelemetryHelper.addWidgetDataToTelemetry(telemetryConfig, telemetryData);
41
- telemetryData.OCChatSDKVersion = chatSdkVersion;
42
- telemetryData.chatComponentVersion = chatComponentVersion;
43
- telemetryData.chatWidgetVersion = widgetPackageInfo;
31
+ telemetryData.OCChatSDKVersion = telemetryConfig.OCChatSDKVersion ?? "0.0.0-0";
32
+ telemetryData.chatComponentVersion = telemetryConfig.chatComponentVersion ?? "0.0.0-0";
33
+ telemetryData.chatWidgetVersion = telemetryConfig.chatWidgetVersion ?? "0.0.0-0";
44
34
  telemetryData.orgId = (_props$chatSDK = props.chatSDK) === null || _props$chatSDK === void 0 ? void 0 : (_props$chatSDK$omnich = _props$chatSDK.omnichannelConfig) === null || _props$chatSDK$omnich === void 0 ? void 0 : _props$chatSDK$omnich.orgId;
45
35
  telemetryData.widgetId = (_props$chatSDK2 = props.chatSDK) === null || _props$chatSDK2 === void 0 ? void 0 : (_props$chatSDK2$omnic = _props$chatSDK2.omnichannelConfig) === null || _props$chatSDK2$omnic === void 0 ? void 0 : _props$chatSDK2$omnic.widgetId;
46
36
  telemetryData.orgUrl = (_props$chatSDK3 = props.chatSDK) === null || _props$chatSDK3 === void 0 ? void 0 : (_props$chatSDK3$omnic = _props$chatSDK3.omnichannelConfig) === null || _props$chatSDK3$omnic === void 0 ? void 0 : _props$chatSDK3$omnic.orgUrl;
@@ -10,46 +10,55 @@ import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
10
10
  import { createAdapter } from "./createAdapter";
11
11
  import { createOnNewAdapterActivityHandler } from "../../../plugins/newMessageEventHandler";
12
12
  import { createTimer } from "../../../common/utils";
13
- import { getReconnectIdForAuthenticatedChat } from "./reconnectChatHelper";
13
+ import { getReconnectIdForAuthenticatedChat, handleRedirectUnauthenticatedReconnectChat } from "./reconnectChatHelper";
14
14
  import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
15
15
  import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
16
 
17
17
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
18
+ var _props$reconnectChatP;
19
+
18
20
  if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
19
21
  return;
20
- } // Getting PreChat Survey Context
21
-
22
+ } // Redirecting if unauthenticated reconnect chat expired
22
23
 
23
- const parseToJson = false;
24
- const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
25
- const showPrechat = state.appStates.conversationState === ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
26
24
 
27
- const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
25
+ if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
26
+ var _props$reconnectChatP2, _props$reconnectChatP3;
28
27
 
29
- if (reconnectId) {
30
- dispatch({
31
- type: LiveChatWidgetActionType.SET_RECONNECT_ID,
32
- payload: reconnectId
33
- });
34
- dispatch({
35
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
36
- payload: ConversationState.ReconnectChat
37
- });
38
- } else if (showPrechat) {
39
- dispatch({
40
- type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
41
- payload: preChatSurveyResponse
42
- });
43
- dispatch({
44
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
45
- payload: ConversationState.Prechat
46
- });
28
+ await handleRedirectUnauthenticatedReconnectChat(chatSDK, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.redirectInSameWindow);
47
29
  } else {
48
- dispatch({
49
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
50
- payload: ConversationState.Loading
51
- });
52
- await initStartChat(chatSDK, dispatch, setAdapter);
30
+ // Getting PreChat Survey Context
31
+ const parseToJson = false;
32
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
33
+ const showPrechat = state.appStates.conversationState === ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
34
+
35
+ const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
36
+
37
+ if (reconnectId) {
38
+ dispatch({
39
+ type: LiveChatWidgetActionType.SET_RECONNECT_ID,
40
+ payload: reconnectId
41
+ });
42
+ dispatch({
43
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
44
+ payload: ConversationState.ReconnectChat
45
+ });
46
+ } else if (showPrechat) {
47
+ dispatch({
48
+ type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
49
+ payload: preChatSurveyResponse
50
+ });
51
+ dispatch({
52
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
53
+ payload: ConversationState.Prechat
54
+ });
55
+ } else {
56
+ dispatch({
57
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
58
+ payload: ConversationState.Loading
59
+ });
60
+ await initStartChat(chatSDK, dispatch, setAdapter);
61
+ }
53
62
  }
54
63
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
64