From 343b9b0d4af0105fbdad63b2fbc3b3d6522176b0 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 8 Mar 2026 11:21:41 +0000 Subject: [PATCH] Actualizar server.js --- server.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 1ae7c3e..7270633 100644 --- a/server.js +++ b/server.js @@ -440,8 +440,17 @@ async function procesarConIA(ownerId, mensajeCliente, datosExpediente) { const userQ = await pool.query("SELECT wa_settings, full_name, portal_settings FROM users WHERE id=$1", [ownerId]); const userData = userQ.rows[0]; const settings = userData?.wa_settings || {}; + const instruccionesExtra = settings.ai_custom_prompt || ""; const empresaNombre = userData?.full_name || "nuestra empresa"; - const horarios = userData?.portal_settings || { m_start: "09:00", m_end: "14:00", a_start: "16:00", a_end: "19:00" }; + + // 🛠️ BLINDAJE DE HORARIOS: Extraemos campo a campo para evitar fallos de lectura + const pSettings = userData?.portal_settings || {}; + const horarios = { + m_start: pSettings.m_start || "09:00", + m_end: pSettings.m_end || "14:00", + a_start: pSettings.a_start || "16:00", + a_end: pSettings.a_end || "19:00" + }; if (!settings.wa_ai_enabled) return null; @@ -541,6 +550,9 @@ async function procesarConIA(ownerId, mensajeCliente, datosExpediente) { --- 🎯 DIRECTIVA ESTRICTA PARA ESTE MENSAJE --- ${directivaEstricta} + --- 📝 INSTRUCCIONES PERSONALIZADAS DE LA EMPRESA --- + ${instruccionesExtra ? instruccionesExtra : 'No hay reglas extra.'} + --- REGLAS DE ORO DE COMUNICACIÓN --- 1. Máximo 2 frases. Los mensajes de WhatsApp deben ser cortos. 2. Lee el historial de la conversación. Si el cliente solo responde "Ok" o "Gracias", dile "De nada, aquí estamos para lo que necesites" y cierra la charla. No le des la chapa.