diff --git a/src/modules/chatbot/components/conversation-box.vue b/src/modules/chatbot/components/conversation-box.vue index 5951e01..79c869c 100644 --- a/src/modules/chatbot/components/conversation-box.vue +++ b/src/modules/chatbot/components/conversation-box.vue @@ -10,6 +10,7 @@ import { chatbotService } from "../services/messageService"; import { pageContexts } from "src/page-contexts"; import type { contextObject } from "src/page-contexts/pages/types/context-object"; +const isSessionReady = ref(false); // Block to receive user from child const userEmail = ref('') @@ -23,20 +24,6 @@ const HandleRole = (role: string) => { userRole.value = role; } -watch([userEmail, userRole], async ([email, role]) => { - if (email && role) { - // Both fields ready — now send to your async service - try { - await chatbotService.sendUserCredentials(email, role) - console.log('✅ Sent user context successfully') - } catch (err) { - console.error('❌ Failed to send user context:', err) - } - } -}) - - - // Block to enable editing the width of the drawer const drawerWidth = ref(370); @@ -71,9 +58,14 @@ onMounted(() => { const handleSend = async () => { const userMessage = text.value.trim(); - if (!userMessage) return - text.value = ''; + if (!userMessage) + if (!isSessionReady.value) { + console.warn("Session not ready yet. Please wait..."); + return; + } + + text.value = ''; messages.push({ text: userMessage, sent: true, @@ -103,7 +95,7 @@ const handleSend = async () => { const index = messages.indexOf(thinkingMessage); if (index !== -1) { messages.splice(index, 1, { - text: "Sorry, something went wrong.", + text: "Sorry, Message wasn't able to sent.", sent: false, isThinking: false, }); @@ -112,6 +104,7 @@ const handleSend = async () => { } }; + // Block to handle sending the url to n8n const route = useRoute() const sendPageContext = chatbotService.sendPageContext; @@ -120,8 +113,11 @@ const currentContext = computed(() => pageContexts.find(ctx => ctx.path === route.fullPath.replace('/', '')) ) -watch(currentContext, async (ctx) => { - if (!ctx) return; + + +watch([currentContext, userEmail, userRole], async ([ctx, email, role]) => { + if (!ctx || !email || !role) return; + if (isSessionReady.value) return; const contextPayload: contextObject = { name: ctx.name, @@ -129,7 +125,15 @@ watch(currentContext, async (ctx) => { features: ctx.features, path: ctx.path } - await sendPageContext(contextPayload) + + try { + await Promise.all([chatbotService.sendUserCredentials(email, role), + sendPageContext(contextPayload), + ]); + isSessionReady.value = true; + } catch (err) { + console.error("Error", err) + } }, { immediate: true } ); @@ -161,18 +165,14 @@ watch(currentContext, async (ctx) => {
-