From edd0e2329f22acc164e5e42aabd0fc0522676a67 Mon Sep 17 00:00:00 2001 From: "Aswin Dev P.S" Date: Tue, 28 Sep 2021 19:25:44 +0530 Subject: [PATCH] feat: Add the ability to close and reopen the chat window via SDK (#3080) --- app/javascript/packs/sdk.js | 4 ++-- app/javascript/sdk/IFrameHelper.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/javascript/packs/sdk.js b/app/javascript/packs/sdk.js index ab02f1f3a..d666b864b 100755 --- a/app/javascript/packs/sdk.js +++ b/app/javascript/packs/sdk.js @@ -40,8 +40,8 @@ const runSDK = ({ baseUrl, websiteToken }) => { launcherTitle: chatwootSettings.launcherTitle || '', showPopoutButton: chatwootSettings.showPopoutButton || false, - toggle() { - IFrameHelper.events.toggleBubble(); + toggle(state) { + IFrameHelper.events.toggleBubble(state); }, setUser(identifier, user) { diff --git a/app/javascript/sdk/IFrameHelper.js b/app/javascript/sdk/IFrameHelper.js index 5fcf215c0..098171fe5 100644 --- a/app/javascript/sdk/IFrameHelper.js +++ b/app/javascript/sdk/IFrameHelper.js @@ -137,8 +137,15 @@ export const IFrameHelper = { setBubbleText(window.$chatwoot.launcherTitle || message.label); }, - toggleBubble: () => { - onBubbleClick(); + toggleBubble: state => { + let bubbleState = {}; + if (state === 'open') { + bubbleState.toggleValue = true; + } else if (state === 'close') { + bubbleState.toggleValue = false; + } + + onBubbleClick(bubbleState); }, onBubbleToggle: isOpen => {