targo-frontend/src/stores/message-store.ts

32 lines
914 B
TypeScript

import type { Message } from "src/modules/chatbot/types/dialogue-message";
import { defineStore } from "pinia";
import { chatbotService } from "src/modules/chatbot/services/messageService";
import { ref } from "vue";
export const useChatStore = defineStore("chat", () => {
const messages = ref<Message[]>([]);
const hasShownInstructions = ref(false);
const sendMessage = async (userInput: string) => {
const reply = await chatbotService.getChatMessage(userInput);
return reply;
};
const showInstructionsOnce = () => {
if (!hasShownInstructions.value) {
messages.value.push({
text: "Welcome to your technical assistant.\nPlease provide the Client ID and \na description of the problem.",
sent: false,
isThinking: false,
});
hasShownInstructions.value = true;
}
};
return {
messages,
sendMessage,
showInstructionsOnce,
};
});