Actualizar robot.js
This commit is contained in:
20
robot.js
20
robot.js
@@ -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) {
|
async function runHomeserve(ownerId, user, pass, gremiosDB) {
|
||||||
const browser = await chromium.launch({
|
const browser = await chromium.launch({
|
||||||
@@ -288,20 +288,29 @@ async function runHomeserve(ownerId, user, pass, gremiosDB) {
|
|||||||
|
|
||||||
const scrapData = await page.evaluate(() => {
|
const scrapData = await page.evaluate(() => {
|
||||||
const d = {};
|
const d = {};
|
||||||
|
let isUrgent = "No"; // <-- EMPEZAMOS ASUMIENDO QUE NO ES URGENTE
|
||||||
|
|
||||||
const rows = Array.from(document.querySelectorAll('tr'));
|
const rows = Array.from(document.querySelectorAll('tr'));
|
||||||
rows.forEach(r => {
|
rows.forEach(r => {
|
||||||
const cells = r.querySelectorAll('td');
|
const cells = r.querySelectorAll('td');
|
||||||
if (cells.length >= 2) {
|
if (cells.length >= 2) {
|
||||||
const k = cells[0].innerText.toUpperCase().trim().replace(':', '');
|
const k = cells[0].innerText.toUpperCase().trim().replace(':', '');
|
||||||
const v = cells[1].innerText.trim();
|
const v = cells[1].innerText.trim();
|
||||||
|
|
||||||
if (k.includes("COMENTARIOS")) {
|
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 inputEl = cells[1].querySelector('textarea');
|
||||||
const txt = inputEl ? inputEl.value : (cells[1].innerText || "");
|
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 cleanDesc = txt.split('\n').filter(line => {
|
||||||
const l = line.toUpperCase();
|
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();
|
}).join('\n').trim();
|
||||||
d['Descripción'] = cleanDesc;
|
d['Descripción'] = cleanDesc;
|
||||||
} else if (k.length > 1 && v.length > 0 && !k.includes("MENU")) {
|
} 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 rawPop = d['POBLACION-PROVINCIA'] || "";
|
||||||
const cpMatch = rawPop.match(/\b\d{5}\b/);
|
const cpMatch = rawPop.match(/\b\d{5}\b/);
|
||||||
d['Código Postal'] = cpMatch ? cpMatch[0] : "";
|
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['Compañía'] = "HOME - " + (d['COMPAÑIA'] || "HOMESERVE");
|
||||||
d['Nombre Cliente'] = d['CLIENTE'] || "";
|
d['Nombre Cliente'] = d['CLIENTE'] || "";
|
||||||
d['Dirección'] = d['DOMICILIO'] || "";
|
d['Dirección'] = d['DOMICILIO'] || "";
|
||||||
|
|
||||||
|
// INYECTAMOS LA URGENCIA AL ESTILO MULTIASISTENCIA
|
||||||
|
d['Urgente'] = isUrgent;
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user