Actualizar robot.js

This commit is contained in:
2026-03-15 13:01:36 +00:00
parent 0955acb487
commit e6dbe284c1

View File

@@ -239,7 +239,7 @@ async function runMultiasistencia(ownerId, user, pass, gremiosDB) {
}
// ==========================================
// 🧹 HOMESERVE
// 🧹 HOMESERVE (ROBOT MEJORADO Y DETECTOR DE URGENCIAS)
// ==========================================
async function runHomeserve(ownerId, user, pass, gremiosDB) {
const browser = await chromium.launch({
@@ -288,20 +288,29 @@ async function runHomeserve(ownerId, user, pass, gremiosDB) {
const scrapData = await page.evaluate(() => {
const d = {};
let isUrgent = "No"; // <-- EMPEZAMOS ASUMIENDO QUE NO ES URGENTE
const rows = Array.from(document.querySelectorAll('tr'));
rows.forEach(r => {
const cells = r.querySelectorAll('td');
if (cells.length >= 2) {
const k = cells[0].innerText.toUpperCase().trim().replace(':', '');
const v = cells[1].innerText.trim();
if (k.includes("COMENTARIOS")) {
// CORRECCIÓN: Evitamos perder el texto si no está dentro de un <textarea> y no lo limitamos a 3 líneas
const inputEl = cells[1].querySelector('textarea');
const txt = inputEl ? inputEl.value : (cells[1].innerText || "");
// 🔥 DETECTOR DE URGENCIA ANTES DE LIMPIAR 🔥
const txtLower = txt.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
if (txtLower.includes("atencion presencial urgencias") || txtLower.includes("atencion de la urgencia") || txtLower.includes("urgente")) {
isUrgent = "Sí"; // Si pilla la urgencia, la guarda.
}
const cleanDesc = txt.split('\n').filter(line => {
const l = line.toUpperCase();
return !["CAMBIO DE ESTADO", "ESTADO ASIGNADO", "SMS NO ENVIADO", "CONTACTO CON PROF", "0000"].some(b => l.includes(b));
// Quitamos los filtros destructivos que borraban el "Cambio de estado"
return !["ESTADO ASIGNADO", "SMS NO ENVIADO", "CONTACTO CON PROF", "0000"].some(b => l.includes(b));
}).join('\n').trim();
d['Descripción'] = cleanDesc;
} else if (k.length > 1 && v.length > 0 && !k.includes("MENU")) {
@@ -309,6 +318,7 @@ async function runHomeserve(ownerId, user, pass, gremiosDB) {
}
}
});
const rawPop = d['POBLACION-PROVINCIA'] || "";
const cpMatch = rawPop.match(/\b\d{5}\b/);
d['Código Postal'] = cpMatch ? cpMatch[0] : "";
@@ -316,6 +326,10 @@ async function runHomeserve(ownerId, user, pass, gremiosDB) {
d['Compañía'] = "HOME - " + (d['COMPAÑIA'] || "HOMESERVE");
d['Nombre Cliente'] = d['CLIENTE'] || "";
d['Dirección'] = d['DOMICILIO'] || "";
// INYECTAMOS LA URGENCIA AL ESTILO MULTIASISTENCIA
d['Urgente'] = isUrgent;
return d;
});