diff --git a/src/modules/chatbot/components/conversation-box.vue b/src/modules/chatbot/components/conversation-box.vue
index 704b672..153ea62 100644
--- a/src/modules/chatbot/components/conversation-box.vue
+++ b/src/modules/chatbot/components/conversation-box.vue
@@ -10,8 +10,47 @@ const { messages } = useChatStore();
const { sendMessage } = useChatApi();
const handleSend = async () => {
- await sendMessage(text.value);
+ if (!text.value.trim()) return;
+ const userMessage = text.value;
text.value = '';
+
+ messages.push({
+ text: userMessage,
+ sent: true,
+ isThinking: false,
+ })
+
+ const thinkingMessage = {
+ text: "Thinking...",
+ sent: false,
+ isThinking: true
+ }
+ messages.push(thinkingMessage)
+
+ try {
+ const aiResponse = await sendMessage(userMessage);
+
+ const index = messages.indexOf(thinkingMessage);
+ if (index !== -1) {
+ messages.splice(index, 1, {
+ text: aiResponse.text,
+ sent: false,
+ isThinking: false,
+ })
+ }
+ }
+ catch (error) {
+ const index = messages.indexOf(thinkingMessage);
+ if (index !== -1) {
+ messages.splice(index, 1, {
+ text: "Sorry, something went wrong.",
+ sent: false,
+ isThinking: false,
+ });
+ }
+ throw error;
+ }
+
};
diff --git a/src/modules/chatbot/components/dialogue-content.vue b/src/modules/chatbot/components/dialogue-content.vue
index 704fac9..7ea148b 100644
--- a/src/modules/chatbot/components/dialogue-content.vue
+++ b/src/modules/chatbot/components/dialogue-content.vue
@@ -12,6 +12,36 @@ defineProps<{
+
+
+
+
+
+
+ Thinking...
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/modules/chatbot/composables/chat-api.ts b/src/modules/chatbot/composables/chat-api.ts
index cd5b9af..2f5ba6c 100644
--- a/src/modules/chatbot/composables/chat-api.ts
+++ b/src/modules/chatbot/composables/chat-api.ts
@@ -1,11 +1,12 @@
// composables/chat-api.ts
import { useChatStore } from "src/stores/message-store";
+import type { Message } from "../types/dialogue-message";
export const useChatApi = () => {
const chatStore = useChatStore();
- const sendMessage = async (text: string) => {
- await chatStore.sendMessage(text);
+ const sendMessage = async (text: string): Promise => {
+ return await chatStore.sendMessage(text);
};
return { sendMessage };
diff --git a/src/modules/chatbot/services/messageService.ts b/src/modules/chatbot/services/messageService.ts
index 5dd3d02..08d14b8 100644
--- a/src/modules/chatbot/services/messageService.ts
+++ b/src/modules/chatbot/services/messageService.ts
@@ -5,7 +5,6 @@ export const chatbotService = {
// Function to get the message from the backend
getChatMessage: async (userInput: string): Promise => {
const response = await api.post("/chat/respond", { userInput });
- console.log(response.data);
return response.data as Message;
},
};
diff --git a/src/modules/chatbot/types/dialogue-message.ts b/src/modules/chatbot/types/dialogue-message.ts
index 74785ce..2e26586 100644
--- a/src/modules/chatbot/types/dialogue-message.ts
+++ b/src/modules/chatbot/types/dialogue-message.ts
@@ -1,4 +1,5 @@
-export interface Message{
- text:string;
- sent: boolean
-};
\ No newline at end of file
+export interface Message {
+ text: string;
+ sent: boolean;
+ isThinking: boolean;
+}
diff --git a/src/stores/message-store.ts b/src/stores/message-store.ts
index 41b9236..ef8a37c 100644
--- a/src/stores/message-store.ts
+++ b/src/stores/message-store.ts
@@ -8,8 +8,6 @@ export const useChatStore = defineStore("chat", () => {
const sendMessage = async (userInput: string) => {
const reply = await chatbotService.getChatMessage(userInput);
- messages.value.push({ text: userInput, sent: true });
- messages.value.push(reply);
return reply;
};