From e5b2c12aedfd4ac251ca72473287117786b8c725 Mon Sep 17 00:00:00 2001 From: Lion Arar Date: Mon, 20 Oct 2025 10:30:29 -0400 Subject: [PATCH] feat: had to take a few lines to make sure the url and context was watched dynamically. --- .../chatbot/components/conversation-box.vue | 63 +++++++++---------- .../chatbot/services/messageService.ts | 2 +- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/modules/chatbot/components/conversation-box.vue b/src/modules/chatbot/components/conversation-box.vue index c028b40..8f19d43 100644 --- a/src/modules/chatbot/components/conversation-box.vue +++ b/src/modules/chatbot/components/conversation-box.vue @@ -10,21 +10,6 @@ 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('') -const userRole = ref('') - -const HandleEmail = (email: string) => { - userEmail.value = email; -} - -const HandleRole = (role: string) => { - userRole.value = role; -} - - // Block to enable editing the width of the drawer const drawerWidth = ref(370); let dragging = false @@ -32,38 +17,32 @@ const startDrag = (e: MouseEvent) => { dragging = true e.preventDefault() } - const onDrag = (e: MouseEvent) => { if (!dragging) return // calculate new width const newWidth = window.innerWidth - e.clientX drawerWidth.value = Math.max(350, Math.min(1000, newWidth)) // min/max width } - const stopDrag = () => { dragging = false } window.addEventListener('mousemove', onDrag) window.addEventListener('mouseup', stopDrag) + // Block to handle the incomming and sending of the messages from the user and the ai const text = ref(''); const { messages } = useChatStore(); const { sendMessage } = useChatApi(); - const chatStore = useChatStore(); onMounted(() => { chatStore.showInstructionsOnce(); }) +const isSessionReady = ref(false); const handleSend = async () => { const userMessage = text.value.trim(); - if (!userMessage) - if (!isSessionReady.value) { - console.warn("Session not ready yet. Please wait..."); - return; - } text.value = ''; messages.push({ @@ -105,6 +84,19 @@ const handleSend = async () => { }; + +// Block to receive user from child +const userEmail = ref('') +const userRole = ref('') + +const HandleEmail = (email: string) => { + userEmail.value = email; +} + +const HandleRole = (role: string) => { + userRole.value = role; +} + // Block to handle sending the url to n8n const route = useRoute() const sendPageContext = chatbotService.sendPageContext; @@ -113,11 +105,9 @@ const currentContext = computed(() => pageContexts.find(ctx => ctx.path === route.fullPath.replace('/', '')) ) - - +// Function that sends the page context to n8n watch([currentContext, userEmail, userRole], async ([ctx, email, role]) => { if (!ctx || !email || !role) return; - if (isSessionReady.value) return; const contextPayload: contextObject = { name: ctx.name, @@ -139,12 +129,12 @@ watch([currentContext, userEmail, userRole], async ([ctx, email, role]) => { ); -const custId = ref('') -const handleCustomerId = async () => { - const cId = custId.value; - custId.value = ''; - await chatbotService.retrieveCustomerDiagnostics(cId); -} +// const custId = ref('') +// const handleCustomerId = async () => { +// const cId = custId.value; +// custId.value = ''; +// await chatbotService.retrieveCustomerDiagnostics(cId); +// } @@ -173,7 +163,10 @@ const handleCustomerId = async () => {
- + { style="margin-left: 8px;" @keyup.enter="handleSend" /> - + /> -->
=> { + console.log(context.path, " ", context.features); const response = await api.post("/chat/context", context); return response.data; }, @@ -26,7 +27,6 @@ export const chatbotService = { }, retrieveCustomerDiagnostics: async (id: string): Promise => { - console.log("Frontend Service id retreived"); const response = await api.get(`/chat/customer/${id}`); return response.data; },