From f7e13e3e0ac6ac0a038c8f337888a322ad80ae5d Mon Sep 17 00:00:00 2001 From: Edward Tran Date: Mon, 28 Feb 2022 12:09:49 -0800 Subject: [PATCH 1/5] Add configuration flag for persistent chat --- .../src/utils/transformLiveChatConfig.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/botframework-webchat-control/src/utils/transformLiveChatConfig.ts b/botframework-webchat-control/src/utils/transformLiveChatConfig.ts index 8b7ae4f..8f35757 100644 --- a/botframework-webchat-control/src/utils/transformLiveChatConfig.ts +++ b/botframework-webchat-control/src/utils/transformLiveChatConfig.ts @@ -1,14 +1,17 @@ export class ConfigurationManager { public static liveChatVersion: number = 1; public static canUploadAttachment: boolean = false; + public static isPersistentChat: boolean = false; } const transformLiveChatConfig = (liveChatConfig: any): ConfigurationManager => { const liveChatVersion = (liveChatConfig as any)["LiveChatVersion"]; const canUploadAttachment = (liveChatConfig as any)["LiveWSAndLiveChatEngJoin"]["msdyn_enablefileattachmentsforcustomers"] === "true" || false; + const isPersistentChat = (liveChatConfig as any)["LiveWSAndLiveChatEngJoin"]["msdyn_conversationmode"] === "192350001" || false; ConfigurationManager.liveChatVersion = parseInt(liveChatVersion) || 1; ConfigurationManager.canUploadAttachment = canUploadAttachment; + ConfigurationManager.isPersistentChat = isPersistentChat; return ConfigurationManager; }; From dda43fe205feec7f9f3d03c6f6aba5a9577124dd Mon Sep 17 00:00:00 2001 From: Edward Tran Date: Mon, 28 Feb 2022 12:17:52 -0800 Subject: [PATCH 2/5] Add configuration flag for chat reconnect --- .../src/utils/transformLiveChatConfig.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/botframework-webchat-control/src/utils/transformLiveChatConfig.ts b/botframework-webchat-control/src/utils/transformLiveChatConfig.ts index 8f35757..6267ac5 100644 --- a/botframework-webchat-control/src/utils/transformLiveChatConfig.ts +++ b/botframework-webchat-control/src/utils/transformLiveChatConfig.ts @@ -2,16 +2,21 @@ 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 isPersistentChat = (liveChatConfig as any)["LiveWSAndLiveChatEngJoin"]["msdyn_conversationmode"] === "192350001" || 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; }; From ed9e25ecd8fd5bcb8906bcbbd2ab0ff362f12ff0 Mon Sep 17 00:00:00 2001 From: Edward Tran Date: Mon, 28 Feb 2022 12:25:54 -0800 Subject: [PATCH 3/5] Add util to fetch chat reconnect config --- .../src/utils/fetchChatReconnectConfig.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 botframework-webchat-control/src/utils/fetchChatReconnectConfig.ts diff --git a/botframework-webchat-control/src/utils/fetchChatReconnectConfig.ts b/botframework-webchat-control/src/utils/fetchChatReconnectConfig.ts new file mode 100644 index 0000000..d7e0778 --- /dev/null +++ b/botframework-webchat-control/src/utils/fetchChatReconnectConfig.ts @@ -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; \ No newline at end of file From ba587c193b28df1bf22d79d47fbbd5a774971faf Mon Sep 17 00:00:00 2001 From: Edward Tran Date: Mon, 28 Feb 2022 12:28:11 -0800 Subject: [PATCH 4/5] Add unauth chat reconnect feature --- .../src/components/WebChat/WebChat.tsx | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/botframework-webchat-control/src/components/WebChat/WebChat.tsx b/botframework-webchat-control/src/components/WebChat/WebChat.tsx index c7f7de1..e2f6f00 100644 --- a/botframework-webchat-control/src/components/WebChat/WebChat.tsx +++ b/botframework-webchat-control/src/components/WebChat/WebChat.tsx @@ -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 { From 1bf1251ea1e547bb7fae2d61c53bea865f3d4609 Mon Sep 17 00:00:00 2001 From: Edward Tran Date: Mon, 28 Feb 2022 12:30:42 -0800 Subject: [PATCH 5/5] Update README.md --- botframework-webchat-control/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/botframework-webchat-control/README.md b/botframework-webchat-control/README.md index 087e326..3bda85a 100644 --- a/botframework-webchat-control/README.md +++ b/botframework-webchat-control/README.md @@ -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/)