Skip to content

Commit

Permalink
Merge pull request #246 from iceljc/features/refine-chat-window
Browse files Browse the repository at this point in the history
simplify postback
  • Loading branch information
iceljc authored Oct 10, 2024
2 parents ae3a838 + e1f60cd commit e9bcf20
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@
}
function handleSaveKnowledge() {
sendChatMessage("Save knowledge", { postback: { payload: '' } });
sendChatMessage("Save knowledge");
}
/**
Expand Down Expand Up @@ -633,7 +633,7 @@
webSpeech.onSpeechToTextDetected = (transcript) => {
if (!!!_.trim(transcript) || isSendingMsg) return;
sendChatMessage(transcript, { postback: { payload: '' } }).then(() => {
sendChatMessage(transcript).then(() => {
microphoneIcon = "microphone-off";
}).catch(() => {
microphoneIcon = "microphone-off";
Expand Down Expand Up @@ -726,7 +726,7 @@
async function sentTextMessage() {
const sentMsg = text;
text = '';
await sendChatMessage(sentMsg, { postback: { payload: '' } });
await sendChatMessage(sentMsg);
}
/**
Expand Down Expand Up @@ -757,6 +757,22 @@
return postback;
}
/**
* @param {string?} messageId
*/
function buildPostback(messageId) {
let postback = null;
if (!messageId) return postback;
const found = dialogs.find(x => x.message_id === messageId && USER_SENDERS.includes(x.sender?.role || ''));
const content = found?.payload;
if (content) {
postback = buildPostbackMessage(dialogs, content, messageId);
}
return postback;
}
/**
* @param {any[]} files
*/
Expand Down Expand Up @@ -901,13 +917,7 @@
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);
}
const postback = buildPostback(message?.message_id);
deleteConversationMessage(params.conversationId, message?.message_id, true).then(resMessageId => {
sendChatMessage(message?.text, { postback: postback, inputMessageId: resMessageId });
});
Expand Down Expand Up @@ -972,13 +982,7 @@
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);
}
const postback = buildPostback(truncateMsgId);
deleteConversationMessage(params.conversationId, truncateMsgId, true).then(resMessageId => {
sendChatMessage(editText, { postback: postback, inputMessageId: resMessageId }).then(() => {
resetEditMsg();
Expand Down Expand Up @@ -1109,7 +1113,7 @@
isOpenBigMsgModal = !isOpenBigMsgModal;
const text = bigText;
bigText = '';
sendChatMessage(text, { postback: { payload: '' } });
sendChatMessage(text);
}
/**
Expand Down

0 comments on commit e9bcf20

Please sign in to comment.