Actualizar server.js

This commit is contained in:
2026-03-07 21:50:23 +00:00
parent c89f1c5b24
commit 9883a848b7

View File

@@ -445,19 +445,33 @@ async function procesarConIA(ownerId, mensajeCliente, datosExpediente) {
const opciones = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }; const opciones = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
const fechaHoyTexto = ahora.toLocaleDateString('es-ES', opciones); const fechaHoyTexto = ahora.toLocaleDateString('es-ES', opciones);
// 🧠 MEMORIA: Comprobar si ha habido mensajes en los últimos 60 minutos
// Usamos datosExpediente.dbId que le pasaremos desde el webhook
const chatCheck = await pool.query(`
SELECT id FROM service_communications
WHERE scraped_id = $1
AND created_at > NOW() - INTERVAL '60 minutes'
LIMIT 1
`, [datosExpediente.dbId]);
const yaSeHaPresentado = chatCheck.rowCount > 0;
const promptSistema = ` const promptSistema = `
Eres el Asistente IA de "${empresaNombre}". Eres el Asistente IA de "${empresaNombre}".
CONTEXTO TEMPORAL: CONTEXTO TEMPORAL:
- Hoy es: ${fechaHoyTexto}. - Hoy es: ${fechaHoyTexto}.
- Estamos en el año 2026. Úsalo para calcular fechas si el cliente dice "el lunes" o "mañana". - Estamos en el año 2026. Úsalo para calcular fechas.
DATOS DEL EXPEDIENTE #${datosExpediente.ref}: DATOS DEL EXPEDIENTE #${datosExpediente.ref}:
- Estado: ${datosExpediente.estado} - Estado: ${datosExpediente.estado}
- Cita actual registrada: ${datosExpediente.cita || 'Ninguna'} - Cita actual registrada: ${datosExpediente.cita || 'Ninguna'}
PRESENTACIÓN (IMPORTANTE): PRESENTACIÓN:
- Si el cliente te saluda por primera vez o es el inicio de la charla, preséntate así: "Hola, soy el asistente virtual de ${empresaNombre}. Estoy aquí para ayudarte con tu expediente #${datosExpediente.ref}." ${!yaSeHaPresentado
? `- Al ser el primer mensaje, preséntate: "Hola, soy el asistente virtual de ${empresaNombre}. Estoy aquí para ayudarte con tu expediente #${datosExpediente.ref}."`
: `- YA TE HAS PRESENTADO. No digas hola, ni quién eres, ni el número de expediente. Ve directo a responder al cliente de forma natural.`
}
REGLA DE CITAS (CRÍTICA): REGLA DE CITAS (CRÍTICA):
- Tú NO confirmas citas finales, solo recoges la preferencia del cliente. - Tú NO confirmas citas finales, solo recoges la preferencia del cliente.
@@ -469,7 +483,7 @@ async function procesarConIA(ownerId, mensajeCliente, datosExpediente) {
1. Si el cliente pregunta "¿Cuándo venís?", usa la "Cita actual registrada". Si no hay, di que la oficina contactará con él. 1. Si el cliente pregunta "¿Cuándo venís?", usa la "Cita actual registrada". Si no hay, di que la oficina contactará con él.
2. NUNCA inventes precios. 2. NUNCA inventes precios.
3. Ante enfados, deriva a un humano con amabilidad. 3. Ante enfados, deriva a un humano con amabilidad.
4. Responde en máximo 2 o 3 frases cortas. 4. Responde en máximo 2 frases. Sé muy natural.
5. No uses negritas (**), usa asteriscos (*) si es vital resaltar algo. 5. No uses negritas (**), usa asteriscos (*) si es vital resaltar algo.
`; `;