2
0

🚸 (chatwoot) Make sure to close the chat bubble before opening Chatwoot

This commit is contained in:
Baptiste Arnaud
2022-11-10 14:21:42 +01:00
parent 54a1dc0431
commit d01549fee6
2 changed files with 6 additions and 5 deletions

View File

@@ -16,7 +16,7 @@ export const IframeEmbedCode = ({
const src = `${ const src = `${
env('VIEWER_INTERNAL_URL') ?? getViewerUrl({ isBuilder: true }) env('VIEWER_INTERNAL_URL') ?? getViewerUrl({ isBuilder: true })
}/${typebot?.publicId}` }/${typebot?.publicId}`
const code = `<iframe src="${src}" width="${widthLabel}" height="${heightLabel}" />` const code = `<iframe src="${src}" width="${widthLabel}" height="${heightLabel}" style="border: none"></iframe>`
return <CodeEditor value={code} lang="html" isReadOnly /> return <CodeEditor value={code} lang="html" isReadOnly />
} }

View File

@@ -5,7 +5,7 @@ import { isEmbedded } from 'services/utils'
import { parseCorrectValueType, parseVariables } from 'services/variable' import { parseCorrectValueType, parseVariables } from 'services/variable'
const parseSetUserCode = (user: ChatwootOptions['user']) => ` const parseSetUserCode = (user: ChatwootOptions['user']) => `
window.$chatwoot.setUser("${user?.id ?? user?.email}", { window.$chatwoot.setUser("${user?.id ?? ''}", {
email: ${user?.email ? `"${user.email}"` : 'undefined'}, email: ${user?.email ? `"${user.email}"` : 'undefined'},
name: ${user?.name ? `"${user.name}"` : 'undefined'}, name: ${user?.name ? `"${user.name}"` : 'undefined'},
avatar_url: ${user?.avatarUrl ? `"${user.avatarUrl}"` : 'undefined'}, avatar_url: ${user?.avatarUrl ? `"${user.avatarUrl}"` : 'undefined'},
@@ -19,10 +19,9 @@ const parseChatwootOpenCode = ({
user, user,
}: ChatwootOptions) => ` }: ChatwootOptions) => `
if (window.$chatwoot) { if (window.$chatwoot) {
if(${Boolean(user?.id || user?.email)}) { if(${Boolean(user)}) {
${parseSetUserCode(user)} ${parseSetUserCode(user)}
} }
if (typeof Typebot !== 'undefined') Typebot.getBubbleActions?.().close()
window.$chatwoot.toggle("open"); window.$chatwoot.toggle("open");
} else { } else {
(function (d, t) { (function (d, t) {
@@ -42,7 +41,6 @@ if (window.$chatwoot) {
if(${Boolean(user?.id || user?.email)}) { if(${Boolean(user?.id || user?.email)}) {
${parseSetUserCode(user)} ${parseSetUserCode(user)}
} }
if (typeof Typebot !== 'undefined') Typebot.getBubbleActions?.().close()
window.$chatwoot.toggle("open"); window.$chatwoot.toggle("open");
}); });
}; };
@@ -60,6 +58,9 @@ export const openChatwootWidget = async (
details: null, details: null,
}) })
} else if (isEmbedded) { } else if (isEmbedded) {
sendEventToParent({
closeChatBubble: true,
})
sendEventToParent({ sendEventToParent({
codeToExecute: parseVariables(variables)( codeToExecute: parseVariables(variables)(
parseChatwootOpenCode(block.options) parseChatwootOpenCode(block.options)