@microsoft/omnichannel-chat-widget 1.2.2-main.03f3121 → 1.2.2-main.26c48a5

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.
@@ -8,12 +8,12 @@ var _TelemetryConstants = require("../../common/telemetry/TelemetryConstants");
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
10
10
  var _Constants = require("../../common/Constants");
11
- var _utils = require("../../common/utils");
12
11
  var _ConversationState = require("../../contexts/common/ConversationState");
13
12
  var _LiveChatWidgetActionType = require("../../contexts/common/LiveChatWidgetActionType");
14
13
  var _TelemetryHelper = require("../../common/telemetry/TelemetryHelper");
15
14
  var _TelemetryManager = require("../../common/telemetry/TelemetryManager");
16
15
  var _defaultOutOfOfficeChatButtonStyleProps = require("./common/styleProps/defaultOutOfOfficeChatButtonStyleProps");
16
+ var _utils = require("../../common/utils");
17
17
  var _useChatContextStore = _interopRequireDefault(require("../../hooks/useChatContextStore"));
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -28,6 +28,22 @@ const ChatButtonStateful = props => {
28
28
  } = props;
29
29
  //Setting OutOfOperatingHours Flag
30
30
  const [outOfOperatingHours, setOutOfOperatingHours] = (0, _react.useState)(((_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.OutOfOperatingHours) === "True");
31
+ const ref = (0, _react.useRef)(() => {
32
+ return;
33
+ });
34
+ ref.current = async () => {
35
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
36
+ Event: _TelemetryConstants.TelemetryEvent.LCWChatButtonClicked
37
+ });
38
+ if (state.appStates.isMinimized) {
39
+ dispatch({
40
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
41
+ payload: false
42
+ });
43
+ } else {
44
+ await startChat();
45
+ }
46
+ };
31
47
  const outOfOfficeStyleProps = Object.assign({}, _defaultOutOfOfficeChatButtonStyleProps.defaultOutOfOfficeChatButtonStyleProps, outOfOfficeButtonProps === null || outOfOfficeButtonProps === void 0 ? void 0 : outOfOfficeButtonProps.styleProps);
32
48
  const controlProps = {
33
49
  id: "oc-lcw-chat-button",
@@ -36,19 +52,7 @@ const ChatButtonStateful = props => {
36
52
  subtitleText: "We're online.",
37
53
  hideNotificationBubble: (buttonProps === null || buttonProps === void 0 ? void 0 : (_buttonProps$controlP = buttonProps.controlProps) === null || _buttonProps$controlP === void 0 ? void 0 : _buttonProps$controlP.hideNotificationBubble) === true || state.appStates.isMinimized === false,
38
54
  unreadMessageCount: state.appStates.unreadMessageCount ? state.appStates.unreadMessageCount > _Constants.Constants.maximumUnreadMessageCount ? (_props$buttonProps = props.buttonProps) === null || _props$buttonProps === void 0 ? void 0 : (_props$buttonProps$co = _props$buttonProps.controlProps) === null || _props$buttonProps$co === void 0 ? void 0 : _props$buttonProps$co.largeUnreadMessageString : state.appStates.unreadMessageCount.toString() : "0",
39
- onClick: async () => {
40
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
41
- Event: _TelemetryConstants.TelemetryEvent.LCWChatButtonClicked
42
- });
43
- if (state.appStates.isMinimized) {
44
- dispatch({
45
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
46
- payload: false
47
- });
48
- } else {
49
- await startChat();
50
- }
51
- },
55
+ onClick: () => ref.current(),
52
56
  unreadMessageString: (_props$buttonProps2 = props.buttonProps) === null || _props$buttonProps2 === void 0 ? void 0 : (_props$buttonProps2$c = _props$buttonProps2.controlProps) === null || _props$buttonProps2$c === void 0 ? void 0 : _props$buttonProps2$c.unreadMessageString,
53
57
  ...(buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.controlProps)
54
58
  };
@@ -88,12 +88,12 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
88
88
  const optionalParams = {
89
89
  isProactiveChat
90
90
  };
