@microsoft/omnichannel-chat-widget 1.7.4-main.c3fef22 → 1.7.4-main.e66bbe9
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/facades/FacadeChatSDK.js +298 -0
- package/lib/cjs/common/facades/types/IFacadeChatSDKInput.js +1 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +5 -0
- package/lib/cjs/common/telemetry/TelemetryHelper.js +10 -0
- package/lib/cjs/common/utils.js +2 -2
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +4 -8
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -6
- package/lib/cjs/components/footerstateful/FooterStateful.js +4 -5
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
- package/lib/cjs/components/livechatwidget/LiveChatWidget.js +26 -3
- package/lib/cjs/components/livechatwidget/common/authHelper.js +14 -5
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +9 -9
- package/lib/cjs/components/livechatwidget/common/endChat.js +21 -22
- package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +3 -3
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +2 -2
- package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +2 -3
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -12
- package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +5 -5
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +4 -4
- package/lib/cjs/components/livechatwidget/common/startChat.js +41 -35
- package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +7 -7
- package/lib/cjs/components/livechatwidget/common/updateSessionDataForTelemetry.js +8 -8
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -39
- package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -2
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
- package/lib/cjs/contexts/FacadeChatSDKStore.js +10 -0
- package/lib/cjs/hooks/useFacadeChatSDKStore.js +17 -0
- package/lib/cjs/index.js +9 -2
- package/lib/cjs/plugins/createChatTranscript.js +2 -2
- package/lib/esm/common/facades/FacadeChatSDK.js +291 -0
- package/lib/esm/common/facades/types/IFacadeChatSDKInput.js +1 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +5 -0
- package/lib/esm/common/telemetry/TelemetryHelper.js +10 -0
- package/lib/esm/common/utils.js +2 -2
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +4 -8
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -6
- package/lib/esm/components/footerstateful/FooterStateful.js +4 -5
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
- package/lib/esm/components/livechatwidget/LiveChatWidget.js +26 -3
- package/lib/esm/components/livechatwidget/common/authHelper.js +14 -5
- package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -9
- package/lib/esm/components/livechatwidget/common/endChat.js +21 -22
- package/lib/esm/components/livechatwidget/common/initCallingSdk.js +3 -3
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +2 -2
- package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +2 -4
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +11 -12
- package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +5 -5
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +4 -4
- package/lib/esm/components/livechatwidget/common/startChat.js +41 -35
- package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +7 -7
- package/lib/esm/components/livechatwidget/common/updateSessionDataForTelemetry.js +8 -8
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -39
- package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -2
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
- package/lib/esm/contexts/FacadeChatSDKStore.js +4 -0
- package/lib/esm/hooks/useFacadeChatSDKStore.js +10 -0
- package/lib/esm/index.js +5 -4
- package/lib/esm/plugins/createChatTranscript.js +2 -2
- package/lib/types/common/facades/FacadeChatSDK.d.ts +71 -0
- package/lib/types/common/facades/types/IFacadeChatSDKInput.d.ts +13 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +6 -1
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +6 -0
- package/lib/types/common/utils.d.ts +2 -1
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +3 -2
- package/lib/types/components/livechatwidget/common/authHelper.d.ts +14 -1
- package/lib/types/components/livechatwidget/common/createAdapter.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -3
- package/lib/types/components/livechatwidget/common/initCallingSdk.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +3 -2
- package/lib/types/components/livechatwidget/common/renderSurveyHelpers.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +5 -4
- package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/updateSessionDataForTelemetry.d.ts +2 -1
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +2 -1
- package/lib/types/contexts/FacadeChatSDKStore.d.ts +1 -0
- package/lib/types/hooks/useFacadeChatSDKStore.d.ts +3 -0
- package/lib/types/index.d.ts +4 -3
- package/lib/types/plugins/createChatTranscript.d.ts +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
3
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
4
|
+
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../telemetry/TelemetryConstants";
|
|
5
|
+
import { getAuthClientFunction, handleAuthentication } from "../../components/livechatwidget/common/authHelper";
|
|
6
|
+
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
7
|
+
import { TelemetryHelper } from "../telemetry/TelemetryHelper";
|
|
8
|
+
import { isNullOrEmptyString } from "../utils";
|
|
9
|
+
export class FacadeChatSDK {
|
|
10
|
+
isSDKMocked() {
|
|
11
|
+
return this.sdkMocked;
|
|
12
|
+
}
|
|
13
|
+
getChatSDK() {
|
|
14
|
+
return this.chatSDK;
|
|
15
|
+
}
|
|
16
|
+
destroy() {
|
|
17
|
+
this.token = null;
|
|
18
|
+
this.expiration = 0;
|
|
19
|
+
}
|
|
20
|
+
isTokenSet() {
|
|
21
|
+
return !isNullOrEmptyString(this.token);
|
|
22
|
+
}
|
|
23
|
+
constructor(input) {
|
|
24
|
+
_defineProperty(this, "chatSDK", void 0);
|
|
25
|
+
_defineProperty(this, "chatConfig", void 0);
|
|
26
|
+
_defineProperty(this, "token", "");
|
|
27
|
+
_defineProperty(this, "expiration", 0);
|
|
28
|
+
_defineProperty(this, "isAuthenticated", void 0);
|
|
29
|
+
_defineProperty(this, "getAuthToken", void 0);
|
|
30
|
+
_defineProperty(this, "sdkMocked", void 0);
|
|
31
|
+
this.chatSDK = input.chatSDK;
|
|
32
|
+
this.chatConfig = input.chatConfig;
|
|
33
|
+
this.getAuthToken = input.getAuthToken;
|
|
34
|
+
this.isAuthenticated = input.isAuthenticated;
|
|
35
|
+
this.sdkMocked = input.isSDKMocked;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//set default expiration to zero, for undefined or missed exp in jwt
|
|
39
|
+
convertExpiration() {
|
|
40
|
+
let expiration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
41
|
+
// Converting expiration to seconds, if contains decimals or is identified as milliseconds
|
|
42
|
+
if (expiration.toString().length === 13) {
|
|
43
|
+
return Math.floor(expiration / 1000);
|
|
44
|
+
}
|
|
45
|
+
// If the epoch value is already in seconds, return it as is
|
|
46
|
+
return expiration;
|
|
47
|
+
}
|
|
48
|
+
isTokenExpired() {
|
|
49
|
+
// if expiration is 0, token is not going to be validated ( this is to cover the case of token with no expiration)
|
|
50
|
+
if (this.expiration === 0) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// obtain current time in seconds
|
|
55
|
+
const now = Math.floor(Date.now() / 1000);
|
|
56
|
+
|
|
57
|
+
// compare expiration time with current time
|
|
58
|
+
if (now > this.expiration) {
|
|
59
|
+
console.log("Token is expired", now, this.expiration, now > this.expiration);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
async setToken(token) {
|
|
65
|
+
// token must be not null, and must be new
|
|
66
|
+
if (!isNullOrEmptyString(token) && token !== this.token) {
|
|
67
|
+
var _this$token;
|
|
68
|
+
const instant = Math.floor(Date.now() / 1000);
|
|
69
|
+
this.token = token;
|
|
70
|
+
// decompose token
|
|
71
|
+
const tokenParts = (_this$token = this.token) === null || _this$token === void 0 ? void 0 : _this$token.split(".");
|
|
72
|
+
if (!tokenParts || tokenParts.length <= 1) {
|
|
73
|
+
TelemetryHelper.logFacadeChatSDKEvent(LogLevel.ERROR, {
|
|
74
|
+
Event: TelemetryEvent.NewTokenFailed,
|
|
75
|
+
Description: "Invalid token format",
|
|
76
|
+
ExceptionDetails: "Token must be in JWT format"
|
|
77
|
+
});
|
|
78
|
+
throw new Error("Invalid token format, must be in JWT format");
|
|
79
|
+
}
|
|
80
|
+
// decode token
|
|
81
|
+
const tokenDecoded = JSON.parse(atob(tokenParts[1]));
|
|
82
|
+
// calculate expiration time
|
|
83
|
+
this.expiration = this.convertExpiration(tokenDecoded.exp);
|
|
84
|
+
|
|
85
|
+
// this is a control , in case the getAuthToken function returns same token
|
|
86
|
+
if (this.expiration > 0 && this.expiration < instant) {
|
|
87
|
+
TelemetryHelper.logFacadeChatSDKEvent(LogLevel.ERROR, {
|
|
88
|
+
Event: TelemetryEvent.NewTokenExpired,
|
|
89
|
+
Description: "New token is already expired",
|
|
90
|
+
ExceptionDetails: {
|
|
91
|
+
"Instant": instant,
|
|
92
|
+
"Expiration": this.expiration
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
throw new Error("New token is already expired, with epoch time " + this.expiration);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async tokenRing() {
|
|
100
|
+
// this is needed for storybooks, specifically for reconnect pane which requires authentication bypass
|
|
101
|
+
if (this.sdkMocked === true) {
|
|
102
|
+
return {
|
|
103
|
+
result: true,
|
|
104
|
+
message: "Authentication not needed"
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (!this.isAuthenticated) {
|
|
108
|
+
return {
|
|
109
|
+
result: true,
|
|
110
|
+
message: "Authentication not needed"
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (this.isTokenSet() && !this.isTokenExpired()) {
|
|
114
|
+
return {
|
|
115
|
+
result: true,
|
|
116
|
+
message: "Token is valid"
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (this.getAuthToken === undefined) {
|
|
120
|
+
TelemetryHelper.logFacadeChatSDKEvent(LogLevel.ERROR, {
|
|
121
|
+
Event: TelemetryEvent.NewTokenFailed,
|
|
122
|
+
Description: "GetAuthToken function is not present",
|
|
123
|
+
ExceptionDetails: "Missing function : " + getAuthClientFunction(this.chatConfig)
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
result: false,
|
|
127
|
+
message: "GetAuthToken function is not present"
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// if token is not set, or token is already expired , then go to grab a token
|
|
132
|
+
this.token = "";
|
|
133
|
+
this.expiration = 0;
|
|
134
|
+
try {
|
|
135
|
+
const ring = await handleAuthentication(this.chatSDK, this.chatConfig, this.getAuthToken);
|
|
136
|
+
if (ring.result === true && ring.token) {
|
|
137
|
+
await this.setToken(ring.token);
|
|
138
|
+
TelemetryHelper.logFacadeChatSDKEvent(LogLevel.INFO, {
|
|
139
|
+
Event: TelemetryEvent.NewTokenSuccess,
|
|
140
|
+
Description: "New Token obtained",
|
|
141
|
+
Data: {
|
|
142
|
+
"Token_Expiration": this.expiration
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
result: true,
|
|
147
|
+
message: "New Token obtained"
|
|
148
|
+
};
|
|
149
|
+
} else {
|
|
150
|
+
var _ring$error, _ring$error2;
|
|
151
|
+
console.error("Failed to get token", ring);
|
|
152
|
+
TelemetryHelper.logFacadeChatSDKEvent(LogLevel.ERROR, {
|
|
153
|
+
Event: TelemetryEvent.NewTokenFailed,
|
|
154
|
+
Description: (_ring$error = ring.error) === null || _ring$error === void 0 ? void 0 : _ring$error.message,
|
|
155
|
+
ExceptionDetails: ring.error
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
result: false,
|
|
159
|
+
message: ((_ring$error2 = ring.error) === null || _ring$error2 === void 0 ? void 0 : _ring$error2.message) || "Failed to get token"
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
} catch (e) {
|
|
163
|
+
console.error("Unexpected error while getting token", e);
|
|
164
|
+
TelemetryHelper.logFacadeChatSDKEvent(LogLevel.ERROR, {
|
|
165
|
+
Event: TelemetryEvent.NewTokenFailed,
|
|
166
|
+
Description: "Unexpected error while getting token",
|
|
167
|
+
ExceptionDetails: e
|
|
168
|
+
});
|
|
169
|
+
return {
|
|
170
|
+
result: false,
|
|
171
|
+
message: "Unexpected error while getting token"
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async validateAndExecuteCall(functionName, fn) {
|
|
176
|
+
const pingResponse = await this.tokenRing();
|
|
177
|
+
if (pingResponse.result === true) {
|
|
178
|
+
return fn();
|
|
179
|
+
}
|
|
180
|
+
const executionErrorMessage = `Authentication failed: Process to get a token failed for ${functionName}, ${pingResponse.message}`;
|
|
181
|
+
//telemetry is already logged in tokenRing, so no need to log again, just return the error and communicate to the console
|
|
182
|
+
console.error(executionErrorMessage);
|
|
183
|
+
BroadcastService.postMessage({
|
|
184
|
+
eventName: BroadcastEvent.OnWidgetError,
|
|
185
|
+
payload: {
|
|
186
|
+
errorMessage: executionErrorMessage
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
throw new Error(executionErrorMessage);
|
|
190
|
+
}
|
|
191
|
+
async initialize() {
|
|
192
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
193
|
+
return this.validateAndExecuteCall("initialize", () => this.chatSDK.initialize(optionalParams));
|
|
194
|
+
}
|
|
195
|
+
async getChatReconnectContext() {
|
|
196
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
197
|
+
return this.validateAndExecuteCall("getChatReconnectContext", () => this.chatSDK.getChatReconnectContext(optionalParams));
|
|
198
|
+
}
|
|
199
|
+
async startChat() {
|
|
200
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
201
|
+
return this.validateAndExecuteCall("startChat", () => this.chatSDK.startChat(optionalParams));
|
|
202
|
+
}
|
|
203
|
+
async endChat() {
|
|
204
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
205
|
+
return this.validateAndExecuteCall("endChat", () => this.chatSDK.endChat(optionalParams));
|
|
206
|
+
}
|
|
207
|
+
async getCurrentLiveChatContext() {
|
|
208
|
+
return this.validateAndExecuteCall("getCurrentLiveChatContext", () => this.chatSDK.getCurrentLiveChatContext());
|
|
209
|
+
}
|
|
210
|
+
async getConversationDetails() {
|
|
211
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
212
|
+
return this.validateAndExecuteCall("getConversationDetails", () => this.chatSDK.getConversationDetails(optionalParams));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
216
|
+
async getPreChatSurvey() {
|
|
217
|
+
let parse = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
218
|
+
//prechat survey is obtained from config object, which is not required to be authenticated
|
|
219
|
+
// removing the tokenRing function from this call for backward compatibility
|
|
220
|
+
// TODO :: wrap this function around authentication
|
|
221
|
+
return this.chatSDK.getPreChatSurvey(parse);
|
|
222
|
+
}
|
|
223
|
+
async getLiveChatConfig(optionalParams) {
|
|
224
|
+
return this.validateAndExecuteCall("getLiveChatConfig", () => this.chatSDK.getLiveChatConfig(optionalParams));
|
|
225
|
+
}
|
|
226
|
+
async getChatToken() {
|
|
227
|
+
let cached = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
228
|
+
let optionalParams = arguments.length > 1 ? arguments[1] : undefined;
|
|
229
|
+
return this.validateAndExecuteCall("getChatToken", () => this.chatSDK.getChatToken(cached, optionalParams));
|
|
230
|
+
}
|
|
231
|
+
async getCallingToken() {
|
|
232
|
+
return this.validateAndExecuteCall("getCallingToken", () => this.chatSDK.getCallingToken());
|
|
233
|
+
}
|
|
234
|
+
async getMessages() {
|
|
235
|
+
return this.validateAndExecuteCall("getMessages", () => this.chatSDK.getMessages());
|
|
236
|
+
}
|
|
237
|
+
async getDataMaskingRules() {
|
|
238
|
+
return this.validateAndExecuteCall("getDataMaskingRules", () => this.chatSDK.getDataMaskingRules());
|
|
239
|
+
}
|
|
240
|
+
async sendMessage(message) {
|
|
241
|
+
return this.validateAndExecuteCall("sendMessage", () => this.chatSDK.sendMessage(message));
|
|
242
|
+
}
|
|
243
|
+
async onNewMessage(onNewMessageCallback) {
|
|
244
|
+
let optionalParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
245
|
+
return this.validateAndExecuteCall("onNewMessage", () => this.chatSDK.onNewMessage(onNewMessageCallback, optionalParams));
|
|
246
|
+
}
|
|
247
|
+
async sendTypingEvent() {
|
|
248
|
+
return this.validateAndExecuteCall("sendTypingEvent", () => this.chatSDK.sendTypingEvent());
|
|
249
|
+
}
|
|
250
|
+
async onTypingEvent(onTypingEventCallback) {
|
|
251
|
+
return this.validateAndExecuteCall("onTypingEvent", () => this.chatSDK.onTypingEvent(onTypingEventCallback));
|
|
252
|
+
}
|
|
253
|
+
async onAgentEndSession(onAgentEndSessionCallback) {
|
|
254
|
+
return this.validateAndExecuteCall("onAgentEndSession", () => this.chatSDK.onAgentEndSession(onAgentEndSessionCallback));
|
|
255
|
+
}
|
|
256
|
+
async uploadFileAttachment(fileInfo) {
|
|
257
|
+
return this.validateAndExecuteCall("uploadFileAttachment", () => this.chatSDK.uploadFileAttachment(fileInfo));
|
|
258
|
+
}
|
|
259
|
+
async downloadFileAttachment(fileMetadata) {
|
|
260
|
+
return this.validateAndExecuteCall("downloadFileAttachment", () => this.chatSDK.downloadFileAttachment(fileMetadata));
|
|
261
|
+
}
|
|
262
|
+
async emailLiveChatTranscript(body) {
|
|
263
|
+
let optionalParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
264
|
+
return this.validateAndExecuteCall("emailLiveChatTranscript", () => this.chatSDK.emailLiveChatTranscript(body, optionalParams));
|
|
265
|
+
}
|
|
266
|
+
async getLiveChatTranscript() {
|
|
267
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
268
|
+
return this.validateAndExecuteCall("getLiveChatTranscript", () => this.chatSDK.getLiveChatTranscript(optionalParams));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// response from origin is unknown, but this definition breaks create adapter for shimAdapter, switching to any until type is returned from origin
|
|
272
|
+
async createChatAdapter() {
|
|
273
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
274
|
+
return this.validateAndExecuteCall("createChatAdapter", () => this.chatSDK.createChatAdapter(optionalParams));
|
|
275
|
+
}
|
|
276
|
+
async isVoiceVideoCallingEnabled() {
|
|
277
|
+
this.tokenRing();
|
|
278
|
+
return this.chatSDK.isVoiceVideoCallingEnabled();
|
|
279
|
+
}
|
|
280
|
+
async getVoiceVideoCalling() {
|
|
281
|
+
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
282
|
+
return this.validateAndExecuteCall("getVoiceVideoCalling", () => this.chatSDK.getVoiceVideoCalling(params));
|
|
283
|
+
}
|
|
284
|
+
async getPostChatSurveyContext() {
|
|
285
|
+
return this.validateAndExecuteCall("getPostChatSurveyContext", () => this.chatSDK.getPostChatSurveyContext());
|
|
286
|
+
}
|
|
287
|
+
async getAgentAvailability() {
|
|
288
|
+
let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
289
|
+
return this.validateAndExecuteCall("getAgentAvailability", () => this.chatSDK.getAgentAvailability(optionalParams));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -182,6 +182,7 @@ export let TelemetryEvent;
|
|
|
182
182
|
TelemetryEvent["SendTypingIndicatorSucceeded"] = "SendTypingIndicatorSucceeded";
|
|
183
183
|
TelemetryEvent["SendTypingIndicatorFailed"] = "SendTypingIndicatorFailed";
|
|
184
184
|
TelemetryEvent["WebChatEvent"] = "WebChatEvent";
|
|
185
|
+
TelemetryEvent["FacadeChatSDKEvent"] = "FacadeChatSDKEvent";
|
|
185
186
|
TelemetryEvent["PreChatSurveyStartChatMethodFailed"] = "PreChatSurveyStartChatMethodFailed";
|
|
186
187
|
TelemetryEvent["ChatAlreadyTriggered"] = "ChatAlreadyTriggered";
|
|
187
188
|
TelemetryEvent["StartProactiveChatEventReceived"] = "StartProactiveChatEventReceived";
|
|
@@ -212,6 +213,10 @@ export let TelemetryEvent;
|
|
|
212
213
|
TelemetryEvent["ChatDisconnectThreadEventReceived"] = "ChatDisconnectThreadEventReceived";
|
|
213
214
|
TelemetryEvent["HiddenAdaptiveCardMessageReceived"] = "HiddenAdaptiveCardMessageReceived";
|
|
214
215
|
TelemetryEvent["EndingAdapterAfterDisconnectionError"] = "EndingAdapterAfterDisconnectionError";
|
|
216
|
+
TelemetryEvent["NewTokenSuccess"] = "NewTokenSuccess";
|
|
217
|
+
TelemetryEvent["NewTokenFailed"] = "NewTokenFailed";
|
|
218
|
+
TelemetryEvent["NewTokenExpired"] = "NewTokenExpired";
|
|
219
|
+
TelemetryEvent["TokenEmptyOrSame"] = "TokenEmptyOrSame";
|
|
215
220
|
})(TelemetryEvent || (TelemetryEvent = {}));
|
|
216
221
|
export class TelemetryConstants {
|
|
217
222
|
static map(eventTypeOrScenarioType) {
|
|
@@ -257,4 +257,14 @@ _defineProperty(TelemetryHelper, "logWebChatEvent", (logLevel, payload) => {
|
|
|
257
257
|
}
|
|
258
258
|
};
|
|
259
259
|
BroadcastService.postMessage(telemetryEvent);
|
|
260
|
+
});
|
|
261
|
+
_defineProperty(TelemetryHelper, "logFacadeChatSDKEvent", (logLevel, payload) => {
|
|
262
|
+
const telemetryEvent = {
|
|
263
|
+
eventName: (payload === null || payload === void 0 ? void 0 : payload.Event) ?? TelemetryEvent.FacadeChatSDKEvent,
|
|
264
|
+
logLevel: logLevel,
|
|
265
|
+
payload: {
|
|
266
|
+
...payload
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
BroadcastService.postMessage(telemetryEvent);
|
|
260
270
|
});
|
package/lib/esm/common/utils.js
CHANGED
|
@@ -357,7 +357,7 @@ export const isThisSessionPopout = href => {
|
|
|
357
357
|
return false;
|
|
358
358
|
};
|
|
359
359
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
360
|
-
export const getConversationDetailsCall = async function (
|
|
360
|
+
export const getConversationDetailsCall = async function (facadeChatSDK) {
|
|
361
361
|
let liveChatContext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
362
362
|
let conversationDetails = undefined; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
363
363
|
const optionalParams = {}; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
@@ -370,7 +370,7 @@ export const getConversationDetailsCall = async function (chatSDK) {
|
|
|
370
370
|
Event: TelemetryEvent.GetConversationDetailsCallStarted,
|
|
371
371
|
Description: "Conversation details call started"
|
|
372
372
|
});
|
|
373
|
-
conversationDetails = await
|
|
373
|
+
conversationDetails = await facadeChatSDK.getConversationDetails(optionalParams);
|
|
374
374
|
} catch (error) {
|
|
375
375
|
checkContactIdError(error);
|
|
376
376
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
@@ -4,15 +4,11 @@ import { CallingContainer } from "@microsoft/omnichannel-chat-components";
|
|
|
4
4
|
import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
|
|
5
5
|
import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
|
|
6
6
|
import useChatContextStore from "../../hooks/useChatContextStore";
|
|
7
|
-
import
|
|
7
|
+
import useFacadeSDKStore from "../../hooks/useFacadeChatSDKStore";
|
|
8
8
|
export const CallingContainerStateful = props => {
|
|
9
9
|
var _props$controlProps, _props$controlProps2, _props$controlProps2$, _props$controlProps3, _props$controlProps3$, _props$controlProps3$2, _props$controlProps4, _props$controlProps4$, _props$controlProps4$2, _props$controlProps5;
|
|
10
|
-
//TODO : Close button confirmation implmentation is pending
|
|
11
|
-
|
|
12
10
|
const [state, dispatch] = useChatContextStore();
|
|
13
|
-
|
|
14
|
-
const chatSDK = useChatSDKStore();
|
|
15
|
-
|
|
11
|
+
const [facadeChatSDK] = useFacadeSDKStore();
|
|
16
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
13
|
const {
|
|
18
14
|
voiceVideoCallingSdk
|
|
@@ -45,7 +41,7 @@ export const CallingContainerStateful = props => {
|
|
|
45
41
|
useEffect(() => {
|
|
46
42
|
const init = async () => {
|
|
47
43
|
try {
|
|
48
|
-
var _controlProps$current, _controlProps$current2, _controlProps$current3, _controlProps$current4;
|
|
44
|
+
var _controlProps$current, _controlProps$current2, _controlProps$current3, _controlProps$current4, _facadeChatSDK$getCha;
|
|
49
45
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
46
|
TelemetryHelper.callId = callId;
|
|
51
47
|
await voiceVideoCallingSdk.initialize({
|
|
@@ -54,7 +50,7 @@ export const CallingContainerStateful = props => {
|
|
|
54
50
|
// HTML element id where video stream of the agent will be rendered
|
|
55
51
|
remoteVideoHTMLElementId: (_controlProps$current3 = controlProps.currentCallControlProps) === null || _controlProps$current3 === void 0 ? void 0 : (_controlProps$current4 = _controlProps$current3.nonActionIds) === null || _controlProps$current4 === void 0 ? void 0 : _controlProps$current4.remoteVideoTileId,
|
|
56
52
|
// HTML element id where video stream of the customer will be rendered
|
|
57
|
-
OCClient:
|
|
53
|
+
OCClient: (_facadeChatSDK$getCha = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha === void 0 ? void 0 : _facadeChatSDK$getCha.OCClient
|
|
58
54
|
});
|
|
59
55
|
} catch (e) {
|
|
60
56
|
TelemetryHelper.logCallingEvent(LogLevel.ERROR, {
|
|
@@ -8,16 +8,15 @@ import { NotificationHandler } from "../webchatcontainerstateful/webchatcontroll
|
|
|
8
8
|
import { NotificationScenarios } from "../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
9
9
|
import { Regex } from "../../common/Constants";
|
|
10
10
|
import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
|
|
11
|
-
import useChatContextStore from "../../hooks/useChatContextStore";
|
|
12
|
-
import useChatSDKStore from "../../hooks/useChatSDKStore";
|
|
13
11
|
import { defaultMiddlewareLocalizedTexts } from "../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
|
|
12
|
+
import useChatContextStore from "../../hooks/useChatContextStore";
|
|
13
|
+
import useFacadeSDKStore from "../../hooks/useFacadeChatSDKStore";
|
|
14
14
|
export const EmailTranscriptPaneStateful = props => {
|
|
15
15
|
var _props$controlProps;
|
|
16
16
|
const initialTabIndexMap = new Map();
|
|
17
17
|
let elements = [];
|
|
18
18
|
const [state, dispatch] = useChatContextStore();
|
|
19
|
-
|
|
20
|
-
const chatSDK = useChatSDKStore();
|
|
19
|
+
const [facadeChatSDK] = useFacadeSDKStore();
|
|
21
20
|
const [initialEmail, setInitialEmail] = useState("");
|
|
22
21
|
const closeEmailTranscriptPane = () => {
|
|
23
22
|
dispatch({
|
|
@@ -45,7 +44,7 @@ export const EmailTranscriptPaneStateful = props => {
|
|
|
45
44
|
attachmentMessage: (props === null || props === void 0 ? void 0 : props.attachmentMessage) ?? "The following attachment was uploaded during the conversation:"
|
|
46
45
|
};
|
|
47
46
|
try {
|
|
48
|
-
await (
|
|
47
|
+
await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.emailLiveChatTranscript(chatTranscriptBody, {
|
|
49
48
|
liveChatContext
|
|
50
49
|
}));
|
|
51
50
|
NotificationHandler.notifySuccess(NotificationScenarios.EmailAddressSaved, defaultMiddlewareLocalizedTexts === null || defaultMiddlewareLocalizedTexts === void 0 ? void 0 : defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS);
|
|
@@ -63,7 +62,7 @@ export const EmailTranscriptPaneStateful = props => {
|
|
|
63
62
|
const message = formatTemplateString(defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR, [email]);
|
|
64
63
|
NotificationHandler.notifyError(NotificationScenarios.EmailTranscriptError, (props === null || props === void 0 ? void 0 : props.bannerMessageOnError) ?? message);
|
|
65
64
|
}
|
|
66
|
-
}, [props.attachmentMessage, props.bannerMessageOnError,
|
|
65
|
+
}, [props.attachmentMessage, props.bannerMessageOnError, facadeChatSDK, state.domainStates.liveChatContext]);
|
|
67
66
|
const controlProps = {
|
|
68
67
|
id: "oclcw-emailTranscriptDialogContainer",
|
|
69
68
|
dir: state.domainStates.globalDir,
|
|
@@ -2,6 +2,7 @@ import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConsta
|
|
|
2
2
|
import React, { useEffect } from "react";
|
|
3
3
|
import AudioNotificationStateful from "./audionotificationstateful/AudioNotificationStateful";
|
|
4
4
|
import { Constants } from "../../common/Constants";
|
|
5
|
+
import { ConversationState } from "../../contexts/common/ConversationState";
|
|
5
6
|
import { Footer } from "@microsoft/omnichannel-chat-components";
|
|
6
7
|
import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
|
|
7
8
|
import { NewMessageNotificationSoundBase64 } from "../../assets/Audios";
|
|
@@ -10,8 +11,7 @@ import { NotificationScenarios } from "../webchatcontainerstateful/webchatcontro
|
|
|
10
11
|
import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
|
|
11
12
|
import { downloadTranscript } from "./downloadtranscriptstateful/DownloadTranscriptStateful";
|
|
12
13
|
import useChatContextStore from "../../hooks/useChatContextStore";
|
|
13
|
-
import
|
|
14
|
-
import { ConversationState } from "../../contexts/common/ConversationState";
|
|
14
|
+
import useFacadeSDKStore from "../../hooks/useFacadeChatSDKStore";
|
|
15
15
|
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
17
|
export const FooterStateful = props => {
|
|
@@ -26,8 +26,7 @@ export const FooterStateful = props => {
|
|
|
26
26
|
audioNotificationProps,
|
|
27
27
|
hideFooterDisplay
|
|
28
28
|
} = props;
|
|
29
|
-
|
|
30
|
-
const chatSDK = useChatSDKStore();
|
|
29
|
+
const [facadeChatSDK] = useFacadeSDKStore();
|
|
31
30
|
const controlProps = {
|
|
32
31
|
id: "oc-lcw-footer",
|
|
33
32
|
dir: state.domainStates.globalDir,
|
|
@@ -37,7 +36,7 @@ export const FooterStateful = props => {
|
|
|
37
36
|
Event: TelemetryEvent.DownloadTranscriptButtonClicked,
|
|
38
37
|
Description: "Download Transcript button clicked."
|
|
39
38
|
});
|
|
40
|
-
await downloadTranscript(
|
|
39
|
+
await downloadTranscript(facadeChatSDK, downloadTranscriptProps, state);
|
|
41
40
|
} catch (ex) {
|
|
42
41
|
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
43
42
|
Event: TelemetryEvent.DownloadTranscriptFailed,
|
package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Constants, TranscriptConstants } from "../../../common/Constants";
|
|
2
|
-
import {
|
|
2
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
3
|
+
import { createFileAndDownload, isNullOrUndefined } from "../../../common/utils";
|
|
4
|
+
import DOMPurify from "dompurify";
|
|
5
|
+
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
3
6
|
import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
|
|
7
|
+
import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
4
8
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
5
|
-
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
6
9
|
import createChatTranscript from "../../../plugins/createChatTranscript";
|
|
7
|
-
import DOMPurify from "dompurify";
|
|
8
|
-
import { createFileAndDownload, isNullOrUndefined } from "../../../common/utils";
|
|
9
10
|
import { executeReducer } from "../../../contexts/createReducer";
|
|
10
|
-
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
11
11
|
const processDisplayName = displayName => {
|
|
12
12
|
// if displayname matches "teamsvisitor:<some alphanumeric string>", we replace it with "Customer"
|
|
13
13
|
const displayNameRegex = ".+:.+";
|
|
@@ -156,9 +156,7 @@ const beautifyChatTranscripts = (chatTranscripts, renderMarkDown, attachmentMess
|
|
|
156
156
|
const str = docTypeTag + docStartTag + docMetaTag + bodyStartTag + mainTranscriptSection + beautifiedChats + divEndTag + bodyEndTag + docEndTag;
|
|
157
157
|
return str;
|
|
158
158
|
};
|
|
159
|
-
|
|
160
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
161
|
-
export const downloadTranscript = async (chatSDK, downloadTranscriptProps, state) => {
|
|
159
|
+
export const downloadTranscript = async (facadeChatSDK, downloadTranscriptProps, state) => {
|
|
162
160
|
var _state$domainStates;
|
|
163
161
|
// Need to keep existing live chat context for scenarios when transcript is downloaded after endchat
|
|
164
162
|
let liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext;
|
|
@@ -169,7 +167,7 @@ export const downloadTranscript = async (chatSDK, downloadTranscriptProps, state
|
|
|
169
167
|
});
|
|
170
168
|
liveChatContext = inMemoryState.domainStates.liveChatContext;
|
|
171
169
|
}
|
|
172
|
-
let data = await (
|
|
170
|
+
let data = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getLiveChatTranscript({
|
|
173
171
|
liveChatContext
|
|
174
172
|
}));
|
|
175
173
|
if (typeof data === Constants.String) {
|
|
@@ -187,7 +185,7 @@ export const downloadTranscript = async (chatSDK, downloadTranscriptProps, state
|
|
|
187
185
|
const transcriptOptions = {
|
|
188
186
|
...webChatTranscript
|
|
189
187
|
};
|
|
190
|
-
await createChatTranscript(data[Constants.ChatMessagesJson],
|
|
188
|
+
await createChatTranscript(data[Constants.ChatMessagesJson], facadeChatSDK, false, transcriptOptions);
|
|
191
189
|
} else {
|
|
192
190
|
// Legacy Transcript
|
|
193
191
|
const chatTranscripts = window.btoa(encodeURIComponent(beautifyChatTranscripts(data[Constants.ChatMessagesJson], renderMarkDown, attachmentMessage)));
|
|
@@ -2,25 +2,48 @@ import React, { useReducer, useState } from "react";
|
|
|
2
2
|
import { ChatAdapterStore } from "../../contexts/ChatAdapterStore";
|
|
3
3
|
import { ChatContextStore } from "../../contexts/ChatContextStore";
|
|
4
4
|
import { ChatSDKStore } from "../../contexts/ChatSDKStore";
|
|
5
|
+
import { FacadeChatSDK } from "../../common/facades/FacadeChatSDK";
|
|
6
|
+
import { FacadeChatSDKStore } from "../../contexts/FacadeChatSDKStore";
|
|
5
7
|
import LiveChatWidgetStateful from "./livechatwidgetstateful/LiveChatWidgetStateful";
|
|
6
8
|
import { createReducer } from "../../contexts/createReducer";
|
|
7
9
|
import { getLiveChatWidgetContextInitialState } from "../../contexts/common/LiveChatWidgetContextInitialState";
|
|
8
10
|
import { getMockChatSDKIfApplicable } from "./common/getMockChatSDKIfApplicable";
|
|
11
|
+
import { isNullOrUndefined } from "../../common/utils";
|
|
9
12
|
import overridePropsOnMockIfApplicable from "./common/overridePropsOnMockIfApplicable";
|
|
10
13
|
export const LiveChatWidget = props => {
|
|
11
|
-
var _props$mock;
|
|
14
|
+
var _props$mock, _props$chatConfig, _props$chatConfig$Liv;
|
|
12
15
|
const reducer = createReducer();
|
|
13
16
|
const [state, dispatch] = useReducer(reducer, getLiveChatWidgetContextInitialState(props));
|
|
14
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
18
|
const [adapter, setAdapter] = useState(undefined);
|
|
19
|
+
const [facadeChatSDK, setFacadeChatSDK] = useState(undefined);
|
|
16
20
|
const chatSDK = getMockChatSDKIfApplicable(props.chatSDK, props === null || props === void 0 ? void 0 : (_props$mock = props.mock) === null || _props$mock === void 0 ? void 0 : _props$mock.type);
|
|
17
21
|
overridePropsOnMockIfApplicable(props);
|
|
18
|
-
|
|
22
|
+
if (!props.chatConfig) {
|
|
23
|
+
throw new Error("chatConfig is required");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
const isAuthenticatedChat = !!((_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);
|
|
28
|
+
if (!facadeChatSDK) {
|
|
29
|
+
var _props$mock2;
|
|
30
|
+
setFacadeChatSDK(new FacadeChatSDK({
|
|
31
|
+
"chatSDK": chatSDK,
|
|
32
|
+
"chatConfig": props.chatConfig,
|
|
33
|
+
"isAuthenticated": isAuthenticatedChat,
|
|
34
|
+
"getAuthToken": props === null || props === void 0 ? void 0 : props.getAuthToken,
|
|
35
|
+
//when type is not undefined, it means the SDK is mocked
|
|
36
|
+
"isSDKMocked": !isNullOrUndefined(props === null || props === void 0 ? void 0 : (_props$mock2 = props.mock) === null || _props$mock2 === void 0 ? void 0 : _props$mock2.type)
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
return /*#__PURE__*/React.createElement(FacadeChatSDKStore.Provider, {
|
|
40
|
+
value: [facadeChatSDK, setFacadeChatSDK]
|
|
41
|
+
}, /*#__PURE__*/React.createElement(ChatSDKStore.Provider, {
|
|
19
42
|
value: chatSDK
|
|
20
43
|
}, /*#__PURE__*/React.createElement(ChatAdapterStore.Provider, {
|
|
21
44
|
value: [adapter, setAdapter]
|
|
22
45
|
}, /*#__PURE__*/React.createElement(ChatContextStore.Provider, {
|
|
23
46
|
value: [state, dispatch]
|
|
24
|
-
}, /*#__PURE__*/React.createElement(LiveChatWidgetStateful, props))));
|
|
47
|
+
}, /*#__PURE__*/React.createElement(LiveChatWidgetStateful, props)))));
|
|
25
48
|
};
|
|
26
49
|
export default LiveChatWidget;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
2
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
3
|
-
import { isNullOrEmptyString } from "../../../common/utils";
|
|
4
3
|
import { WidgetLoadCustomErrorString } from "../../../common/Constants";
|
|
4
|
+
import { isNullOrEmptyString } from "../../../common/utils";
|
|
5
5
|
const getAuthClientFunction = chatConfig => {
|
|
6
6
|
let authClientFunction = undefined;
|
|
7
7
|
if (chatConfig !== null && chatConfig !== void 0 && chatConfig.LiveChatConfigAuthSettings) {
|
|
@@ -10,8 +10,6 @@ const getAuthClientFunction = chatConfig => {
|
|
|
10
10
|
}
|
|
11
11
|
return authClientFunction;
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
13
|
const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
|
|
16
14
|
const authClientFunction = getAuthClientFunction(chatConfig);
|
|
17
15
|
if (getAuthToken && authClientFunction) {
|
|
@@ -24,7 +22,10 @@ const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
|
|
|
24
22
|
chatSDK.setAuthTokenProvider(async () => {
|
|
25
23
|
return token;
|
|
26
24
|
});
|
|
27
|
-
return
|
|
25
|
+
return {
|
|
26
|
+
"result": true,
|
|
27
|
+
"token": token
|
|
28
|
+
};
|
|
28
29
|
} else {
|
|
29
30
|
// instead of returning false, it's more appropiate to thrown an error to force error handling on the caller side
|
|
30
31
|
// this will help to avoid the error to be ignored and the chat to be started
|
|
@@ -34,7 +35,15 @@ const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
|
|
|
34
35
|
throw new Error(WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
return
|
|
38
|
+
return {
|
|
39
|
+
"result": false,
|
|
40
|
+
"token": null,
|
|
41
|
+
"error": {
|
|
42
|
+
"message": "No auth client function or getAuthToken function provided",
|
|
43
|
+
"getAuthTokenPresent": getAuthToken ? true : false,
|
|
44
|
+
"authClientFunctionPresent": authClientFunction ? true : false
|
|
45
|
+
}
|
|
46
|
+
};
|
|
38
47
|
};
|
|
39
48
|
|
|
40
49
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
+
import { BotAuthActivitySubscriber } from "./ActivitySubscriber/BotAuthActivitySubscriber";
|
|
2
|
+
import { ChatAdapterShim } from "./ChatAdapterShim";
|
|
3
|
+
import { HiddenAdaptiveCardActivitySubscriber } from "./ActivitySubscriber/HiddenAdaptiveCardActivitySubscriber";
|
|
4
|
+
import { MockChatSDK } from "../../webchatcontainerstateful/common/mockchatsdk";
|
|
1
5
|
import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
|
|
2
6
|
import { NotificationLevel } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationLevel";
|
|
3
7
|
import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
4
|
-
import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
|
|
5
|
-
import { ChatAdapterShim } from "./ChatAdapterShim";
|
|
6
8
|
import { PauseActivitySubscriber } from "./ActivitySubscriber/PauseActivitySubscriber";
|
|
7
|
-
import {
|
|
8
|
-
import { HiddenAdaptiveCardActivitySubscriber } from "./ActivitySubscriber/HiddenAdaptiveCardActivitySubscriber";
|
|
9
|
+
import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
|
|
9
10
|
const defaultBotAuthConfig = {
|
|
10
11
|
fetchBotAuthConfigRetries: 3,
|
|
11
12
|
fetchBotAuthConfigRetryInterval: 1000
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
export const createAdapter = async (chatSDK, props) => {
|
|
14
|
+
export const createAdapter = async (facadeChatSDK, props) => {
|
|
16
15
|
const chatAdapterOptionalParams = {
|
|
17
16
|
IC3Adapter: {
|
|
18
17
|
options: {
|
|
@@ -35,9 +34,10 @@ export const createAdapter = async (chatSDK, props) => {
|
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
|
-
let adapter = await
|
|
37
|
+
let adapter = await facadeChatSDK.createChatAdapter(chatAdapterOptionalParams);
|
|
39
38
|
//so far, there is no need to convert to the shim adapter when using visual tests
|
|
40
|
-
|
|
39
|
+
const isMocked = facadeChatSDK.getChatSDK() instanceof MockChatSDK;
|
|
40
|
+
if (isMocked !== true) {
|
|
41
41
|
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4;
|
|
42
42
|
const botAuthActivitySubscriberOptionalParams = {
|
|
43
43
|
fetchBotAuthConfigRetries: (props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.botAuthConfig) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.fetchBotAuthConfigRetries) || defaultBotAuthConfig.fetchBotAuthConfigRetries,
|