feat: refactored some things
This commit is contained in:
parent
2a785d68ff
commit
579045d933
|
|
@ -10,6 +10,7 @@ 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";
|
||||||
|
|
||||||
|
const isSessionReady = ref(false);
|
||||||
|
|
||||||
// Block to receive user from child
|
// Block to receive user from child
|
||||||
const userEmail = ref('')
|
const userEmail = ref('')
|
||||||
|
|
@ -23,20 +24,6 @@ const HandleRole = (role: string) => {
|
||||||
userRole.value = role;
|
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);
|
||||||
|
|
@ -71,9 +58,14 @@ onMounted(() => {
|
||||||
|
|
||||||
const handleSend = async () => {
|
const handleSend = async () => {
|
||||||
const userMessage = text.value.trim();
|
const userMessage = text.value.trim();
|
||||||
if (!userMessage) return
|
if (!userMessage)
|
||||||
text.value = '';
|
|
||||||
|
|
||||||
|
if (!isSessionReady.value) {
|
||||||
|
console.warn("Session not ready yet. Please wait...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
text.value = '';
|
||||||
messages.push({
|
messages.push({
|
||||||
text: userMessage,
|
text: userMessage,
|
||||||
sent: true,
|
sent: true,
|
||||||
|
|
@ -103,7 +95,7 @@ const handleSend = async () => {
|
||||||
const index = messages.indexOf(thinkingMessage);
|
const index = messages.indexOf(thinkingMessage);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
messages.splice(index, 1, {
|
messages.splice(index, 1, {
|
||||||
text: "Sorry, something went wrong.",
|
text: "Sorry, Message wasn't able to sent.",
|
||||||
sent: false,
|
sent: false,
|
||||||
isThinking: false,
|
isThinking: false,
|
||||||
});
|
});
|
||||||
|
|
@ -112,6 +104,7 @@ 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;
|
||||||
|
|
@ -120,8 +113,11 @@ const currentContext = computed(() =>
|
||||||
pageContexts.find(ctx => ctx.path === route.fullPath.replace('/', ''))
|
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 = {
|
const contextPayload: contextObject = {
|
||||||
name: ctx.name,
|
name: ctx.name,
|
||||||
|
|
@ -129,7 +125,15 @@ watch(currentContext, async (ctx) => {
|
||||||
features: ctx.features,
|
features: ctx.features,
|
||||||
path: ctx.path
|
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 }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
|
@ -161,18 +165,14 @@ watch(currentContext, async (ctx) => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="line-separator"></div>
|
<div class="line-separator"></div>
|
||||||
<q-form
|
<q-form class="chat-footer row">
|
||||||
@submit="handleSend"
|
|
||||||
class="chat-footer row"
|
|
||||||
>
|
|
||||||
|
|
||||||
<q-input
|
<q-input
|
||||||
v-model="text"
|
v-model="text"
|
||||||
:label="$t('chatbot.chat_placeholder')"
|
:label="$t('chatbot.chat_placeholder')"
|
||||||
autogrow
|
:autogrow="false"
|
||||||
class="col"
|
class="col"
|
||||||
@keydown.enter="handleSend"
|
|
||||||
style="margin-left: 8px;"
|
style="margin-left: 8px;"
|
||||||
|
@keyup.enter="handleSend"
|
||||||
/>
|
/>
|
||||||
</q-form>
|
</q-form>
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ export const chatbotService = {
|
||||||
email: string,
|
email: string,
|
||||||
role: string
|
role: string
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
console.log("FrontService - Email: ", email);
|
|
||||||
const response = await api.post("/chat/user", { email, role });
|
const response = await api.post("/chat/user", { email, role });
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user