91
- await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
91
+ await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams);
92
92
  };
93
93
 
94
94
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
95
  exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
96
- const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
96
+ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
97
97
  var _props$controlProps2;
98
98
  let isStartChatSuccessful = false;
99
99
  const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
@@ -131,7 +131,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
131
131
  try {
132
132
  var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
133
133
  // Set custom context params
134
- await setCustomContextParams(props);
134
+ await setCustomContextParams(state, props);
135
135
  const defaultOptionalParams = {
136
136
  sendDefaultInitContext: true,
137
137
  isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
@@ -295,14 +295,14 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
295
295
  const optionalParams = {
296
296
  liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
297
297
  };
298
- await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
298
+ await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
299
299
  return true;
300
300
  }
301
301
  return false;
302
302
  };
303
303
 
304
304
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
305
- const setCustomContextParams = async props => {
305
+ const setCustomContextParams = async (state, props) => {
306
306
  var _props$chatConfig, _props$chatConfig$Liv, _persistedState$domai8;
307
307
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
308
308
  const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
@@ -310,6 +310,12 @@ const setCustomContextParams = async props => {
310
310
  if (isAuthenticatedChat) {
311
311
  return;
312
312
  }
313
+ if (state !== null && state !== void 0 && state.domainStates.customContext) {
314
+ optionalParams = Object.assign({}, optionalParams, {
315
+ customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : state.domainStates.customContext))
316
+ });
317
+ return;
318
+ }
313
319
  if ((0, _utils.isNullOrEmptyString)(widgetInstanceId)) {
314
320
  widgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props);
315
321
  }
@@ -322,13 +328,13 @@ const setCustomContextParams = async props => {
322
328
  Description: "Setting custom context for unauthenticated chat"
323
329
  });
324
330
  optionalParams = Object.assign({}, optionalParams, {
325
- customContext: customContextLocal
331
+ customContext: JSON.parse(JSON.stringify(customContextLocal))
326
332
  });
327
333
  } else {
328
334
  const customContextFromParent = await getInitContextParamsForPopout();
329
335
  if (!(0, _utils.isUndefinedOrEmpty)(customContextFromParent === null || customContextFromParent === void 0 ? void 0 : customContextFromParent.contextVariables)) {
330
336
  optionalParams = Object.assign({}, optionalParams, {
331
- customContext: customContextFromParent.contextVariables
337
+ customContext: JSON.parse(JSON.stringify(customContextFromParent.contextVariables))
332
338
  });
333
339
  }
334
340
  }
@@ -138,7 +138,7 @@ const LiveChatWidgetStateful = props => {
138
138
  return;
139
139
  }
140
140
  }
141
- await (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, props, optionalParams);
141
+ await (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, state, props, optionalParams);
142
142
  return;
143
143
  }
144
144
  }
@@ -609,7 +609,7 @@ const LiveChatWidgetStateful = props => {
609
609
  const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab, uwid.current);
610
610
  const prepareStartChatRelay = () => (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter);
611
611
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
612
- const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
612
+ const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
613
613
  const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props);
614
614
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
615
615
  const prepareEndChatRelay = () => (0, _endChat.prepareEndChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid.current);
@@ -1,13 +1,13 @@
1
1
  import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
2
- import React, { useEffect, useState } from "react";
2
+ import React, { useEffect, useRef, useState } from "react";
3
3
  import { ChatButton } from "@microsoft/omnichannel-chat-components";
4
4
  import { Constants } from "../../common/Constants";
5
- import { setFocusOnElement } from "../../common/utils";
6
5
  import { ConversationState } from "../../contexts/common/ConversationState";
7
6
  import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
8
7
  import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
9
8
  import { TelemetryTimers } from "../../common/telemetry/TelemetryManager";
10
9
  import { defaultOutOfOfficeChatButtonStyleProps } from "./common/styleProps/defaultOutOfOfficeChatButtonStyleProps";
10
+ import { setFocusOnElement } from "../../common/utils";
11
11
  import useChatContextStore from "../../hooks/useChatContextStore";
