Actualizar robot.js
This commit is contained in:
38
robot.js
38
robot.js
@@ -158,20 +158,46 @@ async function runHomeserve(ownerId, user, pass) {
|
|||||||
const link = await page.getByText(ref).first();
|
const link = await page.getByText(ref).first();
|
||||||
if (await link.isVisible()) {
|
if (await link.isVisible()) {
|
||||||
await link.click(); await page.waitForTimeout(1500);
|
await link.click(); await page.waitForTimeout(1500);
|
||||||
|
// ... dentro de la función runHomeserve, en el evaluate del detalle:
|
||||||
|
|
||||||
const fullData = await page.evaluate(() => {
|
const fullData = await page.evaluate(() => {
|
||||||
const d = {};
|
const d = {};
|
||||||
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();
|
||||||
const v = cells[1].innerText.trim();
|
const v = cells[1].innerText.trim();
|
||||||
if(k.length > 1 && v.length > 0) d[k] = v;
|
|
||||||
|
// Si es la celda de COMENTARIOS (donde está el textarea)
|
||||||
|
if (k.includes("COMENTARIOS")) {
|
||||||
|
const textarea = cells[1].querySelector('textarea');
|
||||||
|
if (textarea) {
|
||||||
|
const rawText = textarea.value;
|
||||||
|
const lines = rawText.split('\n');
|
||||||
|
|
||||||
|
// FILTRO QUIRÚRGICO DE LÍNEAS
|
||||||
|
const cleanLines = lines.filter(line => {
|
||||||
|
const l = line.toUpperCase();
|
||||||
|
// Descartamos basura del sistema
|
||||||
|
if (l.includes("CAMBIO DE ESTADO")) return false;
|
||||||
|
if (l.includes("ESTADO ASIGNADO")) return false;
|
||||||
|
if (l.includes("SMS NO ENVIADO")) return false;
|
||||||
|
if (l.includes("CONTACTO CON PROF")) return false;
|
||||||
|
if (l.includes("CITA CONFIRMADA")) return false;
|
||||||
|
if (l.includes("0000")) return false; // Líneas vacías de sistema
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Nos quedamos con las 3 primeras líneas útiles (que suelen ser la descripción)
|
||||||
|
d['Descripción'] = cleanLines.slice(0, 3).join('\n').trim();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Captura normal de otros campos (CLIENTE, DOMICILIO, etc.)
|
||||||
|
const cleanKey = k.replace(':', '');
|
||||||
|
if (cleanKey.length > 1) d[cleanKey] = v;
|
||||||
}
|
}
|
||||||
if(cells.length >= 4) {
|
|
||||||
const k2 = cells[2].innerText.toUpperCase().trim().replace(':', '');
|
|
||||||
const v2 = cells[3].innerText.trim();
|
|
||||||
if(k2.length > 1 && v2.length > 0) d[k2] = v2;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return d;
|
return d;
|
||||||
|
|||||||
Reference in New Issue
Block a user