diff --git a/src/lib/common/BubbleChat.svelte b/src/lib/common/BubbleChat.svelte new file mode 100644 index 00000000..bd458311 --- /dev/null +++ b/src/lib/common/BubbleChat.svelte @@ -0,0 +1,42 @@ + + +
+
+ + +
handleClose(e)} + > + +
+
+ {text} +
+
+
diff --git a/src/lib/common/LiveChatEntry.svelte b/src/lib/common/LiveChatEntry.svelte index b780b454..976648ba 100644 --- a/src/lib/common/LiveChatEntry.svelte +++ b/src/lib/common/LiveChatEntry.svelte @@ -3,11 +3,14 @@ import { onMount } from 'svelte'; import { PUBLIC_LIVECHAT_HOST, PUBLIC_LIVECHAT_ENTRY_ICON } from '$env/static/public'; import { getSettingDetail } from '$lib/services/setting-service'; - import { chatBotStore } from '$lib/helpers/store'; import { CHAT_FRAME_ID } from '$lib/helpers/constants'; import { ChatAction } from '$lib/helpers/enums'; + import BubbleChat from './BubbleChat.svelte'; let chatUrl = PUBLIC_LIVECHAT_HOST; + let showChatBox = false; + let showBubbleMsg = false; + let receivedMsg = ''; onMount(async () => { const agentSettings = await getSettingDetail("Agent"); @@ -17,33 +20,61 @@ // Handle event from iframe window.onmessage = async function(e) { if (e.data.action == ChatAction.Close) { - chatBotStore.set({ showChatBox: false }); + showChatBox = false; } else if (e.data.action == ChatAction.Open) { - chatBotStore.set({ showChatBox: true }); + // showChatBox = true; + } else if (e.data.action == ChatAction.ReceiveMsg && !showChatBox) { + receivedMsg = e.data?.data?.rich_content?.message?.text || e.data?.data?.text || ''; + showBubbleMsg = true; + wave(); } }; function openChatBox() { - chatBotStore.set({ showChatBox: true }); + showChatBox = true; + receivedMsg = ''; + showBubbleMsg = false; + } + + function closeBubbleMsg() { + receivedMsg = ''; + showBubbleMsg = false; + } + + function wave() { + const elem = document.getElementById('chatbot-icon'); + if (elem) { + elem.classList.add('waving'); + setTimeout(() => { + elem.classList.remove('waving'); + }, 800); + } }
+ {#if showBubbleMsg} +
+ closeBubbleMsg()} /> +
+ {/if} +