Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify postback #246

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading