fix(chatbot): correct formatting issue with text display, now displays markdown properly as html
This commit is contained in:
parent
67132857ac
commit
883e6f8a3d
|
|
@ -16,7 +16,8 @@ declare module 'vue' {
|
||||||
// for each client)
|
// for each client)
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: import.meta.env.VITE_TARGO_BACKEND_URL,
|
baseURL: import.meta.env.VITE_TARGO_BACKEND_URL,
|
||||||
withCredentials: true
|
withCredentials: true,
|
||||||
|
timeout: 5 * 60 * 1000,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default defineBoot(({ app }) => {
|
export default defineBoot(({ app }) => {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export default {
|
||||||
error: {
|
error: {
|
||||||
NO_REPLY_RECEIVED: "encountered an error while waiting for chatbot to reply",
|
NO_REPLY_RECEIVED: "encountered an error while waiting for chatbot to reply",
|
||||||
SEND_MESSAGE_FAILED: "unable to send message to chatbot",
|
SEND_MESSAGE_FAILED: "unable to send message to chatbot",
|
||||||
|
GENERIC_RESPONSE_ERROR: "An error was encountered while waiting for the chatbot to reply, please try again.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ export default {
|
||||||
chat_thinking: "Réflexion en cours...",
|
chat_thinking: "Réflexion en cours...",
|
||||||
error: {
|
error: {
|
||||||
NO_REPLY_RECEIVED: "Une erreur est survenu lors de la réception de la réponse du chatbot",
|
NO_REPLY_RECEIVED: "Une erreur est survenu lors de la réception de la réponse du chatbot",
|
||||||
SEND_MESSAGE_FAILED: "Une erreur est survenu lors de l'envoi de votre message",
|
SEND_MESSAGE_FAILED: "Une erreur est survenue lors de l'envoi de votre message",
|
||||||
|
GENERIC_RESPONSE_ERROR: "Le chatbot ne réponds pas pour le moment, veuillez réessayer.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,15 @@
|
||||||
// const is_remembered = ref<boolean>(false);
|
// const is_remembered = ref<boolean>(false);
|
||||||
const is_employee_email = computed(() => email.value.includes('@targ'));
|
const is_employee_email = computed(() => email.value.includes('@targ'));
|
||||||
const is_game_time = computed(() => email.value.includes('allumette'));
|
const is_game_time = computed(() => email.value.includes('allumette'));
|
||||||
|
|
||||||
|
const onSubmitConnectionRequest = () => {
|
||||||
|
console.log('submit requested');
|
||||||
|
if (is_employee_email.value) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const onClickEmployeeConnect = () => {
|
||||||
|
auth_api.oidcLogin();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -27,28 +36,31 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="q-pt-sm q-px-xl q-pb-lg ">
|
<div class="q-px-xl q-pb-lg ">
|
||||||
<q-card-section class="text-center text-uppercase">
|
<div class="text-h6 text-weight-bold text-center text-uppercase q-py-sm">
|
||||||
<div class="text-h6 text-weight-bold">
|
|
||||||
{{ $t('login.page_header') }}
|
{{ $t('login.page_header') }}
|
||||||
</div>
|
</div>
|
||||||
</q-card-section>
|
|
||||||
|
|
||||||
<q-form @submit="auth_api.login">
|
<q-form
|
||||||
|
@submit="onSubmitConnectionRequest"
|
||||||
|
autocomplete="on"
|
||||||
|
>
|
||||||
<q-input
|
<q-input
|
||||||
v-model="email"
|
v-model="email"
|
||||||
dense
|
dense
|
||||||
outlined
|
outlined
|
||||||
|
label-slot
|
||||||
|
name="email"
|
||||||
color="accent"
|
color="accent"
|
||||||
label-color="accent"
|
label-color="accent"
|
||||||
class="rounded-5 inset-shadow bg-white"
|
class="rounded-5 inset-shadow bg-white"
|
||||||
label-slot
|
|
||||||
input-class="text-h6 text-primary"
|
input-class="text-h6 text-primary"
|
||||||
>
|
>
|
||||||
<template #label>
|
<template #label>
|
||||||
<span class="text-weight-bolder text-uppercase text-overline"> {{ $t('login.email') }} </span>
|
<span class="text-weight-bolder text-uppercase text-overline"> {{ $t('login.email') }} </span>
|
||||||
</template>
|
</template>
|
||||||
</q-input>
|
</q-input>
|
||||||
|
|
||||||
<!-- Stay-logged-in section, removed temporarly until customer module is up -->
|
<!-- Stay-logged-in section, removed temporarly until customer module is up -->
|
||||||
<!-- <q-card-section
|
<!-- <q-card-section
|
||||||
horizontal
|
horizontal
|
||||||
|
|
@ -86,7 +98,6 @@
|
||||||
<!-- <q-card-section class="text-center q-pa-none q-mt-none">
|
<!-- <q-card-section class="text-center q-pa-none q-mt-none">
|
||||||
<RouterLink disabled class="text-primary" to="/signup">{{ $t('loginPage.signUp') }}</RouterLink>
|
<RouterLink disabled class="text-primary" to="/signup">{{ $t('loginPage.signUp') }}</RouterLink>
|
||||||
</q-card-section> -->
|
</q-card-section> -->
|
||||||
</q-form>
|
|
||||||
|
|
||||||
<q-card-section class="row q-pt-sm">
|
<q-card-section class="row q-pt-sm">
|
||||||
<q-separator
|
<q-separator
|
||||||
|
|
@ -128,16 +139,18 @@
|
||||||
<q-btn
|
<q-btn
|
||||||
push
|
push
|
||||||
rounded
|
rounded
|
||||||
|
type="submit"
|
||||||
color="accent"
|
color="accent"
|
||||||
icon="img:src/assets/logo-targo-simple.svg"
|
icon="img:src/assets/logo-targo-simple.svg"
|
||||||
:label="$t('login.button.employee')"
|
:label="$t('login.button.employee')"
|
||||||
class="full-width row"
|
class="full-width row"
|
||||||
@click="auth_api.oidcLogin"
|
@click="onClickEmployeeConnect"
|
||||||
/>
|
/>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
</q-slide-transition>
|
</q-slide-transition>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
</q-form>
|
||||||
</div>
|
</div>
|
||||||
</q-card>
|
</q-card>
|
||||||
<div v-if="is_game_time">
|
<div v-if="is_game_time">
|
||||||
|
|
|
||||||
|
|
@ -2,49 +2,33 @@
|
||||||
setup
|
setup
|
||||||
lang="ts"
|
lang="ts"
|
||||||
>
|
>
|
||||||
|
import MarkdownIt from 'markdown-it';
|
||||||
|
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
// import MarkdownIt from 'markdown-it'
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useAuthStore } from 'src/stores/auth-store';
|
import { useAuthStore } from 'src/stores/auth-store';
|
||||||
import type { Message } from 'src/modules/chatbot/models/dialogue-message.model';
|
import type { Message } from 'src/modules/chatbot/models/dialogue-message.model';
|
||||||
import { useI18n } from 'vue-i18n';
|
|
||||||
|
|
||||||
const { t } = useI18n();
|
// ========== state ========================================
|
||||||
const auth_store = useAuthStore();
|
|
||||||
|
|
||||||
const { message } = defineProps<{
|
const { message } = defineProps<{
|
||||||
message: Message;
|
message: Message;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const message_text = computed(() => message.text.includes('chatbot.') ? t(message.text) : message.text)
|
const { t } = useI18n();
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
const md = new MarkdownIt({
|
||||||
|
linkify: true,
|
||||||
|
typographer: true,
|
||||||
|
})
|
||||||
|
|
||||||
const is_error = computed(() => message.text.includes('NO_REPLY_RECEIVED') || message.text.includes('SEND_MESSAGE_FAILED'));
|
// ========== computed ========================================
|
||||||
|
|
||||||
// Initialize Markdown parser
|
const message_text = computed(() => message.text.includes('chatbot.') ?
|
||||||
// const md = new MarkdownIt({
|
t(message.text) :
|
||||||
// // breaks: false, // Support line breaks
|
message.text.replaceAll("\\n", "\n")
|
||||||
// linkify: true, // Make URLs clickable
|
);
|
||||||
// html: false // Prevent raw HTML injection
|
const is_error = computed(() => message.text.includes('chatbot.error.'));
|
||||||
// })
|
|
||||||
|
|
||||||
// // Removes all the h1,h2,h3 to make the Md more user friendly
|
|
||||||
// const cleanMarkdown = (markdown: string): string => {
|
|
||||||
// if (!markdown) return ''
|
|
||||||
// return markdown
|
|
||||||
// .replace(/\r\n/g, '\n') // normalize Windows line endings
|
|
||||||
// .replace(/([.!?])(\s+)(?=[A-Z])/g, '$1\n') // insert line break after sentence-ending punctuation
|
|
||||||
// .replace(/\n{3,}/g, '\n\n') // squash triple+ line breaks
|
|
||||||
// .replace(/^#{1,3}\s(.*)$/gm, '#### $1') // downgrade headings
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Compute parsed content
|
|
||||||
// const parsedText = computed((): string => {
|
|
||||||
// const cleaned = cleanMarkdown(message.text || '')
|
|
||||||
// if (cleaned.includes('chatbot.')) {
|
|
||||||
// const translated_message = t(message.text);
|
|
||||||
// return md.render(translated_message);
|
|
||||||
// }
|
|
||||||
// return md.render(cleaned);
|
|
||||||
// })
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -67,11 +51,12 @@
|
||||||
|
|
||||||
<q-chat-message
|
<q-chat-message
|
||||||
v-else
|
v-else
|
||||||
|
text-html
|
||||||
:sent="message.sent"
|
:sent="message.sent"
|
||||||
:name="message.sent ? auth_store.user?.first_name : 'TargoBot'"
|
:name="message.sent ? authStore.user?.first_name : 'TargoBot'"
|
||||||
:bg-color="message.sent ? 'accent' : 'info'"
|
:bg-color="message.sent ? 'accent' : 'info'"
|
||||||
:text-color="message.sent ? 'white' : ''"
|
:text-color="message.sent ? 'white' : ''"
|
||||||
:text="[message_text]"
|
:text="[md.renderInline(message_text)]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user