Update
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
const caseID = document.querySelector('.social-case-conversation-header span')?.textContent || '';
|
||||
console.log('Caso unread: ' + caseID);
|
||||
// Capturar TODOS los mensajes en orden cronológico
|
||||
const conversationItems = document.querySelectorAll(
|
||||
'.case-conversation-item.client, .case-conversation-item.agent, .case-conversation-item.system'
|
||||
);
|
||||
|
||||
// var allMessages = [];
|
||||
// Construir el objeto con la estructura requerida
|
||||
const payload = {
|
||||
conversation_id: caseID,
|
||||
source_chat: 'SMCC Recap - Test',
|
||||
case_info: {
|
||||
base_id: '7cb1a048-8e67-44fe-a71e-ccacf19ef944',
|
||||
context_extra: ''
|
||||
},
|
||||
messages: []
|
||||
};
|
||||
|
||||
conversationItems.forEach(item => {
|
||||
if (item.classList.contains("client")) {
|
||||
const spans = item.querySelectorAll("span.body-text");
|
||||
spans.forEach(span => {
|
||||
if (span.textContent.trim() !== "") {
|
||||
payload.messages.push({
|
||||
id: item.getAttribute('id'),
|
||||
role: "user",
|
||||
content: span.textContent.replace(/\n{2,}/g, '\n').trim()
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (item.classList.contains("agent") || item.classList.contains("system")) {
|
||||
const texts = item.querySelectorAll(".sm-whatsapp .text, span.body-text");
|
||||
texts.forEach(t => {
|
||||
if (t.innerText.trim() !== "") {
|
||||
payload.messages.push({
|
||||
id: item.getAttribute('id'),
|
||||
role: "assistant",
|
||||
content: t.innerText.replace(/\n{2,}/g, '\n').trim()
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Reemplazar allMessages por payload en el resto del código
|
||||
// allMessages = payload;
|
||||
|
||||
console.log("Conversación en orden:\n" + JSON.stringify(payload, null, 2));
|
||||
Reference in New Issue
Block a user