From 32ed59260929bd85d3613bbeea6257c729b763b8 Mon Sep 17 00:00:00 2001 From: Ramiro Medina Date: Thu, 22 Feb 2024 20:08:18 +0000 Subject: [PATCH] feat: Add actions to Chat --- ui/src/core_components/CoreChat.vue | 106 ++++++++++++++++++++++++---- 1 file changed, 94 insertions(+), 12 deletions(-) diff --git a/ui/src/core_components/CoreChat.vue b/ui/src/core_components/CoreChat.vue index b9e69648b..e635bbec1 100644 --- a/ui/src/core_components/CoreChat.vue +++ b/ui/src/core_components/CoreChat.vue @@ -15,11 +15,20 @@ }}
- +
+ +
= ref(null); @@ -191,29 +209,56 @@ async function replaceMessage(messageKey: string, message: Message) { async function handleMessageSent() { await addMessage({ origin: "outgoing", - content: outgoingMessage.value, + text: outgoingMessage.value, date: new Date(), }); - outgoingMessage.value = ""; const outgoingMessageKey = await addMessage({ origin: "incoming", - content: "Loading...", + text: "Loading...", isLoading: true, }); const event = new CustomEvent("chat-message", { detail: { payload: outgoingMessage.value, callback: ({ payload }) => { - const content: string = payload.result?.result; + const contents = payload.result?.result; replaceMessage(outgoingMessageKey, { origin: "incoming", - content, + text: contents?.text, + actions: contents?.actions, date: new Date(), }); }, }, }); rootEl.value.dispatchEvent(event); + outgoingMessage.value = ""; +} + +function handleActionClick(action: Message["actions"][number]) { + const {subheading, name, desc, data} = action; + const event = new CustomEvent("chat-action-click", { + detail: { + payload: { + subheading, + name, + desc, + data + } + // callback: ({ payload }) => { + // const text: string = payload.result?.result; + // replaceMessage(outgoingMessageKey, { + // origin: "incoming", + // text, + // actions: [ + // {subheading: "WEBSITE", name: "Google", desc: "Leading search engine."},{subheading: "WEBSITE", name: "ChatGPT", desc: "AI chatbot, great for everyday use."} + // ], + // date: new Date(), + // }); + // }, + }, + }); + rootEl.value.dispatchEvent(event); }