Actualizar fserver.js
This commit is contained in:
@@ -629,17 +629,19 @@ async function triggerWhatsAppEvent(ownerId, serviceId, eventType) {
|
||||
// 1. Miramos si la empresa tiene el botón encendido
|
||||
const userQ = await pool.query("SELECT wa_settings FROM users WHERE id=$1", [ownerId]);
|
||||
const settings = userQ.rows[0]?.wa_settings || {};
|
||||
if (!settings[eventType]) return; // Si el botón está apagado, salimos
|
||||
|
||||
// TRUCO: Si es Modificación, usamos el valor del botón "Cambio de Cita" (wa_evt_date)
|
||||
const checkSwitch = eventType === 'wa_evt_update' ? 'wa_evt_date' : eventType;
|
||||
if (!settings[checkSwitch]) return; // Si el botón está apagado, salimos
|
||||
|
||||
// 2. Buscamos qué plantilla corresponde a este evento
|
||||
const tplTypeMap = {
|
||||
'wa_evt_welcome': 'welcome',
|
||||
'wa_evt_date': 'appointment',
|
||||
'wa_evt_update': 'update', // <--- AÑADIDO: Modificación de cita
|
||||
'wa_evt_date': 'appointment', // Plantilla: Cita Creada
|
||||
'wa_evt_update': 'update', // Plantilla: Modificación de Servicio
|
||||
'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;
|
||||
Reference in New Issue
Block a user