From 4bebdb06ef4ca49f891b0717a2ef332a9f3d7e5a Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 17 May 2026 21:29:19 +0000 Subject: [PATCH] =?UTF-8?q?A=C3=B1adir=20publi.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publi.html | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 publi.html diff --git a/publi.html b/publi.html new file mode 100644 index 0000000..31604d2 --- /dev/null +++ b/publi.html @@ -0,0 +1,32 @@ +// ========================================== +// 🎯 RUTA PARA CUANDO EL CLIENTE PULSA "ME INTERESA" EN PUBLICIDAD +// ========================================== +app.post("/public/portal/:token/interest", async (req, res) => { + try { + const { token } = req.params; + + // 1. Buscamos quién es el cliente usando su token + const clientQ = await pool.query("SELECT owner_id, full_name, phone FROM clients WHERE portal_token = $1 LIMIT 1", [token]); + if (clientQ.rowCount === 0) return res.status(404).json({ ok: false, error: "Token inválido" }); + + const client = clientQ.rows[0]; + const ownerId = client.owner_id; + + // 2. Buscamos el teléfono del administrador (tú) para avisarte + const ownerQ = await pool.query("SELECT phone FROM users WHERE id = $1", [ownerId]); + if (ownerQ.rowCount === 0) return res.status(404).json({ ok: false, error: "Empresa no encontrada" }); + + const adminPhone = ownerQ.rows[0].phone; + + // 3. Montamos el mensaje de WhatsApp para el jefe + const msgWa = `🎉 *¡NUEVO LEAD DE PUBLICIDAD!* 🎉\n\nEl cliente *${client.full_name}* ha pulsado el botón "Me interesa" en el banner de publicidad de su portal web.\n\n📞 *Teléfono:* ${client.phone}\n\n¡Llámale cuanto antes para informarle!`; + + // 4. Enviamos el mensaje + await sendWhatsAppAuto(adminPhone, msgWa, `cliente_${ownerId}`, false); + + res.json({ ok: true }); + } catch (e) { + console.error("Error al registrar interés en publicidad:", e); + res.status(500).json({ ok: false }); + } +}); \ No newline at end of file