diff --git a/src/lib/scss/custom/pages/_chat.scss b/src/lib/scss/custom/pages/_chat.scss index 4b96dfd4..c0dd5a73 100644 --- a/src/lib/scss/custom/pages/_chat.scss +++ b/src/lib/scss/custom/pages/_chat.scss @@ -188,6 +188,40 @@ min-width: 50px; } } + + .card-group-container { + display: flex; + flex-wrap: wrap; + gap: 5px; + margin-top: 10px; + + .card-element { + flex: 1 1 fit-content; + border-radius: 10px; + border-width: 2px; + max-width: 100%; + margin-bottom: 0px; + + .card-element-title { + font-size: 1.1rem; + font-weight: 700; + } + + .card-element-subtitle { + font-size: 0.8rem; + font-weight: 500; + } + + .card-option-group { + margin-top: 5px; + + .btn { + display: block; + margin-left: 0px !important; + } + } + } + } } .ctext-wrap { diff --git a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte index 13213244..7a3b76c9 100644 --- a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte @@ -362,11 +362,11 @@ await sentTextMessage(); } - /** @param {string} payload */ - async function confirmSelectedOption(payload) { + /** @param {string} answer */ + async function confirmSelectedOption(answer) { if (isSendingMsg || isThinking) return; - await sendChatMessage(payload); + await sendChatMessage(answer); } async function sentTextMessage() { diff --git a/src/routes/chat/[agentId]/[conversationId]/richContent/rc-generic-options.svelte b/src/routes/chat/[agentId]/[conversationId]/richContent/rc-generic-options.svelte new file mode 100644 index 00000000..6edb8d0f --- /dev/null +++ b/src/routes/chat/[agentId]/[conversationId]/richContent/rc-generic-options.svelte @@ -0,0 +1,96 @@ + + +{#if cards.length > 0} +
+ {#each cards as card, idx (idx)} + + + {#if !!card.title} +
{card.title}
+ {/if} + {#if !!card.subtitle} +
{card.subtitle}
+ {/if} + {#if card.options?.length > 0} +
+ {#each card.options as option, i (i)} + + {/each} +
+ {/if} +
+
+ {/each} +
+{/if} diff --git a/src/routes/chat/[agentId]/[conversationId]/richContent/rc-options.svelte b/src/routes/chat/[agentId]/[conversationId]/richContent/rc-options.svelte index 97f7a250..7835ca66 100644 --- a/src/routes/chat/[agentId]/[conversationId]/richContent/rc-options.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/richContent/rc-options.svelte @@ -7,6 +7,9 @@ /** @type {boolean} */ export let disableOption = false; + /** @type {boolean} */ + export let fillPostback = false; + /** @type {any[]} */ export let options = []; @@ -30,54 +33,43 @@ /** @param {any[]} options */ function collectOptions(options) { - /** @type {any[]} */ - let res = []; - options?.map(op => { - if (!!!op.title || !!!op.payload) { - return; - } - - if (op.buttons?.length > 0) { - // @ts-ignore - op.buttons?.map(x => { - if (!!x.title && !!x.payload) { - res.push({ - title: x.title, - payload: x.payload, - isClicked: false - }); - } - }); - } else { - res.push({ - title: op.title, - payload: op.payload, - isClicked: false - }); - } - }); + const res = options?.map(op => { + return { + title: op.title, + payload: op.payload, + isClicked: false + }; + }) || []; return res; } /** * @param {any} e - * @param {string} payload + * @param {any} option * @param {number} index */ - function handleClickOption(e, payload, index) { + function handleClickOption(e, option, index) { e.preventDefault(); if (!isMultiSelect) { - innerConfirm(payload); + innerConfirm(fillPostback ? option?.payload : option?.title); } else { localOptions = localOptions.map((op, idx) => { if (idx === index) { op.isClicked = !op.isClicked; if (op.isClicked) { - answers = [...answers, op.payload]; + if (fillPostback) { + answers = [...answers, op.payload]; + } else { + answers = [...answers, op.title]; + } } else { - answers = answers.filter(a => a != op.payload); + if (fillPostback) { + answers = answers.filter(a => a != op.payload); + } else { + answers = answers.filter(a => a != op.title); + } } } return op; @@ -90,15 +82,15 @@ */ function handleConfirm(e) { e.preventDefault(); - const payload = answers.join(separator); - innerConfirm(payload); + const answer = answers.join(separator); + innerConfirm(answer); } /** - * @param {string} payload + * @param {string} answer */ - function innerConfirm(payload) { - onConfirm && onConfirm(payload); + function innerConfirm(answer) { + onConfirm && onConfirm(answer); reset(); } @@ -112,10 +104,24 @@ {#if localOptions.length > 0}
{#each localOptions as option, index} - + {/each} {#if isMultiSelect} - + {/if}
{/if} \ No newline at end of file diff --git a/src/routes/chat/[agentId]/[conversationId]/richContent/rich-content.svelte b/src/routes/chat/[agentId]/[conversationId]/richContent/rich-content.svelte index 08131640..d9e650ca 100644 --- a/src/routes/chat/[agentId]/[conversationId]/richContent/rich-content.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/richContent/rich-content.svelte @@ -2,6 +2,7 @@ import { RichType } from "$lib/helpers/enums"; import Markdown from "$lib/common/Markdown.svelte"; import RcOptions from "./rc-options.svelte"; + import RcGenericOptions from "./rc-generic-options.svelte"; /** @type {any} */ export let message; @@ -16,10 +17,10 @@ export let onConfirm = () => {}; /** - * @param {string} payload + * @param {string} answer */ - function handleConfirm(payload) { - onConfirm && onConfirm(payload); + function handleConfirm(answer) { + onConfirm && onConfirm(answer); } @@ -31,12 +32,12 @@ {#if displayExtraElements} {#if message?.rich_content?.message?.rich_type === RichType.QuickReply} - + {:else if message?.rich_content?.message?.rich_type === RichType.Button} - + {:else if message?.rich_content?.message?.rich_type === RichType.MultiSelect} - + {:else if message?.rich_content?.message?.rich_type === RichType.Generic} - + {/if} {/if} \ No newline at end of file