From f01f921d21441149ba39f86339e5fefce7b4c3a5 Mon Sep 17 00:00:00 2001 From: Gustavo Gonzaga Date: Mon, 21 Sep 2026 13:32:42 -0300 Subject: [PATCH] fix: use a Node-compatible proxy agent for Baileys media upload Baileys 7.0.0-rc13 performs media uploads with Node's native http/https modules instead of fetch/Undici, and passes the fetchAgent option straight to http.request as its `agent`. An Undici ProxyAgent does not implement Node's Agent interface, so every media upload fails as soon as an instance has a proxy configured. The failure is easy to misdiagnose because text messages keep working: they go through the websocket, which already uses the Node agent. Only uploads break, with PTT audio returning "400 Media upload failed on all hosts" and video uploads timing out. Build fetchAgent with makeProxyAgent() so both the websocket and the media upload path get a Node-compatible agent. --- .../channel/whatsapp/whatsapp.baileys.service.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 22839fd451..abeef53d8c 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -85,7 +85,7 @@ import { createId as cuid } from '@paralleldrive/cuid2'; import { Instance, Message } from '@prisma/client'; import { createJid } from '@utils/createJid'; import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion'; -import { makeProxyAgent, makeProxyAgentUndici } from '@utils/makeProxyAgent'; +import { makeProxyAgent } from '@utils/makeProxyAgent'; import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache'; import { status } from '@utils/renderStatus'; import { sendTelemetry } from '@utils/sendTelemetry'; @@ -732,11 +732,15 @@ export class BaileysStartupService extends ChannelStartupService { const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length)); const proxyUrl = 'http://' + proxyUrls[rand]; this.logger.info('Proxy url: ' + proxyUrl); - options = { agent: makeProxyAgent(proxyUrl), fetchAgent: makeProxyAgentUndici(proxyUrl) }; + // Baileys rc13 uploads media through Node's native http/https (not fetch/Undici) on the Node + // runtime, and passes fetchAgent straight to http.request as its `agent`. + options = { agent: makeProxyAgent(proxyUrl), fetchAgent: makeProxyAgent(proxyUrl) }; } catch (error) { this.logger.error(error); } } else { + // Baileys rc13 uploads media through Node's native http/https (not fetch/Undici) on the Node + // runtime, and passes fetchAgent straight to http.request as its `agent`. options = { agent: makeProxyAgent({ host: this.localProxy.host, @@ -745,7 +749,7 @@ export class BaileysStartupService extends ChannelStartupService { username: this.localProxy.username, password: this.localProxy.password, }), - fetchAgent: makeProxyAgentUndici({ + fetchAgent: makeProxyAgent({ host: this.localProxy.host, port: this.localProxy.port, protocol: this.localProxy.protocol,