From c611996eacecb77d8fe252873486743c5efc9d67 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 9 Oct 2024 15:09:44 -0500 Subject: [PATCH] fix postback --- src/lib/helpers/types/conversationTypes.js | 1 + src/lib/scss/custom/common/_common.scss | 11 ++++-- src/lib/scss/custom/pages/_chat.scss | 4 +-- .../[conversationId]/chat-box.svelte | 35 +++++++++++++------ 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/lib/helpers/types/conversationTypes.js b/src/lib/helpers/types/conversationTypes.js index 94212cf..9a34320 100644 --- a/src/lib/helpers/types/conversationTypes.js +++ b/src/lib/helpers/types/conversationTypes.js @@ -134,6 +134,7 @@ IRichContent.prototype.quick_replies; * @property {string} text - The message content. * @property {string} editor - The message editor. * @property {string} function - The function name. + * @property {string} [payload] - The payload. * @property {RichContent} rich_content - Rich content. * @property {string} post_action_disclaimer - The message disclaimer. * @property {string} data - The message data. diff --git a/src/lib/scss/custom/common/_common.scss b/src/lib/scss/custom/common/_common.scss index a593d41..8fc6093 100644 --- a/src/lib/scss/custom/common/_common.scss +++ b/src/lib/scss/custom/common/_common.scss @@ -176,16 +176,23 @@ button:focus { pre { -ms-overflow-style: none !important; white-space: pre-wrap; + margin-top: 0px; + margin-bottom: 0px; } pre::-webkit-scrollbar { display: none !important; } - - p { + + table { margin-top: 1em !important; margin-bottom: 1em !important; } + + p { + margin-top: 0 !important; + margin-bottom: 0 !important; + } a { color: white; diff --git a/src/lib/scss/custom/pages/_chat.scss b/src/lib/scss/custom/pages/_chat.scss index a18cc57..0b70a8f 100644 --- a/src/lib/scss/custom/pages/_chat.scss +++ b/src/lib/scss/custom/pages/_chat.scss @@ -218,8 +218,8 @@ } span p { - margin-top: 1em !important; - margin-bottom: 1em !important; + margin-top: 0px; + margin-bottom: 0px; } .chat-indication { diff --git a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte index 2a8af4e..0e02e3f 100644 --- a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte @@ -527,7 +527,7 @@ } function handleSaveKnowledge() { - sendChatMessage("Save knowledge"); + sendChatMessage("Save knowledge", { postback: { payload: '' } }); } /** @@ -544,9 +544,9 @@ const convId = conversationId || params.conversationId; let postback = data?.postback; - if (!postback) { - postback = buildPostbackMessage(dialogs, data?.payload || msgText, data?.truncateMsgId); - } + // if (!postback) { + // postback = buildPostbackMessage(dialogs, data?.payload || msgText, data?.truncateMsgId); + // } /** @type {import('$conversationTypes').MessageData?} */ let messageData = { @@ -633,7 +633,7 @@ webSpeech.onSpeechToTextDetected = (transcript) => { if (!!!_.trim(transcript) || isSendingMsg) return; - sendChatMessage(transcript).then(() => { + sendChatMessage(transcript, { postback: { payload: '' } }).then(() => { microphoneIcon = "microphone-off"; }).catch(() => { microphoneIcon = "microphone-off"; @@ -719,13 +719,14 @@ async function confirmSelectedOption(title, payload) { if (isSendingMsg || isThinking) return; - await sendChatMessage(title, { payload: payload }); + const postback = buildPostbackMessage(dialogs, payload || title, null);; + await sendChatMessage(title, { postback: postback }); } async function sentTextMessage() { const sentMsg = text; text = ''; - await sendChatMessage(sentMsg); + await sendChatMessage(sentMsg, { postback: { payload: '' } }); } /** @@ -900,8 +901,15 @@ cancelButtonText: 'No' }).then(async (result) => { if (result.value) { + let postback = null; + const found = dialogs.find(x => x.message_id === message?.message_id && USER_SENDERS.includes(x.sender?.role || '')); + const content = found?.payload; + if (content) { + postback = buildPostbackMessage(dialogs, content, message?.message_id); + } + deleteConversationMessage(params.conversationId, message?.message_id, true).then(resMessageId => { - sendChatMessage(message?.text, { inputMessageId: resMessageId }); + sendChatMessage(message?.text, { postback: postback, inputMessageId: resMessageId }); }); } }); @@ -964,8 +972,15 @@ async function confirmEditMsg() { isOpenEditMsgModal = false; + let postback = null; + const found = dialogs.find(x => x.message_id === truncateMsgId && USER_SENDERS.includes(x.sender?.role || '')); + const content = found?.payload; + if (content) { + postback = buildPostbackMessage(dialogs, content, truncateMsgId); + } + deleteConversationMessage(params.conversationId, truncateMsgId, true).then(resMessageId => { - sendChatMessage(editText, { inputMessageId: resMessageId }).then(() => { + sendChatMessage(editText, { postback: postback, inputMessageId: resMessageId }).then(() => { resetEditMsg(); }).catch(() => { resetEditMsg(); @@ -1094,7 +1109,7 @@ isOpenBigMsgModal = !isOpenBigMsgModal; const text = bigText; bigText = ''; - sendChatMessage(text); + sendChatMessage(text, { postback: { payload: '' } }); } /**