Fix: notificacion WhatsApp cita al convertir presupuesto usa plantilla
This commit is contained in:
22
server.js
22
server.js
@@ -5227,18 +5227,12 @@ app.post("/budgets/:id/convert", authMiddleware, async (req, res) => {
|
||||
},
|
||||
body: JSON.stringify({ guild_id, cp, useDelay: false })
|
||||
}).catch(e => console.error("Error lanzando automatización interna:", e));
|
||||
|
||||
if (budget.client_phone) {
|
||||
const msg = `✅ *PRESUPUESTO ACEPTADO*\n\nHola ${budget.client_name}, confirmamos la aceptación del presupuesto por un total de *${budget.total}€*.\n\nEn breve un técnico se pondrá en contacto contigo para agendar la cita. ¡Gracias por confiar en nosotros!`;
|
||||
sendWhatsAppAuto(budget.client_phone, msg, `cliente_${req.user.accountId}`, false).catch(console.error);
|
||||
}
|
||||
}
|
||||
else if (budget.client_phone && date && time) {
|
||||
// Asignación directa a un técnico con fecha y hora
|
||||
const [y, m, d] = date.split('-');
|
||||
const msg = `✅ *PRESUPUESTO ACEPTADO*\n\nHola ${budget.client_name}, confirmamos la aceptación del presupuesto por un total de *${budget.total}€*.\n\nEl servicio ha sido agendado para el *${d}/${m}/${y} a las ${time}*. ¡Gracias por confiar en nosotros!`;
|
||||
sendWhatsAppAuto(budget.client_phone, msg, `cliente_${req.user.accountId}`, false).catch(console.error);
|
||||
|
||||
}
|
||||
|
||||
if (budget.client_phone && date && time) {
|
||||
// Cita ya agendada (fecha y técnico asignados): usamos la plantilla "Cita Creada" configurada en Configuración > Plantillas
|
||||
triggerWhatsAppEvent(req.user.accountId, newServiceId, 'wa_evt_date').catch(console.error);
|
||||
|
||||
if (assigned_to) {
|
||||
const statusQ = await pool.query("SELECT id FROM service_statuses WHERE owner_id=$1 AND name ILIKE '%asignado%' LIMIT 1", [req.user.accountId]);
|
||||
if (statusQ.rowCount > 0) {
|
||||
@@ -5246,6 +5240,10 @@ app.post("/budgets/:id/convert", authMiddleware, async (req, res) => {
|
||||
await pool.query("UPDATE scraped_services SET raw_data = $1 WHERE id = $2", [JSON.stringify(rawData), newServiceId]);
|
||||
}
|
||||
}
|
||||
} else if (budget.client_phone) {
|
||||
|
||||
const msg = `✅ *PRESUPUESTO ACEPTADO*\n\nHola ${budget.client_name}, confirmamos la aceptación del presupuesto por un total de *${budget.total}€*.\n\nEn breve un técnico se pondrá en contacto contigo para agendar la cita. ¡Gracias por confiar en nosotros!`;
|
||||
sendWhatsAppAuto(budget.client_phone, msg, `cliente_${req.user.accountId}`, false).catch(console.error);
|
||||
}
|
||||
|
||||
// --- INICIO TRAZABILIDAD ---
|
||||
|
||||
Reference in New Issue
Block a user