feat: took the user from the front to send to the back

This commit is contained in:
Lion Arar 2025-10-15 08:29:06 -04:00
parent 5a40c8febf
commit 2a785d68ff
4 changed files with 59 additions and 7 deletions

View File

@ -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) => {
<div class="line-separator"></div>
<div class="chat-body">
<DialogueContent :messages="messages" />
<DialogueContent
@sendRole="HandleRole"
@sendEmail="HandleEmail"
:messages="messages"
/>
</div>
<div class="line-separator"></div>

View File

@ -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[];

View File

@ -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<Message> => {
// Function to send the message to the backend
sendChatMessage: async (userInput: string): Promise<Message> => {
const response = await api.post("/chat/respond", { userInput });
return response.data as Message;
},
// Function to send context to backend
sendPageContext: async (context: contextObject): Promise<string> => {
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<boolean> => {
console.log("FrontService - Email: ", email);
const response = await api.post("/chat/user", { email, role });
return response.data;
},
};

View File

@ -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;
};