Actualizar server.js
This commit is contained in:
43
server.js
43
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
|
||||
|
||||
Reference in New Issue
Block a user