Fix node fetch issue by using http.request
This commit is contained in:
parent
a43b8e5db7
commit
720d740582
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue