feat: Add the SDK method to programatically toggle live chat bubble (#4223)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Fayaz Ahmed 2022-05-06 19:30:48 +05:30 committed by GitHub
parent 80b8f5f915
commit ef850eda0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 79 additions and 28 deletions

View file

@ -10,7 +10,8 @@ import {
getUserCookieName,
hasUserKeys,
} from '../sdk/cookieHelpers';
import { addClass, removeClass } from '../sdk/DOMHelpers';
import { SDK_SET_BUBBLE_VISIBILITY } from 'shared/constants/sharedFrameEvents';
const runSDK = ({ baseUrl, websiteToken }) => {
if (window.$chatwoot) {
return;
@ -36,6 +37,23 @@ const runSDK = ({ baseUrl, websiteToken }) => {
IFrameHelper.events.toggleBubble(state);
},
toggleBubbleVisibility(visibility) {
let widgetElm = document.querySelector('.woot--bubble-holder');
let widgetHolder = document.querySelector('.woot-widget-holder');
if (visibility === 'hide') {
addClass(widgetHolder, 'woot-widget--without-bubble');
addClass(widgetElm, 'woot-hidden');
window.$chatwoot.hideMessageBubble = true;
} else if (visibility === 'show') {
removeClass(widgetElm, 'woot-hidden');
removeClass(widgetHolder, 'woot-widget--without-bubble');
window.$chatwoot.hideMessageBubble = false;
}
IFrameHelper.sendMessage(SDK_SET_BUBBLE_VISIBILITY, {
hideMessageBubble: window.$chatwoot.hideMessageBubble,
});
},
popoutChatWindow() {
IFrameHelper.events.popoutChatWindow({
baseUrl: window.$chatwoot.baseUrl,