@microsoft/omnichannel-chat-widget 0.1.0-main.d48dae2 → 0.1.0-main.d553f80
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.
- package/lib/cjs/common/Constants.js +2 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +4 -0
- package/lib/cjs/common/utils.js +20 -7
- package/lib/cjs/components/headerstateful/HeaderStateful.js +2 -1
- package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
- package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
- package/lib/cjs/components/livechatwidget/common/authHelper.js +52 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +3 -0
- package/lib/cjs/components/livechatwidget/common/createInternetConnectionChangeHandler.js +12 -0
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +6 -1
- package/lib/cjs/components/livechatwidget/common/endChat.js +3 -3
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +4 -0
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +35 -23
- package/lib/cjs/components/livechatwidget/common/startChat.js +39 -47
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +107 -44
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +11 -0
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +11 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +1 -0
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -1
- package/lib/cjs/contexts/createReducer.js +8 -0
- package/lib/esm/common/Constants.js +2 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +4 -0
- package/lib/esm/common/utils.js +14 -5
- package/lib/esm/components/headerstateful/HeaderStateful.js +2 -1
- package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
- package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
- package/lib/esm/components/livechatwidget/common/authHelper.js +39 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +3 -1
- package/lib/esm/components/livechatwidget/common/createInternetConnectionChangeHandler.js +8 -0
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +6 -1
- package/lib/esm/components/livechatwidget/common/endChat.js +3 -3
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +4 -0
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +36 -25
- package/lib/esm/components/livechatwidget/common/startChat.js +35 -47
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +106 -46
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +10 -0
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +4 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +1 -0
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -1
- package/lib/esm/contexts/createReducer.js +8 -0
- package/lib/types/common/Constants.d.ts +1 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +3 -1
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -1
- package/lib/types/common/utils.d.ts +4 -3
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
- package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
- package/lib/types/components/livechatwidget/common/authHelper.d.ts +4 -0
- package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +4 -4
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +2 -2
- package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -0
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +2 -1
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -41,4 +41,5 @@ exports.LiveChatWidgetActionType = LiveChatWidgetActionType;
|
|
|
41
41
|
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_LIVE_CHAT_CONTEXT"] = 30] = "SET_LIVE_CHAT_CONTEXT";
|
|
42
42
|
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_BOT_OAUTH_SIGNIN_ID"] = 31] = "SET_BOT_OAUTH_SIGNIN_ID";
|
|
43
43
|
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_SIZE"] = 32] = "SET_WIDGET_SIZE";
|
|
44
|
+
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_INSTANCE_ID"] = 33] = "SET_WIDGET_INSTANCE_ID";
|
|
44
45
|
})(LiveChatWidgetActionType || (exports.LiveChatWidgetActionType = LiveChatWidgetActionType = {}));
|
|
@@ -29,7 +29,8 @@ const getLiveChatWidgetContextInitialState = props => {
|
|
|
29
29
|
globalDir: "ltr",
|
|
30
30
|
liveChatContext: undefined,
|
|
31
31
|
customContext: undefined,
|
|
32
|
-
widgetSize: undefined
|
|
32
|
+
widgetSize: undefined,
|
|
33
|
+
widgetInstanceId: ""
|
|
33
34
|
},
|
|
34
35
|
appStates: {
|
|
35
36
|
conversationState: _ConversationState.ConversationState.Closed,
|
|
@@ -243,6 +243,14 @@ const createReducer = () => {
|
|
|
243
243
|
}
|
|
244
244
|
};
|
|
245
245
|
|
|
246
|
+
case _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_INSTANCE_ID:
|
|
247
|
+
return { ...state,
|
|
248
|
+
domainStates: { ...state.domainStates,
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
250
|
+
widgetInstanceId: action.payload
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
246
254
|
default:
|
|
247
255
|
return state;
|
|
248
256
|
}
|
|
@@ -160,6 +160,8 @@ _defineProperty(Constants, "ChatWidgetStateChangedPrefix", "ChatWidgetStateChang
|
|
|
160
160
|
|
|
161
161
|
_defineProperty(Constants, "PostChatLoadingDurationInMs", 2000);
|
|
162
162
|
|
|
163
|
+
_defineProperty(Constants, "BrowserUnloadConfirmationMessage", "Do you want to leave chat?");
|
|
164
|
+
|
|
163
165
|
export const Regex = (_class = class Regex {}, _defineProperty(_class, "EmailRegex", "(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"), _class);
|
|
164
166
|
export class HtmlIdNames {}
|
|
165
167
|
|
|
@@ -159,6 +159,8 @@ export let TelemetryEvent;
|
|
|
159
159
|
TelemetryEvent["MessageSent"] = "MessageSent";
|
|
160
160
|
TelemetryEvent["MessageReceived"] = "MessageReceived";
|
|
161
161
|
TelemetryEvent["CustomContextReceived"] = "CustomContextReceived";
|
|
162
|
+
TelemetryEvent["NetworkDisconnected"] = "NetworkDisconnected";
|
|
163
|
+
TelemetryEvent["NetworkReconnected"] = "NetworkReconnected";
|
|
162
164
|
})(TelemetryEvent || (TelemetryEvent = {}));
|
|
163
165
|
|
|
164
166
|
export class TelemetryConstants {
|
|
@@ -205,6 +207,8 @@ export class TelemetryConstants {
|
|
|
205
207
|
case TelemetryEvent.MessageReceived:
|
|
206
208
|
case TelemetryEvent.CustomContextReceived:
|
|
207
209
|
case TelemetryEvent.BrowserUnloadEventStarted:
|
|
210
|
+
case TelemetryEvent.NetworkDisconnected:
|
|
211
|
+
case TelemetryEvent.NetworkReconnected:
|
|
208
212
|
return ScenarioType.ACTIONS;
|
|
209
213
|
|
|
210
214
|
case TelemetryEvent.StartChatSDKCall:
|
package/lib/esm/common/utils.js
CHANGED
|
@@ -2,6 +2,7 @@ import { AriaTelemetryConstants, Constants, LocaleConstants } from "./Constants"
|
|
|
2
2
|
import { DataStoreManager } from "./contextDataStore/DataStoreManager";
|
|
3
3
|
import { KeyCodes } from "./KeyCodes";
|
|
4
4
|
import { BroadcastEvent } from "./telemetry/TelemetryConstants";
|
|
5
|
+
import { Md5 } from "md5-typescript";
|
|
5
6
|
|
|
6
7
|
const getElementBySelector = selector => {
|
|
7
8
|
let element;
|
|
@@ -290,20 +291,25 @@ export const getDomain = hostValue => {
|
|
|
290
291
|
|
|
291
292
|
return AriaTelemetryConstants.Public;
|
|
292
293
|
};
|
|
293
|
-
export const getWidgetCacheId = (orgId, widgetId) => {
|
|
294
|
-
|
|
294
|
+
export const getWidgetCacheId = (orgId, widgetId, widgetInstanceId) => {
|
|
295
|
+
const widgetCacheId = `${widgetInstanceId}_${orgId}_${widgetId}`;
|
|
296
|
+
return Md5.init(widgetCacheId);
|
|
295
297
|
};
|
|
296
|
-
export const getWidgetEndChatEventName = (orgId, widgetId) => {
|
|
298
|
+
export const getWidgetEndChatEventName = (orgId, widgetId, widgetInstanceId) => {
|
|
299
|
+
if (!isNullOrEmptyString(widgetInstanceId)) {
|
|
300
|
+
return `${BroadcastEvent.ChatEnded}_${widgetInstanceId}_${orgId}_${widgetId}`;
|
|
301
|
+
}
|
|
302
|
+
|
|
297
303
|
return `${BroadcastEvent.ChatEnded}_${orgId}_${widgetId}`;
|
|
298
304
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
299
305
|
|
|
300
|
-
export const getStateFromCache = (orgId, widgetId) => {
|
|
306
|
+
export const getStateFromCache = (orgId, widgetId, widgetInstanceId) => {
|
|
301
307
|
// Getting updated state from cache
|
|
302
308
|
try {
|
|
303
309
|
if (DataStoreManager.clientDataStore) {
|
|
304
310
|
var _DataStoreManager$cli;
|
|
305
311
|
|
|
306
|
-
const widgetStateEventName = getWidgetCacheId(orgId, widgetId);
|
|
312
|
+
const widgetStateEventName = getWidgetCacheId(orgId, widgetId, widgetInstanceId);
|
|
307
313
|
const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
|
|
308
314
|
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
309
315
|
return persistedState;
|
|
@@ -330,4 +336,7 @@ export const isUndefinedOrEmpty = object => {
|
|
|
330
336
|
|
|
331
337
|
export const addDelayInMs = ms => {
|
|
332
338
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
339
|
+
};
|
|
340
|
+
export const getBroadcastChannelName = (widgetId, widgetInstanceId) => {
|
|
341
|
+
return widgetInstanceId && !isNullOrEmptyString(widgetInstanceId) ? `${widgetInstanceId}_${widgetId}` : widgetId;
|
|
333
342
|
};
|
|
@@ -49,7 +49,8 @@ export const HeaderStateful = props => {
|
|
|
49
49
|
} else {
|
|
50
50
|
const skipEndChatSDK = true;
|
|
51
51
|
const skipCloseChat = false;
|
|
52
|
-
|
|
52
|
+
const postMessageToOtherTabs = true;
|
|
53
|
+
await endChat(adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTabs);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
dispatch({
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
import { Deferred } from "./Deferred";
|
|
4
|
+
export class ActivityStreamHandler {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Use of a deferred pattern, to hold the execution of the activity.
|
|
10
|
+
*
|
|
11
|
+
* */
|
|
12
|
+
static cork() {
|
|
13
|
+
ActivityStreamHandler.restoreDeferred = new Deferred();
|
|
14
|
+
ActivityStreamHandler.restorePromise = ActivityStreamHandler.restoreDeferred.promise;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the promise, releasing it to continue with the execution of the activity.
|
|
18
|
+
*
|
|
19
|
+
* */
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
static uncork() {
|
|
23
|
+
ActivityStreamHandler.restoreDeferred.resolve();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_defineProperty(ActivityStreamHandler, "restoreDeferred", {
|
|
29
|
+
resolve: () => {
|
|
30
|
+
return "initialState";
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
_defineProperty(ActivityStreamHandler, "restorePromise", void 0);
|
package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
import { ActivityStreamHandler } from "../ActivityStreamHandler";
|
|
4
|
+
export class PauseActivitySubscriber {
|
|
5
|
+
constructor() {
|
|
6
|
+
_defineProperty(this, "observer", void 0);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
async apply(activity) {
|
|
11
|
+
await ActivityStreamHandler.restorePromise;
|
|
12
|
+
return activity;
|
|
13
|
+
} // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
applicable(activity) {
|
|
17
|
+
return true;
|
|
18
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
async next(activity) {
|
|
22
|
+
if (this.applicable(activity)) {
|
|
23
|
+
return await this.apply(activity);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return activity;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
export class Deferred {
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
constructor() {
|
|
6
|
+
_defineProperty(this, "_promise", void 0);
|
|
7
|
+
|
|
8
|
+
_defineProperty(this, "_resolve", void 0);
|
|
9
|
+
|
|
10
|
+
_defineProperty(this, "_reject", () => {
|
|
11
|
+
return;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
_defineProperty(this, "resolve", value => {
|
|
15
|
+
this._resolve(value);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
_defineProperty(this, "reject", value => {
|
|
19
|
+
this._reject(value);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
this._promise = new Promise((resolve, reject) => {
|
|
23
|
+
this._resolve = resolve;
|
|
24
|
+
this._reject = reject;
|
|
25
|
+
});
|
|
26
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
get promise() {
|
|
30
|
+
return this._promise;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
3
|
+
import { isNullOrEmptyString } from "../../../common/utils"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
|
|
5
|
+
const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
|
|
6
|
+
let authClientFunction = undefined;
|
|
7
|
+
|
|
8
|
+
if (chatConfig !== null && chatConfig !== void 0 && chatConfig.LiveChatConfigAuthSettings) {
|
|
9
|
+
var _chatConfig$LiveChatC;
|
|
10
|
+
|
|
11
|
+
authClientFunction = (chatConfig === null || chatConfig === void 0 ? void 0 : (_chatConfig$LiveChatC = chatConfig.LiveChatConfigAuthSettings) === null || _chatConfig$LiveChatC === void 0 ? void 0 : _chatConfig$LiveChatC.msdyn_javascriptclientfunction) ?? undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (getAuthToken && authClientFunction) {
|
|
15
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
16
|
+
Event: TelemetryEvent.GetAuthTokenCalled
|
|
17
|
+
});
|
|
18
|
+
const token = await getAuthToken(authClientFunction);
|
|
19
|
+
|
|
20
|
+
if (!isNullOrEmptyString(token)) {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
chatSDK.setAuthTokenProvider(async () => {
|
|
23
|
+
return token;
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
27
|
+
Event: TelemetryEvent.ReceivedNullOrEmptyToken
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
const removeAuthTokenProvider = chatSDK => {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
chatSDK.authenticatedUserToken = null;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { handleAuthentication, removeAuthTokenProvider };
|
|
@@ -2,7 +2,8 @@ import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontr
|
|
|
2
2
|
import { NotificationLevel } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationLevel";
|
|
3
3
|
import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
4
4
|
import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
|
|
5
|
-
import { ChatAdapterShim } from "./ChatAdapterShim";
|
|
5
|
+
import { ChatAdapterShim } from "./ChatAdapterShim";
|
|
6
|
+
import { PauseActivitySubscriber } from "./ActivitySubscriber/PauseActivitySubscriber"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
7
|
|
|
7
8
|
export const createAdapter = async chatSDK => {
|
|
8
9
|
const chatAdapterOptionalParams = {
|
|
@@ -28,6 +29,7 @@ export const createAdapter = async chatSDK => {
|
|
|
28
29
|
|
|
29
30
|
if (chatSDK.isMockModeOn !== true) {
|
|
30
31
|
adapter = new ChatAdapterShim(adapter);
|
|
32
|
+
adapter.addSubscriber(new PauseActivitySubscriber());
|
|
31
33
|
return adapter.chatAdapter;
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -2,6 +2,8 @@ import { Constants } from "../../../common/Constants";
|
|
|
2
2
|
import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
|
|
3
3
|
import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
4
4
|
import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
|
|
5
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
6
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
5
7
|
|
|
6
8
|
const isInternetConnected = async () => {
|
|
7
9
|
try {
|
|
@@ -18,8 +20,14 @@ export const createInternetConnectionChangeHandler = async () => {
|
|
|
18
20
|
const connected = await isInternetConnected();
|
|
19
21
|
|
|
20
22
|
if (!connected) {
|
|
23
|
+
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
24
|
+
Event: TelemetryEvent.NetworkDisconnected
|
|
25
|
+
});
|
|
21
26
|
NotificationHandler.notifyError(NotificationScenarios.InternetConnection, defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_NO_INTERNET_CONNECTION);
|
|
22
27
|
} else {
|
|
28
|
+
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
29
|
+
Event: TelemetryEvent.NetworkReconnected
|
|
30
|
+
});
|
|
23
31
|
NotificationHandler.notifySuccess(NotificationScenarios.InternetConnection, defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_INTERNET_BACK_ONLINE);
|
|
24
32
|
}
|
|
25
33
|
}; // Checking connection status on online & offline events due to possible false positives
|
|
@@ -318,7 +318,8 @@ export const dummyDefaultProps = {
|
|
|
318
318
|
hideChatTitle: false,
|
|
319
319
|
hideNotificationBubble: true,
|
|
320
320
|
unreadMessageString: "new messages",
|
|
321
|
-
largeUnreadMessageString: "99+"
|
|
321
|
+
largeUnreadMessageString: "99+",
|
|
322
|
+
ariaLabelUnreadMessageString: "you have new messages"
|
|
322
323
|
},
|
|
323
324
|
styleProps: {
|
|
324
325
|
generalStyleProps: {
|
|
@@ -1681,6 +1682,10 @@ export const dummyDefaultProps = {
|
|
|
1681
1682
|
botMagicCode: {
|
|
1682
1683
|
disabled: false,
|
|
1683
1684
|
fwdUrl: ""
|
|
1685
|
+
},
|
|
1686
|
+
adaptiveCardStyles: {
|
|
1687
|
+
background: "white",
|
|
1688
|
+
color: "black"
|
|
1684
1689
|
}
|
|
1685
1690
|
},
|
|
1686
1691
|
telemetryConfig: undefined,
|
|
@@ -31,7 +31,7 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
|
|
|
31
31
|
if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === Constants.truePascal) {
|
|
32
32
|
const skipEndChatSDK = false;
|
|
33
33
|
const skipCloseChat = true;
|
|
34
|
-
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat,
|
|
34
|
+
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, false);
|
|
35
35
|
|
|
36
36
|
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
37
37
|
dispatch({
|
|
@@ -129,9 +129,9 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
if (postMessageToOtherTab) {
|
|
132
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
|
|
132
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps;
|
|
133
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);
|
|
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
135
|
BroadcastService.postMessage({
|
|
136
136
|
eventName: endChatEventName
|
|
137
137
|
});
|
|
@@ -83,6 +83,10 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
} else {
|
|
86
|
+
dispatch({
|
|
87
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
88
|
+
payload: ConversationState.InActive
|
|
89
|
+
});
|
|
86
90
|
dispatch({
|
|
87
91
|
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
|
|
88
92
|
payload: true
|
|
@@ -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";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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;
|
|
@@ -43,7 +52,9 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
|
|
|
43
52
|
|
|
44
53
|
/* && !isLoadWithState() */
|
|
45
54
|
) {
|
|
46
|
-
|
|
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);
|
|
47
58
|
|
|
48
59
|
if (previousActiveSessionResponse && previousActiveSessionResponse.reconnectId) {
|
|
49
60
|
return previousActiveSessionResponse.reconnectId;
|
|
@@ -54,8 +65,8 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
|
|
|
54
65
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
66
|
|
|
56
67
|
|
|
57
|
-
const handleUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
|
|
58
|
-
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);
|
|
59
70
|
|
|
60
71
|
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
61
72
|
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
@@ -65,8 +76,8 @@ const handleUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthTo
|
|
|
65
76
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
77
|
|
|
67
78
|
|
|
68
|
-
const startUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
69
|
-
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);
|
|
70
81
|
|
|
71
82
|
if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
72
83
|
await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
|
|
@@ -140,8 +151,8 @@ const startNewChatEmptyRedirectionUrl = async (chatSDK, chatConfig, getAuthToken
|
|
|
140
151
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
152
|
|
|
142
153
|
|
|
143
|
-
const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
|
|
144
|
-
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);
|
|
145
156
|
|
|
146
157
|
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
147
158
|
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
@@ -8,19 +8,24 @@ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
|
8
8
|
import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
|
|
9
9
|
import { createAdapter } from "./createAdapter";
|
|
10
10
|
import { createOnNewAdapterActivityHandler } from "../../../plugins/newMessageEventHandler";
|
|
11
|
-
import { createTimer, getStateFromCache,
|
|
11
|
+
import { createTimer, getStateFromCache, isUndefinedOrEmpty } from "../../../common/utils";
|
|
12
12
|
import { getReconnectIdForAuthenticatedChat, handleRedirectUnauthenticatedReconnectChat } from "./reconnectChatHelper";
|
|
13
13
|
import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
|
|
14
14
|
import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
|
|
15
|
-
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
15
|
+
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
16
|
+
import { ActivityStreamHandler } from "./ActivityStreamHandler";
|
|
17
|
+
import { handleAuthentication } from "./authHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
18
|
|
|
17
19
|
let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
20
|
|
|
21
|
+
let widgetInstanceId; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
|
|
19
23
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
20
|
-
var _props$reconnectChatP;
|
|
24
|
+
var _props$controlProps, _props$reconnectChatP;
|
|
21
25
|
|
|
22
26
|
optionalParams = {}; //Resetting to ensure no stale values
|
|
23
|
-
|
|
27
|
+
|
|
28
|
+
widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId; // Can connect to existing chat session
|
|
24
29
|
|
|
25
30
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
26
31
|
return;
|
|
@@ -28,9 +33,9 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
28
33
|
|
|
29
34
|
|
|
30
35
|
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
31
|
-
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
36
|
+
var _props$reconnectChatP2, _props$reconnectChatP3, _props$reconnectChatP4;
|
|
32
37
|
|
|
33
|
-
await handleRedirectUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.
|
|
38
|
+
await handleRedirectUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.isReconnectEnabled, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.reconnectId, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.redirectInSameWindow);
|
|
34
39
|
return;
|
|
35
40
|
} // Getting reconnectId for authenticated chat
|
|
36
41
|
|
|
@@ -47,10 +52,8 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
47
52
|
payload: ConversationState.ReconnectChat
|
|
48
53
|
});
|
|
49
54
|
return;
|
|
50
|
-
} //
|
|
51
|
-
|
|
55
|
+
} // Setting Proactive chat settings
|
|
52
56
|
|
|
53
|
-
setCustomContextParams(props, chatSDK); // Setting Proactive chat settings
|
|
54
57
|
|
|
55
58
|
const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
|
|
56
59
|
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
|
|
@@ -86,35 +89,6 @@ const setPreChatAndInitiateChat = async (chatSDK, chatConfig, getAuthToken, disp
|
|
|
86
89
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
90
|
|
|
88
91
|
|
|
89
|
-
const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
|
|
90
|
-
if (getAuthToken) {
|
|
91
|
-
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
92
|
-
Event: TelemetryEvent.GetAuthTokenCalled
|
|
93
|
-
});
|
|
94
|
-
let authClientFunction = undefined;
|
|
95
|
-
|
|
96
|
-
if (chatConfig !== null && chatConfig !== void 0 && chatConfig.LiveChatConfigAuthSettings) {
|
|
97
|
-
var _chatConfig$LiveChatC;
|
|
98
|
-
|
|
99
|
-
authClientFunction = (chatConfig === null || chatConfig === void 0 ? void 0 : (_chatConfig$LiveChatC = chatConfig.LiveChatConfigAuthSettings) === null || _chatConfig$LiveChatC === void 0 ? void 0 : _chatConfig$LiveChatC.msdyn_javascriptclientfunction) ?? undefined;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const token = await getAuthToken(authClientFunction);
|
|
103
|
-
|
|
104
|
-
if (!isNullOrEmptyString(token)) {
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
-
chatSDK.setAuthTokenProvider(async () => {
|
|
107
|
-
return token;
|
|
108
|
-
});
|
|
109
|
-
} else {
|
|
110
|
-
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
111
|
-
Event: TelemetryEvent.ReceivedNullOrEmptyToken
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
-
|
|
117
|
-
|
|
118
92
|
const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, params, persistedState) => {
|
|
119
93
|
try {
|
|
120
94
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
@@ -138,8 +112,9 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
138
112
|
TelemetryTimers.WidgetLoadTimer = createTimer();
|
|
139
113
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
140
114
|
Event: TelemetryEvent.StartChatSDKCall
|
|
141
|
-
}); // Set
|
|
115
|
+
}); // Set custom context params
|
|
142
116
|
|
|
117
|
+
setCustomContextParams(chatSDK);
|
|
143
118
|
optionalParams = Object.assign({}, params, optionalParams); // set auth token to chat sdk before start chat
|
|
144
119
|
|
|
145
120
|
await handleAuthentication(chatSDK, chatConfig, getAuthToken);
|
|
@@ -193,6 +168,7 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
193
168
|
await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
|
|
194
169
|
|
|
195
170
|
if (isStartChatSuccessful) {
|
|
171
|
+
ActivityStreamHandler.uncork();
|
|
196
172
|
dispatch({
|
|
197
173
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
198
174
|
payload: ConversationState.Active
|
|
@@ -225,19 +201,20 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
225
201
|
}
|
|
226
202
|
} finally {
|
|
227
203
|
optionalParams = {};
|
|
204
|
+
widgetInstanceId = "";
|
|
228
205
|
}
|
|
229
206
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
230
207
|
|
|
231
208
|
|
|
232
209
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
233
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _persistedState$domai6, _persistedState$appSt;
|
|
210
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps2, _persistedState$domai6, _persistedState$appSt;
|
|
234
211
|
|
|
235
212
|
// By pass this function in case of popout chat
|
|
236
213
|
if (state.appStates.skipChatButtonRendering === true) {
|
|
237
214
|
return false;
|
|
238
215
|
}
|
|
239
216
|
|
|
240
|
-
const persistedState = getStateFromCache(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); //Connect to only active chat session
|
|
217
|
+
const persistedState = getStateFromCache(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$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? ""); //Connect to only active chat session
|
|
241
218
|
|
|
242
219
|
if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === ConversationState.Active) {
|
|
243
220
|
var _persistedState$domai7;
|
|
@@ -257,17 +234,28 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
257
234
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
235
|
|
|
259
236
|
|
|
260
|
-
const setCustomContextParams =
|
|
261
|
-
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4,
|
|
237
|
+
const setCustomContextParams = chatSDK => {
|
|
238
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _persistedState$domai8;
|
|
262
239
|
|
|
263
240
|
// Add custom context only for unauthenticated chat
|
|
264
|
-
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId);
|
|
241
|
+
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId, widgetInstanceId ?? "");
|
|
242
|
+
|
|
243
|
+
if (!isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
|
|
244
|
+
var _persistedState$domai9, _persistedState$domai10;
|
|
265
245
|
|
|
266
|
-
|
|
267
|
-
|
|
246
|
+
if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai9 = persistedState.domainStates.liveChatConfig) !== null && _persistedState$domai9 !== void 0 && _persistedState$domai9.LiveChatConfigAuthSettings) {
|
|
247
|
+
const errorMessage = "Use of custom context with authenticated chat is deprecated. The chat would not go through.";
|
|
248
|
+
TelemetryHelper.logSDKEvent(LogLevel.WARN, {
|
|
249
|
+
Event: TelemetryEvent.StartChatMethodException,
|
|
250
|
+
ExceptionDetails: {
|
|
251
|
+
exception: errorMessage
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
throw new Error(errorMessage);
|
|
255
|
+
}
|
|
268
256
|
|
|
269
257
|
optionalParams = Object.assign({}, optionalParams, {
|
|
270
|
-
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$
|
|
258
|
+
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai10 = persistedState.domainStates) === null || _persistedState$domai10 === void 0 ? void 0 : _persistedState$domai10.customContext
|
|
271
259
|
});
|
|
272
260
|
}
|
|
273
261
|
};
|