feat: took the user from the front to send to the back
This commit is contained in:
parent
5a40c8febf
commit
2a785d68ff
|
|
@ -10,6 +10,34 @@ import { chatbotService } from "../services/messageService";
|
||||||
import { pageContexts } from "src/page-contexts";
|
import { pageContexts } from "src/page-contexts";
|
||||||
import type { contextObject } from "src/page-contexts/pages/types/context-object";
|
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
|
// Block to enable editing the width of the drawer
|
||||||
const drawerWidth = ref(370);
|
const drawerWidth = ref(370);
|
||||||
let dragging = false
|
let dragging = false
|
||||||
|
|
@ -84,8 +112,6 @@ const handleSend = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Block to handle sending the url to n8n
|
// Block to handle sending the url to n8n
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const sendPageContext = chatbotService.sendPageContext;
|
const sendPageContext = chatbotService.sendPageContext;
|
||||||
|
|
@ -127,7 +153,11 @@ watch(currentContext, async (ctx) => {
|
||||||
<div class="line-separator"></div>
|
<div class="line-separator"></div>
|
||||||
|
|
||||||
<div class="chat-body">
|
<div class="chat-body">
|
||||||
<DialogueContent :messages="messages" />
|
<DialogueContent
|
||||||
|
@sendRole="HandleRole"
|
||||||
|
@sendEmail="HandleEmail"
|
||||||
|
:messages="messages"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="line-separator"></div>
|
<div class="line-separator"></div>
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,20 @@
|
||||||
import DialoguePhrase from './dialogue-phrase.vue';
|
import DialoguePhrase from './dialogue-phrase.vue';
|
||||||
import type { Message } from '../types/dialogue-message';
|
import type { Message } from '../types/dialogue-message';
|
||||||
import { useAuthStore } from 'src/stores/auth-store';
|
import { useAuthStore } from 'src/stores/auth-store';
|
||||||
import { watch, nextTick } from 'vue';
|
import { watch, nextTick, onMounted } from 'vue';
|
||||||
|
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
const currentUser = authStore.user;
|
const currentUser = authStore.user;
|
||||||
|
const emitUser = defineEmits(['sendRole', 'sendEmail']);
|
||||||
|
|
||||||
|
const sendUser = () => {
|
||||||
|
emitUser('sendEmail', currentUser.email)
|
||||||
|
emitUser('sendRole', currentUser.role)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
sendUser();
|
||||||
|
})
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
messages: Message[];
|
messages: Message[];
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,26 @@ import type { Message } from "../types/dialogue-message";
|
||||||
import { api } from "src/boot/axios";
|
import { api } from "src/boot/axios";
|
||||||
|
|
||||||
export const chatbotService = {
|
export const chatbotService = {
|
||||||
// Function to get the message from the backend
|
// Function to send the message to the backend
|
||||||
getChatMessage: async (userInput: string): Promise<Message> => {
|
sendChatMessage: async (userInput: string): Promise<Message> => {
|
||||||
const response = await api.post("/chat/respond", { userInput });
|
const response = await api.post("/chat/respond", { userInput });
|
||||||
return response.data as Message;
|
return response.data as Message;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Function to send context to backend
|
||||||
sendPageContext: async (context: contextObject): Promise<string> => {
|
sendPageContext: async (context: contextObject): Promise<string> => {
|
||||||
const response = await api.post("/chat/context", context);
|
const response = await api.post("/chat/context", context);
|
||||||
return response.data;
|
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;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ export const useChatStore = defineStore("chat", () => {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const sendMessage = async (userInput: string) => {
|
const sendMessage = async (userInput: string) => {
|
||||||
const reply = await chatbotService.getChatMessage(userInput);
|
const reply = await chatbotService.sendChatMessage(userInput);
|
||||||
return reply;
|
return reply;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user