From 49ffa5e3158577f78c6e60328488489df6c1d9e5 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sat, 7 Mar 2026 22:07:37 +0000 Subject: [PATCH] Actualizar server.js --- server.js | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/server.js b/server.js index af12ffe..3697e48 100644 --- a/server.js +++ b/server.js @@ -3025,30 +3025,31 @@ app.post("/webhook/evolution", async (req, res) => { const matchPropuesta = respuestaIA.match(/\[PROPUESTA:(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2})\]/); if (matchPropuesta) { - const fechaSugerida = matchPropuesta[1]; - const horaSugerida = matchPropuesta[2]; + const fechaSugerida = matchPropuesta[1]; + const horaSugerida = matchPropuesta[2]; - console.log(`📅 PROPUESTA RECIBIDA: ${fechaSugerida} a las ${horaSugerida} para exp #${service.service_ref}`); + console.log(`📅 PROPUESTA RECIBIDA: ${fechaSugerida} a las ${horaSugerida} para exp #${service.service_ref}`); - // Actualizamos el siniestro indicando que hay una propuesta pendiente (sin confirmar cita final) - await pool.query(` - UPDATE scraped_services - SET raw_data = raw_data || jsonb_build_object( - 'propuesta_cliente_fecha', $1, - 'propuesta_cliente_hora', $2, - 'status_ia', 'esperando_confirmacion_humana' - ) - WHERE id = $3 - `, [fechaSugerida, horaSugerida, service.id]); + // Actualizamos el siniestro indicando que hay una propuesta pendiente + // 💡 HEMOS AÑADIDO ::text a los parámetros para solucionar el error + await pool.query(` + UPDATE scraped_services + SET raw_data = raw_data || jsonb_build_object( + 'propuesta_cliente_fecha', $1::text, + 'propuesta_cliente_hora', $2::text, + 'status_ia', 'esperando_confirmacion_humana' + ) + WHERE id = $3 + `, [fechaSugerida, horaSugerida, service.id]); - // Registramos el movimiento para que salga en el historial del servicio - await registrarMovimiento( - service.id, - null, - "Propuesta de Cita", - `El cliente solicita cita para el ${fechaSugerida} a las ${horaSugerida}. Pendiente de confirmación por el operario.` - ); - } + // Registramos el movimiento para que el operario vea la notificación + await registrarMovimiento( + service.id, + null, + "Propuesta de Cita", + `El cliente solicita cita para el ${fechaSugerida} a las ${horaSugerida}. Pendiente de confirmación por operario.` + ); + } // 2. --- LIMPIEZA Y ENVÍO --- // Quitamos el código [PROPUESTA:...] del texto para que el cliente no lo vea