From 720d7405825975f865bb59f2a29eabcdc80c1613 Mon Sep 17 00:00:00 2001 From: Deep Koluguri Date: Fri, 19 Jun 2026 16:41:44 -0400 Subject: [PATCH] Fix node fetch issue by using http.request --- whatsapp-gateway/server.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/whatsapp-gateway/server.js b/whatsapp-gateway/server.js index 272e2a1..a0971fa 100644 --- a/whatsapp-gateway/server.js +++ b/whatsapp-gateway/server.js @@ -111,17 +111,31 @@ client.on('message_create', async msg => { const targetJid = msg.fromMe ? msg.to : msg.from; try { - await fetch(AGENTS_API_URL, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - text: text, - sender: msg.author || msg.from, - targetJid: targetJid - }) + const data = JSON.stringify({ + 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) { - console.error('[WhatsApp Bot] Failed to forward message to agents-runtime:', err.message); + console.error('[WhatsApp Bot] Failed to execute http.request:', err); } } });