Merge pull request #19 from xTEddie/unauth-chat-reconnect

Unauth chat reconnect
This commit is contained in:
xTEddie 2022-02-28 12:42:15 -08:00 коммит произвёл GitHub
Родитель 102d391711 1bf1251ea1
Коммит 5b3e91e2c6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 51 добавлений и 5 удалений

Просмотреть файл

@ -26,6 +26,7 @@ The sample app includes the following scenarios:
- [X] Avatar middleware - [X] Avatar middleware
- [X] Activity status middleware - [X] Activity status middleware
- [X] Escalation to Voice & Video - [X] Escalation to Voice & Video
- [X] Unauthenticated Chat Reconnect
## Prerequisites ## Prerequisites
- [React](https://reactjs.org/) - [React](https://reactjs.org/)

Просмотреть файл

@ -22,6 +22,7 @@ import fetchOmnichannelConfig from '../../utils/fetchOmnichannelConfig';
import fetchTelemetryConfig from '../../utils/fetchTelemetryConfig'; import fetchTelemetryConfig from '../../utils/fetchTelemetryConfig';
import fetchCallingConfig from '../../utils/fetchCallingConfig'; import fetchCallingConfig from '../../utils/fetchCallingConfig';
import fetchDebugConfig from '../../utils/fetchDebugConfig'; import fetchDebugConfig from '../../utils/fetchDebugConfig';
import fetchChatReconnectConfig from '../../utils/fetchChatReconnectConfig';
import transformLiveChatConfig, { ConfigurationManager } from '../../utils/transformLiveChatConfig'; import transformLiveChatConfig, { ConfigurationManager } from '../../utils/transformLiveChatConfig';
import './WebChat.css'; import './WebChat.css';
@ -29,6 +30,7 @@ const omnichannelConfig: any = fetchOmnichannelConfig();
const telemetryConfig: any = fetchTelemetryConfig(); const telemetryConfig: any = fetchTelemetryConfig();
const callingConfig: any = fetchCallingConfig(); const callingConfig: any = fetchCallingConfig();
const debugConfig: any = fetchDebugConfig(); const debugConfig: any = fetchDebugConfig();
const chatReconnectConfig: any = fetchChatReconnectConfig();
console.log(`%c [OmnichannelConfig]`, 'background-color:#001433;color:#fff'); console.log(`%c [OmnichannelConfig]`, 'background-color:#001433;color:#fff');
console.log(omnichannelConfig); console.log(omnichannelConfig);
@ -78,9 +80,14 @@ function WebChat() {
useEffect(() => { useEffect(() => {
const init = async () => { const init = async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig, { const chatSDKConfig = {
...telemetryConfig ...telemetryConfig,
}); chatReconnect: {
disable: false
}
};
const chatSDK = new OmnichannelChatSDK(omnichannelConfig, chatSDKConfig);
chatSDK.setDebug(!debugConfig.disable); chatSDK.setDebug(!debugConfig.disable);
@ -169,8 +176,24 @@ function WebChat() {
dispatch({type: ActionType.SET_CHAT_STARTED, payload: true}); 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 // 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}); dispatch({type: ActionType.SET_LOADING, payload: true});
try { 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 { export class ConfigurationManager {
public static liveChatVersion: number = 1; public static liveChatVersion: number = 1;
public static canUploadAttachment: boolean = false; public static canUploadAttachment: boolean = false;
public static isPersistentChat: boolean = false;
public static isChatReconnect: boolean = false;
} }
const transformLiveChatConfig = (liveChatConfig: any): ConfigurationManager => { const transformLiveChatConfig = (liveChatConfig: any): ConfigurationManager => {
const liveWSAndLiveChatEngJoin = (liveChatConfig as any)["LiveWSAndLiveChatEngJoin"];
const liveChatVersion = (liveChatConfig as any)["LiveChatVersion"]; 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.liveChatVersion = parseInt(liveChatVersion) || 1;
ConfigurationManager.canUploadAttachment = canUploadAttachment; ConfigurationManager.canUploadAttachment = canUploadAttachment;
ConfigurationManager.isPersistentChat = isPersistentChat;
ConfigurationManager.isChatReconnect = isChatReconnect;
return ConfigurationManager; return ConfigurationManager;
}; };