// ========================================== // 🎯 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 }); } });