`;
- } else {
- // Si no está conectado, intentamos obtener el QR
- // Nota: En Evolution v2 el endpoint de QR puede variar, aquí asumo el estándar
+ } else if (data.qr) {
container.innerHTML = `
-
-
-
-
-
Desconectado
-
Escanea el QR para vincular
-
+
`;
-
- // Fetch QR (esto depende de la versión exacta de Evolution API)
- const resQr = await fetch(`${conf.url}/instance/connect/${conf.instance}`, { headers: { "apikey": conf.key } });
- const dataQr = await resQr.json();
- if(dataQr.code || dataQr.base64) {
- // Si recibimos base64, lo mostramos como imagen
- // Si recibimos string, usamos qrcode.js (si está cargado)
- const qrCode = dataQr.code || dataQr.base64;
- if(qrCode.startsWith('data:image')) {
- document.getElementById('qrcode').innerHTML = `

`;
- }
+
+ if(data.qr.startsWith('data:image')) {
+ document.getElementById('qrcode').innerHTML = `

`;
+ } else {
+ new QRCode(document.getElementById("qrcode"), { text: data.qr, width: 180, height: 180 });
}
+ } else {
+ container.innerHTML = `
Iniciando... intenta de nuevo en unos segundos.
`;
}
} catch(e) {
container.innerHTML = `
-
-
-
Error de conexión
-
Revisa la URL y la API Key
+
+
+
Error de conexión
+
${e.message}
`;
}
lucide.createIcons();
}
- // --- GESTIÓN DE PLANTILLAS (IGUAL QUE ANTES) ---
+ // --- GESTIÓN DE PLANTILLAS ---
async function loadTemplates() {
try {
const res = await fetch(`${API_URL}/templates`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });