Fix node fetch issue by using http.request

This commit is contained in:
Deep Koluguri 2026-06-19 16:41:44 -04:00
parent a43b8e5db7
commit 720d740582
1 changed files with 23 additions and 9 deletions

View File

@ -111,17 +111,31 @@ client.on('message_create', async msg => {
const targetJid = msg.fromMe ? msg.to : msg.from; const targetJid = msg.fromMe ? msg.to : msg.from;
try { try {
await fetch(AGENTS_API_URL, { const data = JSON.stringify({
method: 'POST', text: text,
headers: { 'Content-Type': 'application/json' }, sender: msg.author || msg.from,
body: JSON.stringify({ targetJid: targetJid
text: text,
sender: msg.author || msg.from,
targetJid: targetJid
})
}); });
const url = new URL(AGENTS_API_URL);
const req = require('http').request({
hostname: url.hostname,
port: url.port || 80,
path: url.pathname,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}, (res) => {
let body = '';
res.on('data', chunk => body += chunk);
res.on('end', () => console.log(`[WhatsApp Bot] Forwarded to agents-runtime. Status: ${res.statusCode}, Body: ${body}`));
});
req.on('error', (err) => console.error('[WhatsApp Bot] Failed to forward message:', err));
req.write(data);
req.end();
} catch (err) { } catch (err) {
console.error('[WhatsApp Bot] Failed to forward message to agents-runtime:', err.message); console.error('[WhatsApp Bot] Failed to execute http.request:', err);
} }
} }
}); });