Actualizar server.js
This commit is contained in:
18
server.js
18
server.js
@@ -660,16 +660,28 @@ async function triggerWhatsAppEvent(ownerId, serviceId, eventType) {
|
|||||||
const token = clientQ.rowCount > 0 ? clientQ.rows[0].portal_token : "ERROR";
|
const token = clientQ.rowCount > 0 ? clientQ.rows[0].portal_token : "ERROR";
|
||||||
const linkMagico = `https://portal.integrarepara.es/?token=${token}`;
|
const linkMagico = `https://portal.integrarepara.es/?token=${token}`;
|
||||||
|
|
||||||
// 5. Reemplazamos las variables
|
// ==========================================
|
||||||
|
// 🔄 5. TRADUCTOR DE FECHAS AL FORMATO ESPAÑOL
|
||||||
|
// ==========================================
|
||||||
|
let fechaLimpia = raw["scheduled_date"] || "la fecha acordada";
|
||||||
|
// Si la fecha viene como 2026-02-22, la partimos y le damos la vuelta a 22/02/2026
|
||||||
|
if (fechaLimpia.includes("-")) {
|
||||||
|
const partes = fechaLimpia.split("-");
|
||||||
|
if (partes.length === 3) {
|
||||||
|
fechaLimpia = `${partes[2]}/${partes[1]}/${partes[0]}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. Reemplazamos las variables
|
||||||
text = text.replace(/{{NOMBRE}}/g, raw["Nombre Cliente"] || raw["CLIENTE"] || "Cliente");
|
text = text.replace(/{{NOMBRE}}/g, raw["Nombre Cliente"] || raw["CLIENTE"] || "Cliente");
|
||||||
text = text.replace(/{{DIRECCION}}/g, raw["Dirección"] || raw["DOMICILIO"] || "su domicilio");
|
text = text.replace(/{{DIRECCION}}/g, raw["Dirección"] || raw["DOMICILIO"] || "su domicilio");
|
||||||
text = text.replace(/{{FECHA}}/g, raw["scheduled_date"] || "la fecha acordada");
|
text = text.replace(/{{FECHA}}/g, fechaLimpia); // <--- Usamos la fecha ya formateada
|
||||||
text = text.replace(/{{HORA}}/g, raw["scheduled_time"] || "la hora acordada");
|
text = text.replace(/{{HORA}}/g, raw["scheduled_time"] || "la hora acordada");
|
||||||
text = text.replace(/{{COMPANIA}}/g, raw["Compañía"] || raw["COMPAÑIA"] || "su Aseguradora");
|
text = text.replace(/{{COMPANIA}}/g, raw["Compañía"] || raw["COMPAÑIA"] || "su Aseguradora");
|
||||||
text = text.replace(/{{REFERENCIA}}/g, s.service_ref || "");
|
text = text.replace(/{{REFERENCIA}}/g, s.service_ref || "");
|
||||||
text = text.replace(/{{ENLACE}}/g, linkMagico);
|
text = text.replace(/{{ENLACE}}/g, linkMagico);
|
||||||
|
|
||||||
// 6. Disparamos el mensaje
|
// 7. Disparamos el mensaje
|
||||||
const useDelay = settings.wa_delay_enabled !== false;
|
const useDelay = settings.wa_delay_enabled !== false;
|
||||||
await sendWhatsAppAuto(phone, text, `cliente_${ownerId}`, useDelay);
|
await sendWhatsAppAuto(phone, text, `cliente_${ownerId}`, useDelay);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user