diff --git a/servicios.html b/servicios.html
index e4caa63..a3f04a2 100644
--- a/servicios.html
+++ b/servicios.html
@@ -458,7 +458,6 @@
// --- EXTRACCIÓN INTELIGENTE DE UN SOLO TELÉFONO ---
const rawPhone = raw["Teléfono"] || raw["TELEFONOS"] || raw["TELEFONO"] || "";
- // Extrae el primer número que empiece por 6,7,8 o 9 y tenga 9 dígitos
const matchPhone = rawPhone.toString().match(/[6789]\d{8}/);
const singlePhone = matchPhone ? matchPhone[0] : "";
@@ -547,7 +546,6 @@
const btn = document.getElementById('btnAuto');
btn.innerHTML = '';
- // Leemos si el usuario tiene activado el retraso (es true por defecto)
const savedSetting = localStorage.getItem('wa_delay_enabled');
const useDelay = savedSetting === null ? true : savedSetting === 'true';
@@ -555,7 +553,6 @@
const res = await fetch(`${API_URL}/providers/automate/${id}`, {
method: 'POST',
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
- // Añadimos useDelay al payload que va al servidor
body: JSON.stringify({ guild_id, cp, useDelay })
});
const data = await res.json();
@@ -629,8 +626,12 @@
if(data.ok) sel.innerHTML = '' + data.operators.map(o => ``).join('');
}
+ // ====== AQUÍ ESTÁ LA NUEVA FUNCIÓN CORREGIDA ======
async function copyClientPortalLink() {
const phone = document.getElementById('detPhone').innerText;
+ const name = document.getElementById('detName').innerText;
+ const addr = document.getElementById('detAddrText').innerText;
+
if (!phone || phone === "Sin Teléfono") {
showToast("No hay un teléfono válido para este cliente.", "warning");
return;
@@ -639,13 +640,18 @@
const btn = document.getElementById('btnPortalLink');
const originalHtml = btn.innerHTML;
- // Animación de carga en el botón
btn.innerHTML = ' Generando...';
lucide.createIcons();
try {
- const res = await fetch(`${API_URL}/clients/search?phone=${encodeURIComponent(phone)}`, {
- headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
+ // Ahora usamos /ensure en lugar de /search, y enviamos los datos por POST
+ const res = await fetch(`${API_URL}/clients/ensure`, {
+ method: 'POST',
+ headers: {
+ "Content-Type": "application/json",
+ "Authorization": `Bearer ${localStorage.getItem("token")}`
+ },
+ body: JSON.stringify({ phone: phone, name: name, address: addr })
});
const data = await res.json();
@@ -665,7 +671,7 @@
lucide.createIcons();
}, 3000);
} else {
- showToast("El cliente aún no está registrado en la base de datos oficial.", "warning");
+ showToast("No se pudo generar el token. Revisa la consola.", "warning");
btn.innerHTML = originalHtml;
lucide.createIcons();
}