Actualizar server.js
This commit is contained in:
17
server.js
17
server.js
@@ -637,11 +637,13 @@ async function triggerWhatsAppEvent(ownerId, serviceId, eventType) {
|
||||
// 2. Buscamos qué plantilla corresponde a este evento
|
||||
const tplTypeMap = {
|
||||
'wa_evt_welcome': 'welcome',
|
||||
'wa_evt_date': 'appointment', // Plantilla: Cita Creada
|
||||
'wa_evt_update': 'update', // Plantilla: Modificación de Servicio
|
||||
'wa_evt_assigned': 'assigned', // <--- NUEVO: Asignado a operario
|
||||
'wa_evt_date': 'appointment',
|
||||
'wa_evt_update': 'update',
|
||||
'wa_evt_onway': 'on_way',
|
||||
'wa_evt_survey': 'survey'
|
||||
};
|
||||
|
||||
const tplQ = await pool.query("SELECT content FROM message_templates WHERE owner_id=$1 AND type=$2", [ownerId, tplTypeMap[eventType]]);
|
||||
if (tplQ.rowCount === 0 || !tplQ.rows[0].content) return;
|
||||
let text = tplQ.rows[0].content;
|
||||
@@ -964,6 +966,17 @@ app.put("/services/set-appointment/:id", authMiddleware, async (req, res) => {
|
||||
const statusQ = await pool.query("SELECT name FROM service_statuses WHERE id=$1", [status_operativo]);
|
||||
const stName = statusQ.rows[0]?.name.toLowerCase() || "";
|
||||
|
||||
// ... dentro de la lógica del Motor en set-appointment ...
|
||||
const stName = statusQ.rows[0]?.name.toLowerCase() || "";
|
||||
|
||||
if (stName.includes('asignado')) {
|
||||
// Si el estado contiene "asignado", disparamos el nuevo evento
|
||||
triggerWhatsAppEvent(req.user.accountId, id, 'wa_evt_assigned');
|
||||
} else if (stName.includes('citado') && newDate !== "") {
|
||||
// ... resto de lógica que ya tenemos ...
|
||||
|
||||
|
||||
|
||||
// REGLA ESTRICTA: ¿Es estado Citado y tiene fecha?
|
||||
if (stName.includes('citado') && newDate !== "") {
|
||||
if (oldDate === "") {
|
||||
|
||||
Reference in New Issue
Block a user