-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix: "Media upload failed on all hosts" utilizando proxy #2141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: "Media upload failed on all hosts" utilizando proxy #2141
Conversation
…ici como implementação nativa de fetch(), e o Undici não aceita mais objetos agent tradicionais (como os criados por https-proxy-agent ou socks-proxy-agent). Ele espera objetos compatíveis com a interface moderna Dispatcher, que possuem o método dispatch(). Ou seja, o Baileys estava recebendo um tipo de agente incompatível com o novo sistema de rede do Node. Foi criada uma nova função makeProxyAgentUndici() para gerar agentes de proxy compatíveis com o Undici, mantendo a versão antiga (makeProxyAgent()) inalterada para compatibilidade com bibliotecas como Axios. A nova função substitui os antigos HttpsProxyAgent e SocksProxyAgent por ProxyAgent da biblioteca undici, garantindo compatibilidade total com o Baileys e com qualquer uso de fetch() moderno.
Reviewer's GuideThis PR adds a new Undici-compatible proxy agent generator and updates the WhatsApp Baileys integration to use it for fetchAgent, ensuring compatibility with Node.js 18+ native fetch while preserving legacy proxy support and updating dependencies. Sequence diagram for BaileysStartupService proxy agent selection (Node.js 18+ fetch compatibility)sequenceDiagram
participant BaileysStartupService
participant ProxyConfig
participant makeProxyAgent
participant makeProxyAgentUndici
participant ProxyAgent (undici)
BaileysStartupService->>ProxyConfig: Get proxy configuration
alt Using legacy agent
BaileysStartupService->>makeProxyAgent: Create agent for Axios/legacy
makeProxyAgent-->>BaileysStartupService: Return HttpsProxyAgent/SocksProxyAgent
end
alt Using fetchAgent (Node.js 18+)
BaileysStartupService->>makeProxyAgentUndici: Create agent for fetch
makeProxyAgentUndici->>ProxyAgent (undici): Instantiate ProxyAgent
ProxyAgent (undici)-->>BaileysStartupService: Return ProxyAgent
end
ER diagram for proxy configuration normalizationerDiagram
PROXY {
string host
string protocol
string username
string password
int port
}
PROXY ||--o{ PROXY_URL : normalizes
PROXY_URL {
string url
}
Class diagram for updated proxy agent creation utilitiesclassDiagram
class Proxy {
host: string
password?: string
port?: number
protocol: string
username?: string
}
class HttpsProxyAgent
class SocksProxyAgent
class ProxyAgent
class makeProxyAgent {
+HttpsProxyAgent makeProxyAgent(proxy: Proxy | string)
}
class makeProxyAgentUndici {
+ProxyAgent makeProxyAgentUndici(proxy: Proxy | string)
}
makeProxyAgent --|> HttpsProxyAgent
makeProxyAgent --|> SocksProxyAgent
makeProxyAgentUndici --|> ProxyAgent
Proxy <.. makeProxyAgent
Proxy <.. makeProxyAgentUndici
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/utils/makeProxyAgent.ts:58` </location>
<code_context>
+ proxyUrl = proxy
+ } else {
+ const { host, password, port, protocol: proto, username } = proxy
+ protocol = proto.replace(':', '')
+
+ if (protocol === 'socks') {
</code_context>
<issue_to_address>
**issue:** Potential issue if 'proto' is undefined in Proxy object.
Add a check or default value for 'proto' to prevent errors when it is undefined.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@suissa quando tempo até a verificação da PR? |
|
EDIT: aqui deu certo. mt obrigado |
|
@JefersonRamos isso ja esta na versão 2.3.6? ou vai ser na próxima? |
Já foi dado merge, mas foi direto para main |

📋 Description
Esse erro acontece porque o Node.js (a partir da versão 18) usa o Undici como implementação nativa de fetch(), e o Undici não aceita mais objetos agent tradicionais (como os criados por https-proxy-agent ou socks-proxy-agent).
Ele espera objetos compatíveis com a interface moderna Dispatcher, que possuem o método dispatch().
Ou seja, o Baileys estava recebendo um tipo de agente incompatível com o novo sistema de rede do Node.
Foi criada uma nova função makeProxyAgentUndici() para gerar agentes de proxy compatíveis com o Undici, mantendo a versão antiga (makeProxyAgent()) inalterada para compatibilidade com bibliotecas como Axios.
A nova função substitui os antigos HttpsProxyAgent e SocksProxyAgent por ProxyAgent da biblioteca undici, garantindo compatibilidade total com o Baileys e com qualquer uso de fetch() moderno.
🔗 Related Issue
Closes #2117
🧪 Type of Change
🧪 Testing
📸 Screenshots (if applicable)
✅ Checklist
📝 Additional Notes
O protocolo socks é automaticamente normalizado para socks5, evitando erro de usuários que informem apenas "socks"
Summary by Sourcery
Introduce Undici-compatible proxy handling by adding makeProxyAgentUndici, updating BaileysStartupService to use it for fetchAgent, and adding undici to dependencies to ensure compatibility with Node.js 18+ native fetch
New Features:
Bug Fixes:
Enhancements:
Build: