@microsoft/omnichannel-chat-widget 1.7.3-main.7a38853 → 1.7.3-main.c8bb80a

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.
@@ -101,6 +101,7 @@ exports.TelemetryEvent = TelemetryEvent;
101
101
  TelemetryEvent["GetConversationDetailsCallStarted"] = "GetConversationDetailsCallStarted";
102
102
  TelemetryEvent["GetConversationDetailsCallFailed"] = "GetConversationDetailsCallFailed";
103
103
  TelemetryEvent["EndChatSDKCallFailed"] = "EndChatSDKCallFailed";
104
+ TelemetryEvent["DisconnectEndChatSDKCallFailed"] = "DisconnectEndChatSDKCallFailed";
104
105
  TelemetryEvent["GetChatReconnectContextSDKCallStarted"] = "GetChatReconnectContextSDKCallStarted";
105
106
  TelemetryEvent["GetChatReconnectContextSDKCallFailed"] = "GetChatReconnectContextSDKCallFailed";
106
107
  TelemetryEvent["ParseAdaptiveCardFailed"] = "ParseAdaptiveCardFailed";
@@ -141,12 +141,27 @@ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatSt
141
141
  await (0, _authHelper.handleAuthentication)(chatSDK, props.chatConfig, props.getAuthToken);
142
142
  await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
143
143
  } catch (ex) {
144
- _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
145
- Event: _TelemetryConstants.TelemetryEvent.EndChatSDKCallFailed,
146
- ExceptionDetails: {
147
- exception: ex
148
- }
144
+ var _inMemoryState$appSta;
145
+ const inMemoryState = (0, _createReducer.executeReducer)(state, {
146
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
147
+ payload: null
149
148
  });
149
+ // if the chat was disconnected or ended by the agent, we don't want to log the error
150
+ if (!(inMemoryState !== null && inMemoryState !== void 0 && (_inMemoryState$appSta = inMemoryState.appStates) !== null && _inMemoryState$appSta !== void 0 && _inMemoryState$appSta.chatDisconnectEventReceived)) {
151
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
152
+ Event: _TelemetryConstants.TelemetryEvent.EndChatSDKCallFailed,
153
+ ExceptionDetails: {
154
+ exception: ex
155
+ }
156
+ });
157
+ } else {
158
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.WARN, {
159
+ Event: _TelemetryConstants.TelemetryEvent.DisconnectEndChatSDKCallFailed,
160
+ ExceptionDetails: {
161
+ exception: ex
162
+ }
163
+ });
164
+ }
150
165
  postMessageToOtherTab = false;
151
166
  } finally {
152
167
  await endChatStateCleanUp(dispatch);
@@ -30,10 +30,25 @@ let widgetInstanceId;
30
30
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
31
  let popoutWidgetInstanceId;
32
32
 
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ const setAuthenticationIfApplicable = async (props, chatSDK) => {
35
+ const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
36
+ const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
37
+ const authClientFunction = (0, _authHelper.getAuthClientFunction)(chatConfig);
38
+ if (getAuthToken && authClientFunction) {
39
+ // set auth token to chat sdk before start chat
40
+ const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
41
+ if (!authSuccess) {
42
+ throw new Error(_Constants.WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
43
+ }
44
+ }
45
+ };
46
+
33
47
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
48
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
35
49
  optionalParams = {}; //Resetting to ensure no stale values
36
50
  widgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props);
51
+
37
52
  // reconnect > chat from cache
38
53
  if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
39
54
  const shouldStartChatNormally = await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, initStartChat, state);
@@ -56,6 +71,11 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
56
71
  const isProactiveChat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat;
57
72
  const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
58
73
 
74
+ // Setting auth settings to OC API to retrieve existing persistent chat session before start chat if any
75
+ if ((0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
76
+ await setAuthenticationIfApplicable(props, chatSDK);
77
+ }
78
+
59
79
  //Setting PreChat and intiate chat
60
80
  await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
61
81
  };
@@ -132,8 +152,6 @@ exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
132
152
  const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
133
153
  var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
134
154
  let isStartChatSuccessful = false;
135
- const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
136
- const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
137
155
  const persistentChatEnabled = await (0, _liveChatConfigUtils.isPersistentChatEnabled)(state === null || state === void 0 ? void 0 : (_state$domainStates5 = state.domainStates) === null || _state$domainStates5 === void 0 ? void 0 : (_state$domainStates5$ = _state$domainStates5.liveChatConfig) === null || _state$domainStates5$ === void 0 ? void 0 : (_state$domainStates5$2 = _state$domainStates5$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates5$2 === void 0 ? void 0 : _state$domainStates5$2.msdyn_conversationmode);
138
156
  if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === _ConversationState.ConversationState.Closed) {
139
157
  // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
@@ -153,14 +171,9 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
153
171
  Event: _TelemetryConstants.TelemetryEvent.WidgetLoadStarted,
154
172
  Description: "Widget loading started"
155
173
  });
