@microsoft/omnichannel-chat-widget 1.3.0 → 1.3.1-main.57e27d3
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/components/livechatwidget/common/endChat.js +53 -4
- package/lib/cjs/components/livechatwidget/common/startChat.js +1 -1
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +23 -3
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +3 -0
- package/lib/esm/components/livechatwidget/common/endChat.js +51 -3
- package/lib/esm/components/livechatwidget/common/startChat.js +1 -1
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +23 -3
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +3 -0
- package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.prepareEndChat = exports.endChat = void 0;
|
|
6
|
+
exports.prepareEndChat = exports.endVoiceVideoCallIfOngoing = exports.endChat = void 0;
|
|
7
7
|
var _Constants = require("../../../common/Constants");
|
|
8
8
|
var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
|
|
9
9
|
var _authHelper = require("./authHelper");
|
|
@@ -19,20 +19,22 @@ var _defaultWebChatContainerStatefulProps = require("../../webchatcontainerstate
|
|
|
19
19
|
const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid) => {
|
|
20
20
|
try {
|
|
21
21
|
var _conversationDetails$, _state$domainStates, _state$domainStates2;
|
|
22
|
+
// Use Case: If call is ongoing, end the call by simulating end call button click
|
|
23
|
+
endVoiceVideoCallIfOngoing(chatSDK, dispatch);
|
|
22
24
|
const conversationDetails = await (0, _utils.getConversationDetailsCall)(chatSDK);
|
|
23
25
|
|
|
24
|
-
// Use Case
|
|
26
|
+
// Use Case: When post chat is not configured
|
|
25
27
|
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : (_conversationDetails$ = conversationDetails.canRenderPostChat) === null || _conversationDetails$ === void 0 ? void 0 : _conversationDetails$.toLowerCase()) === _Constants.Constants.false) {
|
|
26
28
|
var _state$appStates;
|
|
27
29
|
// If ended by customer, just close chat
|
|
28
30
|
if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.conversationEndedBy) === _Constants.ConversationEndEntity.Customer) {
|
|
29
31
|
await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
|
|
30
32
|
}
|
|
31
|
-
//Use Case: If ended by Agent, stay chat in InActive state
|
|
33
|
+
// Use Case: If ended by Agent, stay chat in InActive state
|
|
32
34
|
return;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
// Use Case
|
|
37
|
+
// Use Case: Can render post chat scenarios
|
|
36
38
|
await (0, _renderSurveyHelpers.getPostChatContext)(chatSDK, state, dispatch);
|
|
37
39
|
|
|
38
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -142,6 +144,28 @@ const endChat = async function (props, chatSDK, state, dispatch, setAdapter, set
|
|
|
142
144
|
}
|
|
143
145
|
};
|
|
144
146
|
exports.endChat = endChat;
|
|
147
|
+
const callingStateCleanUp = async dispatch => {
|
|
148
|
+
dispatch({
|
|
149
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SHOW_CALLING_CONTAINER,
|
|
150
|
+
payload: false
|
|
151
|
+
});
|
|
152
|
+
dispatch({
|
|
153
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_INCOMING_CALL,
|
|
154
|
+
payload: true
|
|
155
|
+
});
|
|
156
|
+
dispatch({
|
|
157
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.DISABLE_VIDEO_CALL,
|
|
158
|
+
payload: true
|
|
159
|
+
});
|
|
160
|
+
dispatch({
|
|
161
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.DISABLE_LOCAL_VIDEO,
|
|
162
|
+
payload: true
|
|
163
|
+
});
|
|
164
|
+
dispatch({
|
|
165
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.DISABLE_REMOTE_VIDEO,
|
|
166
|
+
payload: true
|
|
167
|
+
});
|
|
168
|
+
};
|
|
145
169
|
const endChatStateCleanUp = async dispatch => {
|
|
146
170
|
// Need to clear these states immediately when chat ended from OC.
|
|
147
171
|
dispatch({
|
|
@@ -192,6 +216,31 @@ const closeChatStateCleanUp = async dispatch => {
|
|
|
192
216
|
}
|
|
193
217
|
});
|
|
194
218
|
};
|
|
219
|
+
|
|
220
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
221
|
+
const endVoiceVideoCallIfOngoing = async (chatSDK, dispatch) => {
|
|
222
|
+
let callId = "";
|
|
223
|
+
try {
|
|
224
|
+
const voiceVideoCallingSdk = await chatSDK.getVoiceVideoCalling();
|
|
225
|
+
if (voiceVideoCallingSdk && voiceVideoCallingSdk.isInACall()) {
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
227
|
+
callId = voiceVideoCallingSdk.callId;
|
|
228
|
+
voiceVideoCallingSdk.stopCall();
|
|
229
|
+
_TelemetryHelper.TelemetryHelper.logCallingEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
230
|
+
Event: _TelemetryConstants.TelemetryEvent.EndCallButtonClick
|
|
231
|
+
}, callId);
|
|
232
|
+
callingStateCleanUp(dispatch);
|
|
233
|
+
}
|
|
234
|
+
} catch (error) {
|
|
235
|
+
_TelemetryHelper.TelemetryHelper.logCallingEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
236
|
+
Event: _TelemetryConstants.TelemetryEvent.EndCallButtonClickException,
|
|
237
|
+
ExceptionDetails: {
|
|
238
|
+
exception: `Failed to End Call: ${error}`
|
|
239
|
+
}
|
|
240
|
+
}, callId);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
exports.endVoiceVideoCallIfOngoing = endVoiceVideoCallIfOngoing;
|
|
195
244
|
const closeChatWidget = (dispatch, props, state) => {
|
|
196
245
|
var _state$appStates3;
|
|
197
246
|
if (state !== null && state !== void 0 && (_state$appStates3 = state.appStates) !== null && _state$appStates3 !== void 0 && _state$appStates3.hideStartChatButton) {
|
|
@@ -55,7 +55,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
55
55
|
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
|
|
56
56
|
|
|
57
57
|
//Setting PreChat and intiate chat
|
|
58
|
-
await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat,
|
|
58
|
+
await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -326,7 +326,27 @@ const LiveChatWidgetStateful = props => {
|
|
|
326
326
|
});
|
|
327
327
|
|
|
328
328
|
// Start chat from SDK Event
|
|
329
|
-
_omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartChat).subscribe(
|
|
329
|
+
_omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartChat).subscribe(msg => {
|
|
330
|
+
var _msg$payload4;
|
|
331
|
+
let stateWithUpdatedContext = state;
|
|
332
|
+
if (msg !== null && msg !== void 0 && (_msg$payload4 = msg.payload) !== null && _msg$payload4 !== void 0 && _msg$payload4.customContext) {
|
|
333
|
+
var _msg$payload5, _msg$payload6;
|
|
334
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
335
|
+
Event: _TelemetryConstants.TelemetryEvent.CustomContextReceived,
|
|
336
|
+
Description: "CustomContext received through startChat event."
|
|
337
|
+
});
|
|
338
|
+
dispatch({
|
|
339
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
|
|
340
|
+
payload: msg === null || msg === void 0 ? void 0 : (_msg$payload5 = msg.payload) === null || _msg$payload5 === void 0 ? void 0 : _msg$payload5.customContext
|
|
341
|
+
});
|
|
342
|
+
stateWithUpdatedContext = {
|
|
343
|
+
...state,
|
|
344
|
+
domainStates: {
|
|
345
|
+
...state.domainStates,
|
|
346
|
+
customContext: msg === null || msg === void 0 ? void 0 : (_msg$payload6 = msg.payload) === null || _msg$payload6 === void 0 ? void 0 : _msg$payload6.customContext
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
330
350
|
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
331
351
|
Event: _TelemetryConstants.TelemetryEvent.StartChatEventRecevied,
|
|
332
352
|
Description: "Start chat event received."
|
|
@@ -340,7 +360,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
340
360
|
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
341
361
|
eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
|
|
342
362
|
});
|
|
343
|
-
(0, _startChat.prepareStartChat)(props, chatSDK,
|
|
363
|
+
(0, _startChat.prepareStartChat)(props, chatSDK, stateWithUpdatedContext, dispatch, setAdapter);
|
|
344
364
|
return;
|
|
345
365
|
}
|
|
346
366
|
|
|
@@ -352,7 +372,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
352
372
|
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
353
373
|
eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
|
|
354
374
|
});
|
|
355
|
-
(0, _startChat.prepareStartChat)(props, chatSDK,
|
|
375
|
+
(0, _startChat.prepareStartChat)(props, chatSDK, stateWithUpdatedContext, dispatch, setAdapter);
|
|
356
376
|
return;
|
|
357
377
|
}
|
|
358
378
|
|
|
@@ -14,20 +14,22 @@ import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstat
|
|
|
14
14
|
const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid) => {
|
|
15
15
|
try {
|
|
16
16
|
var _conversationDetails$, _state$domainStates, _state$domainStates2;
|
|
17
|
+
// Use Case: If call is ongoing, end the call by simulating end call button click
|
|
18
|
+
endVoiceVideoCallIfOngoing(chatSDK, dispatch);
|
|
17
19
|
const conversationDetails = await getConversationDetailsCall(chatSDK);
|
|
18
20
|
|
|
19
|
-
// Use Case
|
|
21
|
+
// Use Case: When post chat is not configured
|
|
20
22
|
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : (_conversationDetails$ = conversationDetails.canRenderPostChat) === null || _conversationDetails$ === void 0 ? void 0 : _conversationDetails$.toLowerCase()) === Constants.false) {
|
|
21
23
|
var _state$appStates;
|
|
22
24
|
// If ended by customer, just close chat
|
|
23
25
|
if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.conversationEndedBy) === ConversationEndEntity.Customer) {
|
|
24
26
|
await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
|
|
25
27
|
}
|
|
26
|
-
//Use Case: If ended by Agent, stay chat in InActive state
|
|
28
|
+
// Use Case: If ended by Agent, stay chat in InActive state
|
|
27
29
|
return;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
// Use Case
|
|
32
|
+
// Use Case: Can render post chat scenarios
|
|
31
33
|
await getPostChatContext(chatSDK, state, dispatch);
|
|
32
34
|
|
|
33
35
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -135,6 +137,28 @@ const endChat = async function (props, chatSDK, state, dispatch, setAdapter, set
|
|
|
135
137
|
});
|
|
136
138
|
}
|
|
137
139
|
};
|
|
140
|
+
const callingStateCleanUp = async dispatch => {
|
|
141
|
+
dispatch({
|
|
142
|
+
type: LiveChatWidgetActionType.SHOW_CALLING_CONTAINER,
|
|
143
|
+
payload: false
|
|
144
|
+
});
|
|
145
|
+
dispatch({
|
|
146
|
+
type: LiveChatWidgetActionType.SET_INCOMING_CALL,
|
|
147
|
+
payload: true
|
|
148
|
+
});
|
|
149
|
+
dispatch({
|
|
150
|
+
type: LiveChatWidgetActionType.DISABLE_VIDEO_CALL,
|
|
151
|
+
payload: true
|
|
152
|
+
});
|
|
153
|
+
dispatch({
|
|
154
|
+
type: LiveChatWidgetActionType.DISABLE_LOCAL_VIDEO,
|
|
155
|
+
payload: true
|
|
156
|
+
});
|
|
157
|
+
dispatch({
|
|
158
|
+
type: LiveChatWidgetActionType.DISABLE_REMOTE_VIDEO,
|
|
159
|
+
payload: true
|
|
160
|
+
});
|
|
161
|
+
};
|
|
138
162
|
const endChatStateCleanUp = async dispatch => {
|
|
139
163
|
// Need to clear these states immediately when chat ended from OC.
|
|
140
164
|
dispatch({
|
|
@@ -185,6 +209,30 @@ const closeChatStateCleanUp = async dispatch => {
|
|
|
185
209
|
}
|
|
186
210
|
});
|
|
187
211
|
};
|
|
212
|
+
|
|
213
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
214
|
+
export const endVoiceVideoCallIfOngoing = async (chatSDK, dispatch) => {
|
|
215
|
+
let callId = "";
|
|
216
|
+
try {
|
|
217
|
+
const voiceVideoCallingSdk = await chatSDK.getVoiceVideoCalling();
|
|
218
|
+
if (voiceVideoCallingSdk && voiceVideoCallingSdk.isInACall()) {
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
220
|
+
callId = voiceVideoCallingSdk.callId;
|
|
221
|
+
voiceVideoCallingSdk.stopCall();
|
|
222
|
+
TelemetryHelper.logCallingEvent(LogLevel.INFO, {
|
|
223
|
+
Event: TelemetryEvent.EndCallButtonClick
|
|
224
|
+
}, callId);
|
|
225
|
+
callingStateCleanUp(dispatch);
|
|
226
|
+
}
|
|
227
|
+
} catch (error) {
|
|
228
|
+
TelemetryHelper.logCallingEvent(LogLevel.ERROR, {
|
|
229
|
+
Event: TelemetryEvent.EndCallButtonClickException,
|
|
230
|
+
ExceptionDetails: {
|
|
231
|
+
exception: `Failed to End Call: ${error}`
|
|
232
|
+
}
|
|
233
|
+
}, callId);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
188
236
|
const closeChatWidget = (dispatch, props, state) => {
|
|
189
237
|
var _state$appStates3;
|
|
190
238
|
if (state !== null && state !== void 0 && (_state$appStates3 = state.appStates) !== null && _state$appStates3 !== void 0 && _state$appStates3.hideStartChatButton) {
|
|
@@ -50,7 +50,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
50
50
|
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
|
|
51
51
|
|
|
52
52
|
//Setting PreChat and intiate chat
|
|
53
|
-
await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat,
|
|
53
|
+
await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -318,7 +318,27 @@ export const LiveChatWidgetStateful = props => {
|
|
|
318
318
|
});
|
|
319
319
|
|
|
320
320
|
// Start chat from SDK Event
|
|
321
|
-
BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(
|
|
321
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(msg => {
|
|
322
|
+
var _msg$payload4;
|
|
323
|
+
let stateWithUpdatedContext = state;
|
|
324
|
+
if (msg !== null && msg !== void 0 && (_msg$payload4 = msg.payload) !== null && _msg$payload4 !== void 0 && _msg$payload4.customContext) {
|
|
325
|
+
var _msg$payload5, _msg$payload6;
|
|
326
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
327
|
+
Event: TelemetryEvent.CustomContextReceived,
|
|
328
|
+
Description: "CustomContext received through startChat event."
|
|
329
|
+
});
|
|
330
|
+
dispatch({
|
|
331
|
+
type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
|
|
332
|
+
payload: msg === null || msg === void 0 ? void 0 : (_msg$payload5 = msg.payload) === null || _msg$payload5 === void 0 ? void 0 : _msg$payload5.customContext
|
|
333
|
+
});
|
|
334
|
+
stateWithUpdatedContext = {
|
|
335
|
+
...state,
|
|
336
|
+
domainStates: {
|
|
337
|
+
...state.domainStates,
|
|
338
|
+
customContext: msg === null || msg === void 0 ? void 0 : (_msg$payload6 = msg.payload) === null || _msg$payload6 === void 0 ? void 0 : _msg$payload6.customContext
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
322
342
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
323
343
|
Event: TelemetryEvent.StartChatEventRecevied,
|
|
324
344
|
Description: "Start chat event received."
|
|
@@ -332,7 +352,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
332
352
|
BroadcastService.postMessage({
|
|
333
353
|
eventName: BroadcastEvent.ChatInitiated
|
|
334
354
|
});
|
|
335
|
-
prepareStartChat(props, chatSDK,
|
|
355
|
+
prepareStartChat(props, chatSDK, stateWithUpdatedContext, dispatch, setAdapter);
|
|
336
356
|
return;
|
|
337
357
|
}
|
|
338
358
|
|
|
@@ -344,7 +364,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
344
364
|
BroadcastService.postMessage({
|
|
345
365
|
eventName: BroadcastEvent.ChatInitiated
|
|
346
366
|
});
|
|
347
|
-
prepareStartChat(props, chatSDK,
|
|
367
|
+
prepareStartChat(props, chatSDK, stateWithUpdatedContext, dispatch, setAdapter);
|
|
348
368
|
return;
|
|
349
369
|
}
|
|
350
370
|
|
|
@@ -4,4 +4,5 @@ import { ILiveChatWidgetContext } from "../../../contexts/common/ILiveChatWidget
|
|
|
4
4
|
import { ILiveChatWidgetProps } from "../interfaces/ILiveChatWidgetProps";
|
|
5
5
|
declare const prepareEndChat: (props: ILiveChatWidgetProps, chatSDK: any, state: ILiveChatWidgetContext, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, setWebChatStyles: any, adapter: any, uwid: string) => Promise<void>;
|
|
6
6
|
declare const endChat: (props: ILiveChatWidgetProps, chatSDK: any, state: ILiveChatWidgetContext, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, setWebChatStyles: any, adapter: any, skipEndChatSDK?: boolean | undefined, skipCloseChat?: boolean | undefined, postMessageToOtherTab?: boolean | undefined, uwid?: string) => Promise<void>;
|
|
7
|
+
export declare const endVoiceVideoCallIfOngoing: (chatSDK: any, dispatch: Dispatch<ILiveChatWidgetAction>) => Promise<void>;
|
|
7
8
|
export { prepareEndChat, endChat };
|