12
12
  export const ChatButtonStateful = props => {
13
13
  var _state$domainStates$l, _state$domainStates$l2, _buttonProps$controlP, _props$buttonProps, _props$buttonProps$co, _props$buttonProps2, _props$buttonProps2$c, _props$buttonProps3, _props$buttonProps3$c;
@@ -19,6 +19,22 @@ export const ChatButtonStateful = props => {
19
19
  } = props;
20
20
  //Setting OutOfOperatingHours Flag
21
21
  const [outOfOperatingHours, setOutOfOperatingHours] = useState(((_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.OutOfOperatingHours) === "True");
22
+ const ref = useRef(() => {
23
+ return;
24
+ });
25
+ ref.current = async () => {
26
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
27
+ Event: TelemetryEvent.LCWChatButtonClicked
28
+ });
29
+ if (state.appStates.isMinimized) {
30
+ dispatch({
31
+ type: LiveChatWidgetActionType.SET_MINIMIZED,
32
+ payload: false
33
+ });
34
+ } else {
35
+ await startChat();
36
+ }
37
+ };
22
38
  const outOfOfficeStyleProps = Object.assign({}, defaultOutOfOfficeChatButtonStyleProps, outOfOfficeButtonProps === null || outOfOfficeButtonProps === void 0 ? void 0 : outOfOfficeButtonProps.styleProps);
23
39
  const controlProps = {
24
40
  id: "oc-lcw-chat-button",
@@ -27,19 +43,7 @@ export const ChatButtonStateful = props => {
27
43
  subtitleText: "We're online.",
28
44
  hideNotificationBubble: (buttonProps === null || buttonProps === void 0 ? void 0 : (_buttonProps$controlP = buttonProps.controlProps) === null || _buttonProps$controlP === void 0 ? void 0 : _buttonProps$controlP.hideNotificationBubble) === true || state.appStates.isMinimized === false,
29
45
  unreadMessageCount: state.appStates.unreadMessageCount ? state.appStates.unreadMessageCount > Constants.maximumUnreadMessageCount ? (_props$buttonProps = props.buttonProps) === null || _props$buttonProps === void 0 ? void 0 : (_props$buttonProps$co = _props$buttonProps.controlProps) === null || _props$buttonProps$co === void 0 ? void 0 : _props$buttonProps$co.largeUnreadMessageString : state.appStates.unreadMessageCount.toString() : "0",
30
- onClick: async () => {
31
- TelemetryHelper.logActionEvent(LogLevel.INFO, {
32
- Event: TelemetryEvent.LCWChatButtonClicked
33
- });
34
- if (state.appStates.isMinimized) {
35
- dispatch({
36
- type: LiveChatWidgetActionType.SET_MINIMIZED,
37
- payload: false
38
- });
39
- } else {
40
- await startChat();
41
- }
42
- },
46
+ onClick: () => ref.current(),
43
47
  unreadMessageString: (_props$buttonProps2 = props.buttonProps) === null || _props$buttonProps2 === void 0 ? void 0 : (_props$buttonProps2$c = _props$buttonProps2.controlProps) === null || _props$buttonProps2$c === void 0 ? void 0 : _props$buttonProps2$c.unreadMessageString,
44
48
  ...(buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.controlProps)
45
49
  };
@@ -82,11 +82,11 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
82
82
  const optionalParams = {
83
83
  isProactiveChat
84
84
  };
85
- await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
85
+ await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams);
86
86
  };
87
87
 
88
88
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
- const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
89
+ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
90
90
  var _props$controlProps2;
91
91
  let isStartChatSuccessful = false;
92
92
  const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
@@ -124,7 +124,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
124
124
  try {
125
125
  var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
126
126
  // Set custom context params
127
- await setCustomContextParams(props);
127
+ await setCustomContextParams(state, props);
128
128
  const defaultOptionalParams = {
129
129
  sendDefaultInitContext: true,
130
130
  isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
@@ -287,14 +287,14 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
287
287
  const optionalParams = {
288
288
  liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
289
289
  };
290
- await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
290
+ await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
291
291
  return true;
292
292
  }
293
293
  return false;
294
294
  };
