Merge pull request #19 from xTEddie/unauth-chat-reconnect
Unauth chat reconnect
This commit is contained in:
Коммит
5b3e91e2c6
|
@ -26,6 +26,7 @@ The sample app includes the following scenarios:
|
|||
- [X] Avatar middleware
|
||||
- [X] Activity status middleware
|
||||
- [X] Escalation to Voice & Video
|
||||
- [X] Unauthenticated Chat Reconnect
|
||||
|
||||
## Prerequisites
|
||||
- [React](https://reactjs.org/)
|
||||
|
|
|
@ -22,6 +22,7 @@ import fetchOmnichannelConfig from '../../utils/fetchOmnichannelConfig';
|
|||
import fetchTelemetryConfig from '../../utils/fetchTelemetryConfig';
|
||||
import fetchCallingConfig from '../../utils/fetchCallingConfig';
|
||||
import fetchDebugConfig from '../../utils/fetchDebugConfig';
|
||||
import fetchChatReconnectConfig from '../../utils/fetchChatReconnectConfig';
|
||||
import transformLiveChatConfig, { ConfigurationManager } from '../../utils/transformLiveChatConfig';
|
||||
import './WebChat.css';
|
||||
|
||||
|
@ -29,6 +30,7 @@ const omnichannelConfig: any = fetchOmnichannelConfig();
|
|||
const telemetryConfig: any = fetchTelemetryConfig();
|
||||
const callingConfig: any = fetchCallingConfig();
|
||||
const debugConfig: any = fetchDebugConfig();
|
||||
const chatReconnectConfig: any = fetchChatReconnectConfig();
|
||||
|
||||
console.log(`%c [OmnichannelConfig]`, 'background-color:#001433;color:#fff');
|
||||
console.log(omnichannelConfig);
|
||||
|
@ -78,9 +80,14 @@ function WebChat() {
|
|||
|
||||
useEffect(() => {
|
||||
const init = async () => {
|
||||
const chatSDK = new OmnichannelChatSDK(omnichannelConfig, {
|
||||
...telemetryConfig
|
||||
});
|
||||
const chatSDKConfig = {
|
||||
...telemetryConfig,
|
||||
chatReconnect: {
|
||||
disable: false
|
||||
}
|
||||
};
|
||||
|
||||
const chatSDK = new OmnichannelChatSDK(omnichannelConfig, chatSDKConfig);
|
||||
|
||||
chatSDK.setDebug(!debugConfig.disable);
|
||||
|
||||
|
@ -169,8 +176,24 @@ function WebChat() {
|
|||
|
||||
dispatch({type: ActionType.SET_CHAT_STARTED, payload: true});
|
||||
|
||||
if (ConfigurationManager.isChatReconnect && chatReconnectConfig.reconnectId) {
|
||||
// Validate reconnect id if any
|
||||
const chatReconnectContext = await chatSDK?.getChatReconnectContext({
|
||||
reconnectId: chatReconnectConfig.reconnectId
|
||||
});
|
||||
|
||||
// Redirect URL if any
|
||||
if (chatReconnectContext?.redirectURL) {
|
||||
window.location.replace(chatReconnectContext?.redirectURL);
|
||||
}
|
||||
|
||||
if (chatReconnectContext?.reconnectId) {
|
||||
optionalParams.reconnectId = chatReconnectContext?.reconnectId;
|
||||
}
|
||||
}
|
||||
|
||||
// Start chats only if there's an existing live chat context or no PreChat
|
||||
if (liveChatContext || !preChatSurvey) {
|
||||
if (liveChatContext || !preChatSurvey || chatReconnectConfig.reconnectId) {
|
||||
dispatch({type: ActionType.SET_LOADING, payload: true});
|
||||
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
const fetchChatReconnectConfig = () => {
|
||||
const chatReconnectConfig: any = {
|
||||
reconnectId: null
|
||||
}
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
if (urlParams.get('oc.reconnectid') !== null) {
|
||||
chatReconnectConfig.reconnectId = urlParams.get('oc.reconnectid') || null;
|
||||
}
|
||||
|
||||
return chatReconnectConfig;
|
||||
}
|
||||
|
||||
export default fetchChatReconnectConfig;
|
|
@ -1,14 +1,22 @@
|
|||
export class ConfigurationManager {
|
||||
public static liveChatVersion: number = 1;
|
||||
public static canUploadAttachment: boolean = false;
|
||||
public static isPersistentChat: boolean = false;
|
||||
public static isChatReconnect: boolean = false;
|
||||
}
|
||||
|
||||
const transformLiveChatConfig = (liveChatConfig: any): ConfigurationManager => {
|
||||
const liveWSAndLiveChatEngJoin = (liveChatConfig as any)["LiveWSAndLiveChatEngJoin"];
|
||||
|
||||
const liveChatVersion = (liveChatConfig as any)["LiveChatVersion"];
|
||||
const canUploadAttachment = (liveChatConfig as any)["LiveWSAndLiveChatEngJoin"]["msdyn_enablefileattachmentsforcustomers"] === "true" || false;
|
||||
const canUploadAttachment = liveWSAndLiveChatEngJoin["msdyn_enablefileattachmentsforcustomers"] === "true" || false;
|
||||
const isPersistentChat = liveWSAndLiveChatEngJoin["msdyn_conversationmode"] === "192350001" || false;
|
||||
const isChatReconnect = (liveWSAndLiveChatEngJoin["msdyn_conversationmode"] === "192350000" && liveWSAndLiveChatEngJoin["msdyn_enablechatreconnect"] === "true") || false
|
||||
|
||||
ConfigurationManager.liveChatVersion = parseInt(liveChatVersion) || 1;
|
||||
ConfigurationManager.canUploadAttachment = canUploadAttachment;
|
||||
ConfigurationManager.isPersistentChat = isPersistentChat;
|
||||
ConfigurationManager.isChatReconnect = isChatReconnect;
|
||||
|
||||
return ConfigurationManager;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче