Actualizar server.js
This commit is contained in:
@@ -661,21 +661,22 @@ async function triggerWhatsAppEvent(ownerId, serviceId, eventType) {
|
|||||||
const linkMagico = `https://portal.integrarepara.es/?token=${token}`;
|
const linkMagico = `https://portal.integrarepara.es/?token=${token}`;
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// 🔄 5. TRADUCTOR DE FECHAS AL FORMATO ESPAÑOL
|
// 🔄 5. TRADUCTOR DE FECHAS AL FORMATO ESPAÑOL + DÍA
|
||||||
// ==========================================
|
// ==========================================
|
||||||
let fechaLimpia = raw["scheduled_date"] || "la fecha acordada";
|
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("-")) {
|
if (fechaLimpia.includes("-")) {
|
||||||
const partes = fechaLimpia.split("-");
|
const partes = fechaLimpia.split("-");
|
||||||
if (partes.length === 3) {
|
if (partes.length === 3) {
|
||||||
fechaLimpia = `${partes[2]}/${partes[1]}/${partes[0]}`;
|
const fechaObj = new Date(partes[0], partes[1] - 1, partes[2], 12, 0, 0);
|
||||||
|
const diaSemana = fechaObj.toLocaleDateString('es-ES', { weekday: 'long' });
|
||||||
|
fechaLimpia = `(${diaSemana}) ${partes[2]}/${partes[1]}/${partes[0]}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Reemplazamos las variables
|
// 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, fechaLimpia); // <--- Usamos la fecha ya formateada
|
text = text.replace(/{{FECHA}}/g, fechaLimpia);
|
||||||
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 || "");
|
||||||
|
|||||||
Reference in New Issue
Block a user