From 2a785d68ff985284e70ca38681a92598185db60f Mon Sep 17 00:00:00 2001 From: Lion Arar Date: Wed, 15 Oct 2025 08:29:06 -0400 Subject: [PATCH] feat: took the user from the front to send to the back --- .../chatbot/components/conversation-box.vue | 36 +++++++++++++++++-- .../chatbot/components/dialogue-content.vue | 12 ++++++- .../chatbot/services/messageService.ts | 16 +++++++-- src/stores/message-store.ts | 2 +- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/modules/chatbot/components/conversation-box.vue b/src/modules/chatbot/components/conversation-box.vue index 6ecef34..5951e01 100644 --- a/src/modules/chatbot/components/conversation-box.vue +++ b/src/modules/chatbot/components/conversation-box.vue @@ -10,6 +10,34 @@ import { chatbotService } from "../services/messageService"; import { pageContexts } from "src/page-contexts"; import type { contextObject } from "src/page-contexts/pages/types/context-object"; + +// 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; +} + +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); let dragging = false @@ -84,8 +112,6 @@ const handleSend = async () => { } }; - - // Block to handle sending the url to n8n const route = useRoute() const sendPageContext = chatbotService.sendPageContext; @@ -127,7 +153,11 @@ watch(currentContext, async (ctx) => {
- +
diff --git a/src/modules/chatbot/components/dialogue-content.vue b/src/modules/chatbot/components/dialogue-content.vue index 585d049..5578c15 100644 --- a/src/modules/chatbot/components/dialogue-content.vue +++ b/src/modules/chatbot/components/dialogue-content.vue @@ -2,10 +2,20 @@ import DialoguePhrase from './dialogue-phrase.vue'; import type { Message } from '../types/dialogue-message'; import { useAuthStore } from 'src/stores/auth-store'; -import { watch, nextTick } from 'vue'; +import { watch, nextTick, onMounted } from 'vue'; const authStore = useAuthStore(); const currentUser = authStore.user; +const emitUser = defineEmits(['sendRole', 'sendEmail']); + +const sendUser = () => { + emitUser('sendEmail', currentUser.email) + emitUser('sendRole', currentUser.role) +} + +onMounted(() => { + sendUser(); +}) const props = defineProps<{ messages: Message[]; diff --git a/src/modules/chatbot/services/messageService.ts b/src/modules/chatbot/services/messageService.ts index c7bafb8..3431a07 100644 --- a/src/modules/chatbot/services/messageService.ts +++ b/src/modules/chatbot/services/messageService.ts @@ -3,14 +3,26 @@ import type { Message } from "../types/dialogue-message"; import { api } from "src/boot/axios"; export const chatbotService = { - // Function to get the message from the backend - getChatMessage: async (userInput: string): Promise => { + // Function to send the message to the backend + sendChatMessage: async (userInput: string): Promise => { const response = await api.post("/chat/respond", { userInput }); return response.data as Message; }, + // Function to send context to backend sendPageContext: async (context: contextObject): Promise => { const response = await api.post("/chat/context", context); return response.data; }, + + // Function to send user credentials to the backend to communicate with n8n. + // Will have to modify later on to accomodate newer versions of User Auth/User Structure + sendUserCredentials: async ( + email: string, + role: string + ): Promise => { + console.log("FrontService - Email: ", email); + const response = await api.post("/chat/user", { email, role }); + return response.data; + }, }; diff --git a/src/stores/message-store.ts b/src/stores/message-store.ts index 179854f..b7dd045 100644 --- a/src/stores/message-store.ts +++ b/src/stores/message-store.ts @@ -10,7 +10,7 @@ export const useChatStore = defineStore("chat", () => { const { t } = useI18n(); const sendMessage = async (userInput: string) => { - const reply = await chatbotService.getChatMessage(userInput); + const reply = await chatbotService.sendChatMessage(userInput); return reply; };