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})\]/);
|
const matchPropuesta = respuestaIA.match(/\[PROPUESTA:(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2})\]/);
|
||||||
|
|
||||||
if (matchPropuesta) {
|
if (matchPropuesta) {
|
||||||
const fechaSugerida = matchPropuesta[1];
|
const fechaSugerida = matchPropuesta[1];
|
||||||
const horaSugerida = matchPropuesta[2];
|
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)
|
// Actualizamos el siniestro indicando que hay una propuesta pendiente
|
||||||
await pool.query(`
|
// 💡 HEMOS AÑADIDO ::text a los parámetros para solucionar el error
|
||||||
UPDATE scraped_services
|
await pool.query(`
|
||||||
SET raw_data = raw_data || jsonb_build_object(
|
UPDATE scraped_services
|
||||||
'propuesta_cliente_fecha', $1,
|
SET raw_data = raw_data || jsonb_build_object(
|
||||||
'propuesta_cliente_hora', $2,
|
'propuesta_cliente_fecha', $1::text,
|
||||||
'status_ia', 'esperando_confirmacion_humana'
|
'propuesta_cliente_hora', $2::text,
|
||||||
)
|
'status_ia', 'esperando_confirmacion_humana'
|
||||||
WHERE id = $3
|
)
|
||||||
`, [fechaSugerida, horaSugerida, service.id]);
|
WHERE id = $3
|
||||||
|
`, [fechaSugerida, horaSugerida, service.id]);
|
||||||
|
|
||||||
// Registramos el movimiento para que salga en el historial del servicio
|
// Registramos el movimiento para que el operario vea la notificación
|
||||||
await registrarMovimiento(
|
await registrarMovimiento(
|
||||||
service.id,
|
service.id,
|
||||||
null,
|
null,
|
||||||
"Propuesta de Cita",
|
"Propuesta de Cita",
|
||||||
`El cliente solicita cita para el ${fechaSugerida} a las ${horaSugerida}. Pendiente de confirmación por el operario.`
|
`El cliente solicita cita para el ${fechaSugerida} a las ${horaSugerida}. Pendiente de confirmación por operario.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. --- LIMPIEZA Y ENVÍO ---
|
// 2. --- LIMPIEZA Y ENVÍO ---
|
||||||
// Quitamos el código [PROPUESTA:...] del texto para que el cliente no lo vea
|
// Quitamos el código [PROPUESTA:...] del texto para que el cliente no lo vea
|
||||||
|
|||||||
Reference in New Issue
Block a user