Actualizar index2.html

This commit is contained in:
2026-03-29 14:31:09 +00:00
parent 800fb1292c
commit 39c7dd1972

View File

@@ -807,57 +807,75 @@
function summarizeDescription(rawText) { function summarizeDescription(rawText) {
if (!rawText) return "Revisión técnica en el domicilio."; if (!rawText) return "Revisión técnica en el domicilio.";
// 1. Limpieza inicial de saltos de línea let text = String(rawText);
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, " ");
// 3. Extracción de paja: Condiciones de seguros, notas internas, seguimientos y operadoras // 1. Limpieza inicial: Quitar fechas y coletillas exactas que ensucian el corte
const paja = [ text = text.replace(/\(?\d{2}\/\d{2}\/\d{4}.{0,12}\d{2}:\d{2}\)?\s*-?/g, " "); // (23/02/2026 - 11:42)
/COBERTURA.*?PROFESIONAL/gi, text = text.replace(/\d{2}\/\d{2}\/\d{4}\s*-\s*/g, " "); // 17/02/2026 -
/INDICO DEBE FACILITAR MATERIAL.*?REPARACIÓN/gi, text = text.replace(/Descripción de la Averia/gi, " ");
/INFO SERVICIOS DISPONIBLES/gi, text = text.replace(/Suceso:/gi, " ");
/CONFORME/gi, text = text.replace(/Texto manual/gi, " ");
/SERVICIOS PRESTADOS:?/gi, text = text.replace(/DAñO_[0-9]:/gi, " ");
/Primer contacto con cliente.*?(\.|$)/gi, text = text.replace(/\(posible cobertura\)/gi, " ");
/Por seguimiento se desasigna.*?(\.|$)/gi,
/Cliente llama.*?(\.|$)/gi, // 2. Separar por saltos de línea reales O por dobles barras (//) típicas de Multiasistencia
/LLAMA TOMADOR/gi, let lines = text.split(/[\n]|(?:\/\/?)/);
/SOLICITA SERVICIO DE /gi,
/Enviar factura.*?Madrid/gi, let validLines = [];
/\[PROPUESTA.*?\]/gi,
/Aver[ií]a:?/gi, /Descripci[oó]n:?/gi, /Motivo:?/gi, /Siniestro:?/gi, /Detalle:?/gi, // 3. LISTA NEGRA: Si la línea tiene alguna de estas palabras, es basura interna y se borra entera
/\bM\.O\.?\b/gi, /\bMATERIALES?\b/gi, /\bASEGURADO\b/gi, /\bFRANQUICIA\b/gi, const junkKeywords = [
/TEL[EÉ]FONO\s*\d+/gi, /\b[6789]\d{8}\b/g // Elimina teléfonos sueltos "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 => { for (let line of lines) {
text = text.replace(regex, " "); let cleanLine = line.trim();
}); if (cleanLine.length < 12) continue; // Ignorar códigos o números sueltos
// 4. Limpiar símbolos sobrantes (barras, guiones o comas repetidas tras la limpieza) let isJunk = junkKeywords.some(keyword => cleanLine.toLowerCase().includes(keyword));
text = text.replace(/[\/]+/g, ", "); if (!isJunk) {
text = text.replace(/[-_]{2,}/g, " "); // Limpiar asteriscos y basura suelta
text = text.replace(/\s{2,}/g, " ").trim(); cleanLine = cleanLine.replace(/[\*\_]+/g, "").trim();
text = text.replace(/^[,.\s]+/, ""); if(cleanLine.length > 5) validLines.push(cleanLine);
}
// 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() + "...";
} }
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) { function addOneHour(timeStr) {