295
295
 
296
296
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
297
- const setCustomContextParams = async props => {
297
+ const setCustomContextParams = async (state, props) => {
298
298
  var _props$chatConfig, _props$chatConfig$Liv, _persistedState$domai8;
299
299
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
300
  const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
@@ -302,6 +302,12 @@ const setCustomContextParams = async props => {
302
302
  if (isAuthenticatedChat) {
303
303
  return;
304
304
  }
305
+ if (state !== null && state !== void 0 && state.domainStates.customContext) {
306
+ optionalParams = Object.assign({}, optionalParams, {
307
+ customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : state.domainStates.customContext))
308
+ });
309
+ return;
310
+ }
305
311
  if (isNullOrEmptyString(widgetInstanceId)) {
306
312
  widgetInstanceId = getWidgetCacheIdfromProps(props);
307
313
  }
@@ -314,13 +320,13 @@ const setCustomContextParams = async props => {
314
320
  Description: "Setting custom context for unauthenticated chat"
315
321
  });
316
322
  optionalParams = Object.assign({}, optionalParams, {
317
- customContext: customContextLocal
323
+ customContext: JSON.parse(JSON.stringify(customContextLocal))
318
324
  });
319
325
  } else {
320
326
  const customContextFromParent = await getInitContextParamsForPopout();
321
327
  if (!isUndefinedOrEmpty(customContextFromParent === null || customContextFromParent === void 0 ? void 0 : customContextFromParent.contextVariables)) {
322
328
  optionalParams = Object.assign({}, optionalParams, {
323
- customContext: customContextFromParent.contextVariables
329
+ customContext: JSON.parse(JSON.stringify(customContextFromParent.contextVariables))
324
330
  });
325
331
  }
326
332
  }
@@ -130,7 +130,7 @@ export const LiveChatWidgetStateful = props => {
130
130
  return;
131
131
  }
132
132
  }
133
- await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
133
+ await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams);
134
134
  return;
135
135
  }
136
136
  }
@@ -601,7 +601,7 @@ export const LiveChatWidgetStateful = props => {
601
601
  const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab, uwid.current);
602
602
  const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
603
603
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
604
- const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
604
+ const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
605
605
  const confirmationPaneProps = initConfirmationPropsComposer(props);
606
606
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
607
607
  const prepareEndChatRelay = () => prepareEndChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid.current);
@@ -5,6 +5,6 @@ import { ILiveChatWidgetProps } from "../interfaces/ILiveChatWidgetProps";
5
5
  import StartChatOptionalParams from "@microsoft/omnichannel-chat-sdk/lib/core/StartChatOptionalParams";
6
6
  declare const prepareStartChat: (props: ILiveChatWidgetProps, chatSDK: any, state: ILiveChatWidgetContext, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any) => Promise<void>;
7
7
  declare const setPreChatAndInitiateChat: (chatSDK: any, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, isProactiveChat?: boolean | undefined, proactiveChatEnablePrechatState?: boolean | undefined, state?: ILiveChatWidgetContext | undefined, props?: ILiveChatWidgetProps | undefined) => Promise<void>;
8
- declare const initStartChat: (chatSDK: any, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, props?: ILiveChatWidgetProps | undefined, params?: StartChatOptionalParams | undefined, persistedState?: any) => Promise<void>;
8
+ declare const initStartChat: (chatSDK: any, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, state: ILiveChatWidgetContext | undefined, props?: ILiveChatWidgetProps | undefined, params?: StartChatOptionalParams | undefined, persistedState?: any) => Promise<void>;
9
9
  declare const checkIfConversationStillValid: (chatSDK: any, dispatch: Dispatch<ILiveChatWidgetAction>, state: ILiveChatWidgetContext) => Promise<boolean>;
10
10
  export { prepareStartChat, initStartChat, setPreChatAndInitiateChat, checkIfConversationStillValid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.2.2-main.03f3121",
3
+ "version": "1.2.2-main.26c48a5",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",