// Using native fetch async function setWebhook() { const apiUrl = process.env.EVOLUTION_API_URL || 'https://evolution.almeira.com.co'; const apiKey = process.env.EVOLUTION_API_KEY || 'mgXxu2eAwyhWNnptFEouUE6qLkvwVm6K'; const instance = process.env.EVOLUTION_INSTANCE_NAME || 'AutomataAlmeira'; // El destino de donde escuchará Evolution las respuestas const webhookTargetUrl = 'https://news.almeira.com.co/api/webhooks/whatsapp'; const payload = { webhook: { enabled: true, url: webhookTargetUrl, webhookByEvents: false, base64: false, events: [ "MESSAGES_UPSERT" ] } }; console.log("Configurando el Webhook en Evolution API..."); try { const response = await fetch(`${apiUrl}/webhook/set/${instance}`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'apikey': apiKey }, body: JSON.stringify(payload) }); const data = await response.json(); console.log(`Estado: HTTP ${response.status}`); console.log("Respuesta:", JSON.stringify(data, null, 2)); } catch (e) { console.error("Fallo:", e.message); } } setWebhook();