Actualizar index2.html
This commit is contained in:
60
index2.html
60
index2.html
@@ -347,16 +347,58 @@
|
||||
|
||||
// --- FUNCIONES DE TEXTO Y FECHAS ---
|
||||
function summarizeDescription(rawText) {
|
||||
if (!rawText) return "Revisión técnica de avería 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).replace(/(\r\n|\n|\r)/gm, " ");
|
||||
const regexCorte = /(\bM\.O\b|\bMATERIAL\b|\bASEGURADO\b|\bTELEFONO\b|\bTEL\b|\bURGENTE\b|\bFRANQUICIA\b|\[PROPUESTA)/i;
|
||||
let cutPos = text.search(regexCorte);
|
||||
if (cutPos > 15) text = text.substring(0, cutPos);
|
||||
text = text.replace(/^(Aver[ií]a|Descripci[oó]n|Motivo|Siniestro|Detalle)[\s:]*/i, '').trim();
|
||||
if (text.length > 0) text = text.charAt(0).toUpperCase() + text.slice(1);
|
||||
let words = text.split(/\s+/);
|
||||
if (words.length > 20) text = words.slice(0, 20).join(" ") + "...";
|
||||
if (text.length < 5) return "Revisión general en el domicilio.";
|
||||
|
||||
// 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
|
||||
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
|
||||
];
|
||||
|
||||
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() + "...";
|
||||
}
|
||||
|
||||
return text.endsWith('.') || text.endsWith('...') ? text : text + ".";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user