156
- const authClientFunction = (0, _authHelper.getAuthClientFunction)(chatConfig);
157
- if (getAuthToken && authClientFunction) {
158
- // set auth token to chat sdk before start chat
159
- const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
160
- if (!authSuccess) {
161
- throw new Error(_Constants.WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
162
- }
163
- }
174
+
175
+ // Auth token retrieval needs to happen during start chat to support pop-out chat
176
+ await setAuthenticationIfApplicable(props, chatSDK);
164
177
 
165
178
  //Check if chat retrieved from cache
166
179
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
@@ -20,7 +20,7 @@ const createOnNewAdapterActivityHandler = (chatId, userId) => {
20
20
  const raiseMessageEvent = (activity, isHistoryMessage) => {
21
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
22
  const polyfillMessagePayloadForEvent = payload => {
23
- var _activity$conversatio, _TelemetryManager$Int;
23
+ var _activity$conversatio, _TelemetryManager$Int, _attachments;
24
24
  return {
25
25
  ...payload,
26
26
  channelData: activity === null || activity === void 0 ? void 0 : activity.channelData,
@@ -29,7 +29,9 @@ const createOnNewAdapterActivityHandler = (chatId, userId) => {
29
29
  id: activity === null || activity === void 0 ? void 0 : activity.id,
30
30
  isChatComplete: false,
31
31
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- text: activity === null || activity === void 0 ? void 0 : activity.text
32
+ text: activity === null || activity === void 0 ? void 0 : activity.text,
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ attachment: (activity === null || activity === void 0 ? void 0 : (_attachments = activity.attachments) === null || _attachments === void 0 ? void 0 : _attachments.length) >= 1 ? activity === null || activity === void 0 ? void 0 : activity.attachments : []
33
35
  };
34
36
  };
35
37
  if ((activity === null || activity === void 0 ? void 0 : activity.type) === _Constants.Constants.message) {
@@ -95,6 +95,7 @@ export let TelemetryEvent;
95
95
  TelemetryEvent["GetConversationDetailsCallStarted"] = "GetConversationDetailsCallStarted";
96
96
  TelemetryEvent["GetConversationDetailsCallFailed"] = "GetConversationDetailsCallFailed";
97
97
  TelemetryEvent["EndChatSDKCallFailed"] = "EndChatSDKCallFailed";
98
+ TelemetryEvent["DisconnectEndChatSDKCallFailed"] = "DisconnectEndChatSDKCallFailed";
98
99
  TelemetryEvent["GetChatReconnectContextSDKCallStarted"] = "GetChatReconnectContextSDKCallStarted";
99
100
  TelemetryEvent["GetChatReconnectContextSDKCallFailed"] = "GetChatReconnectContextSDKCallFailed";
100
101
  TelemetryEvent["ParseAdaptiveCardFailed"] = "ParseAdaptiveCardFailed";
@@ -135,12 +135,27 @@ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatSt
135
135
  await handleAuthentication(chatSDK, props.chatConfig, props.getAuthToken);
136
136
  await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
137
137
  } catch (ex) {
138
- TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
139
- Event: TelemetryEvent.EndChatSDKCallFailed,
140
- ExceptionDetails: {
141
- exception: ex
142
- }
138
+ var _inMemoryState$appSta;
139
+ const inMemoryState = executeReducer(state, {
140
+ type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
141
+ payload: null
143
142
  });
143
+ // if the chat was disconnected or ended by the agent, we don't want to log the error
144
+ if (!(inMemoryState !== null && inMemoryState !== void 0 && (_inMemoryState$appSta = inMemoryState.appStates) !== null && _inMemoryState$appSta !== void 0 && _inMemoryState$appSta.chatDisconnectEventReceived)) {
145
+ TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
146
+ Event: TelemetryEvent.EndChatSDKCallFailed,
147
+ ExceptionDetails: {
148
+ exception: ex
149
+ }
150
+ });
151
+ } else {
152
+ TelemetryHelper.logSDKEvent(LogLevel.WARN, {
153
+ Event: TelemetryEvent.DisconnectEndChatSDKCallFailed,
154
+ ExceptionDetails: {
155
+ exception: ex
156
+ }
157
+ });
158
+ }
144
159
  postMessageToOtherTab = false;
145
160
  } finally {
146
161
  await endChatStateCleanUp(dispatch);
@@ -25,10 +25,25 @@ let widgetInstanceId;
25
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
26
  let popoutWidgetInstanceId;
27
27
 
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ const setAuthenticationIfApplicable = async (props, chatSDK) => {
30
+ const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
31
+ const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
32
+ const authClientFunction = getAuthClientFunction(chatConfig);
33
+ if (getAuthToken && authClientFunction) {
34
+ // set auth token to chat sdk before start chat
35
+ const authSuccess = await handleAuthentication(chatSDK, chatConfig, getAuthToken);
36
+ if (!authSuccess) {
37
+ throw new Error(WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
38
+ }
39
+ }
40
+ };
41
+
28
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
43
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
30
44
  optionalParams = {}; //Resetting to ensure no stale values
31
45
  widgetInstanceId = getWidgetCacheIdfromProps(props);
46
+
32
47
  // reconnect > chat from cache
33
48
  if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
34
49
  const shouldStartChatNormally = await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
@@ -51,6 +66,11 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
51
66
  const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
52
67
  const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
53
68
 
69
+ // Setting auth settings to OC API to retrieve existing persistent chat session before start chat if any
70
+ if (isPersistentEnabled(props.chatConfig)) {
71
+ await setAuthenticationIfApplicable(props, chatSDK);
72
+ }
73
+
54
74
  //Setting PreChat and intiate chat
55
75
  await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
56
76
  };
@@ -125,8 +145,6 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
125
145
  const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
126
146
  var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
127
147
  let isStartChatSuccessful = false;
128
- const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
129
- const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
130
148
  const persistentChatEnabled = await isPersistentChatEnabled(state === null || state === void 0 ? void 0 : (_state$domainStates5 = state.domainStates) === null || _state$domainStates5 === void 0 ? void 0 : (_state$domainStates5$ = _state$domainStates5.liveChatConfig) === null || _state$domainStates5$ === void 0 ? void 0 : (_state$domainStates5$2 = _state$domainStates5$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates5$2 === void 0 ? void 0 : _state$domainStates5$2.msdyn_conversationmode);
131
149
  if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === ConversationState.Closed) {
132
150
  // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
@@ -146,14 +164,9 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
146
164
  Event: TelemetryEvent.WidgetLoadStarted,
147
165
  Description: "Widget loading started"
148
166
  });
149
- const authClientFunction = getAuthClientFunction(chatConfig);
150
- if (getAuthToken && authClientFunction) {
151
- // set auth token to chat sdk before start chat
152
- const authSuccess = await handleAuthentication(chatSDK, chatConfig, getAuthToken);
153
- if (!authSuccess) {
154
- throw new Error(WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
155
- }
156
- }
167
+
168
+ // Auth token retrieval needs to happen during start chat to support pop-out chat
169
+ await setAuthenticationIfApplicable(props, chatSDK);
157
170
 
158
171
  //Check if chat retrieved from cache
159
172
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
@@ -14,7 +14,7 @@ export const createOnNewAdapterActivityHandler = (chatId, userId) => {
14
14
  const raiseMessageEvent = (activity, isHistoryMessage) => {
15
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
16
  const polyfillMessagePayloadForEvent = payload => {
17
- var _activity$conversatio, _TelemetryManager$Int;
17
+ var _activity$conversatio, _TelemetryManager$Int, _attachments;
18
18
  return {
19
19
  ...payload,
20
20
  channelData: activity === null || activity === void 0 ? void 0 : activity.channelData,
@@ -23,7 +23,9 @@ export const createOnNewAdapterActivityHandler = (chatId, userId) => {
23
23
  id: activity === null || activity === void 0 ? void 0 : activity.id,
24
24
  isChatComplete: false,
25
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- text: activity === null || activity === void 0 ? void 0 : activity.text
26
+ text: activity === null || activity === void 0 ? void 0 : activity.text,
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ attachment: (activity === null || activity === void 0 ? void 0 : (_attachments = activity.attachments) === null || _attachments === void 0 ? void 0 : _attachments.length) >= 1 ? activity === null || activity === void 0 ? void 0 : activity.attachments : []
27
29
  };
28
30
  };
29
31
  if ((activity === null || activity === void 0 ? void 0 : activity.type) === Constants.message) {
@@ -88,6 +88,7 @@ export declare enum TelemetryEvent {
88
88
  GetConversationDetailsCallStarted = "GetConversationDetailsCallStarted",
89
89
  GetConversationDetailsCallFailed = "GetConversationDetailsCallFailed",
90
90
  EndChatSDKCallFailed = "EndChatSDKCallFailed",
91
+ DisconnectEndChatSDKCallFailed = "DisconnectEndChatSDKCallFailed",
91
92
  GetChatReconnectContextSDKCallStarted = "GetChatReconnectContextSDKCallStarted",
92
93
  GetChatReconnectContextSDKCallFailed = "GetChatReconnectContextSDKCallFailed",
93
94
  ParseAdaptiveCardFailed = "ParseAdaptiveCardFailed",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.7.3-main.7a38853",
3
+ "version": "1.7.3-main.c8bb80a",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -75,9 +75,9 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@microsoft/omnichannel-chat-components": "1.1.5",
78
- "@microsoft/omnichannel-chat-sdk": "^1.9.5",
78
+ "@microsoft/omnichannel-chat-sdk": "^1.9.6",
79
79
  "abort-controller-es5": "^2.0.1",
80
- "dompurify": "^2.3.4",
80
+ "dompurify": "^2.5.4",
81
81
  "markdown-it": "^12.3.2",
82
82
  "markdown-it-attrs": "^4.1.6",
83
83
  "markdown-it-attrs-es5": "^2.0.2",