From 39c7dd19725cc4e7ff1af4155f84e9c695a5d293 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 29 Mar 2026 14:31:09 +0000 Subject: [PATCH] Actualizar index2.html --- index2.html | 110 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 46 deletions(-) diff --git a/index2.html b/index2.html index 2f690b3..8cf4254 100644 --- a/index2.html +++ b/index2.html @@ -807,57 +807,75 @@ function summarizeDescription(rawText) { if (!rawText) return "Revisión técnica en el domicilio."; - // 1. Limpieza inicial de saltos de línea - let text = String(rawText).replace(/(\r\n|\n|\r)/gm, " "); - - // 2. Eliminar fechas, horas y marcas automáticas de los CRM (ej. 27/02/2026 - 15:44) - text = text.replace(/\(?\d{2}\/\d{2}\/\d{4}.{0,12}\d{2}:\d{2}\)?/g, " "); - text = text.replace(/\d{2}\/\d{2}\/\d{4}\s*-\s*/g, " "); - text = text.replace(/Texto manual/gi, " "); + let text = String(rawText); - // 3. Extracción de paja: Condiciones de seguros, notas internas, seguimientos y operadoras - const paja = [ - /COBERTURA.*?PROFESIONAL/gi, - /INDICO DEBE FACILITAR MATERIAL.*?REPARACIÓN/gi, - /INFO SERVICIOS DISPONIBLES/gi, - /CONFORME/gi, - /SERVICIOS PRESTADOS:?/gi, - /Primer contacto con cliente.*?(\.|$)/gi, - /Por seguimiento se desasigna.*?(\.|$)/gi, - /Cliente llama.*?(\.|$)/gi, - /LLAMA TOMADOR/gi, - /SOLICITA SERVICIO DE /gi, - /Enviar factura.*?Madrid/gi, - /\[PROPUESTA.*?\]/gi, - /Aver[ií]a:?/gi, /Descripci[oó]n:?/gi, /Motivo:?/gi, /Siniestro:?/gi, /Detalle:?/gi, - /\bM\.O\.?\b/gi, /\bMATERIALES?\b/gi, /\bASEGURADO\b/gi, /\bFRANQUICIA\b/gi, - /TEL[EÉ]FONO\s*\d+/gi, /\b[6789]\d{8}\b/g // Elimina teléfonos sueltos + // 1. Limpieza inicial: Quitar fechas y coletillas exactas que ensucian el corte + text = text.replace(/\(?\d{2}\/\d{2}\/\d{4}.{0,12}\d{2}:\d{2}\)?\s*-?/g, " "); // (23/02/2026 - 11:42) + text = text.replace(/\d{2}\/\d{2}\/\d{4}\s*-\s*/g, " "); // 17/02/2026 - + text = text.replace(/Descripción de la Averia/gi, " "); + text = text.replace(/Suceso:/gi, " "); + text = text.replace(/Texto manual/gi, " "); + text = text.replace(/DAñO_[0-9]:/gi, " "); + text = text.replace(/\(posible cobertura\)/gi, " "); + + // 2. Separar por saltos de línea reales O por dobles barras (//) típicas de Multiasistencia + let lines = text.split(/[\n]|(?:\/\/?)/); + + let validLines = []; + + // 3. LISTA NEGRA: Si la línea tiene alguna de estas palabras, es basura interna y se borra entera + const junkKeywords = [ + "cobro banco", "cobro contado", "servicio asignado", "sms", "enviado sms", + "cambio de estado", "este servicio requiere", "atención: el importe", + "el tipo de cobro", "siniestro comunicado", "cita confirmada", "visita al cliente", + "introducción ptto", "aplazamiento pte", "fecha y hora", "para el ofrecimiento", + "enviar factura", "declarante", "aviso nocita", "límite máximo", "importante", + "conectese via", "servicio con prof", "servicio sin prof", "servicio con la fecha", + "servicio desasignado", "comentario de desasignacion", "webservice", "alta servicio", + "alta avería", "alta reparación", "alta daños", "alta sin luz", "alta cambio", + "contacto con cliente", "fin previsto", "entrega presupuesto", "reparación con expediente", + "abierta reclamación", "llamada autom", "voicebot", "cliente informado por whatsapp", + "a espera de cita", "llamada entrante", "llamada saliente", "se ha introducido un importe", + "intento de llamada", "llamada de asegurado", "llama asegurad", "llamo a", + "servicio generado por proceso automático", "cubre", "cobertura", "daños propios", + "tipo de averia", "franja horaria", "agente", "oficina bbva", "repasar", + "revisado por perito", "perito tasa", "cita deseada", "rango horario" ]; - paja.forEach(regex => { - text = text.replace(regex, " "); - }); - - // 4. Limpiar símbolos sobrantes (barras, guiones o comas repetidas tras la limpieza) - text = text.replace(/[\/]+/g, ", "); - text = text.replace(/[-_]{2,}/g, " "); - text = text.replace(/\s{2,}/g, " ").trim(); - text = text.replace(/^[,.\s]+/, ""); - - // Si al limpiar todo se nos ha quedado vacío, ponemos un texto por defecto - if (text.length < 5) return "Revisión técnica en el domicilio."; - - // 5. Toque IA: Convertir los gritos (TODO MAYÚSCULAS) en un texto agradable y humano - text = text.toLowerCase(); - text = text.replace(/(^\w|\.\s*\w)/g, match => match.toUpperCase()); - - // 6. Ya no cortamos a 20 palabras, dejamos toda la información útil. - // Solo aplicamos un cortafuegos si el texto es escandalosamente gigante (más de 300 caracteres). - if (text.length > 300) { - text = text.substring(0, 300).trim() + "..."; + for (let line of lines) { + let cleanLine = line.trim(); + if (cleanLine.length < 12) continue; // Ignorar códigos o números sueltos + + let isJunk = junkKeywords.some(keyword => cleanLine.toLowerCase().includes(keyword)); + if (!isJunk) { + // Limpiar asteriscos y basura suelta + cleanLine = cleanLine.replace(/[\*\_]+/g, "").trim(); + if(cleanLine.length > 5) validLines.push(cleanLine); + } } - return text.endsWith('.') || text.endsWith('...') ? text : text + "."; + // Si después de la escabechina nos quedamos sin nada, ponemos el texto base + if (validLines.length === 0) return "Revisión técnica en el domicilio."; + + // 4. EL MAGO: Nos quedamos única y exclusivamente con la primera frase válida + let finalSummary = validLines[0]; + + // Limpieza estética final + finalSummary = finalSummary.replace(/[\/]+/g, ", ") + .replace(/[-_]{2,}/g, " ") + .replace(/\s{2,}/g, " ") + .trim(); + + // Transformar MAYÚSCULAS en texto normal para que no parezca que gritamos + finalSummary = finalSummary.toLowerCase(); + finalSummary = finalSummary.charAt(0).toUpperCase() + finalSummary.slice(1); + + // Cortar si es escandalosamente largo (más de 150 caracteres) + if (finalSummary.length > 150) { + finalSummary = finalSummary.substring(0, 150).trim() + "..."; + } + + return finalSummary.endsWith('.') || finalSummary.endsWith('...') ? finalSummary : finalSummary + "."; } function addOneHour(timeStr) {