Skip to content

Conversation

@gomessguii
Copy link
Member

@gomessguii gomessguii commented Oct 29, 2025

πŸ“‹ Description

πŸ”— Related Issue

Closes #(issue_number)

πŸ§ͺ Type of Change

  • πŸ› Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • πŸ’₯ Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • πŸ“š Documentation update
  • πŸ”§ Refactoring (no functional changes)
  • ⚑ Performance improvement
  • 🧹 Code cleanup
  • πŸ”’ Security fix

πŸ§ͺ Testing

  • Manual testing completed
  • Functionality verified in development environment
  • No breaking changes introduced
  • Tested with different connection types (if applicable)

πŸ“Έ Screenshots (if applicable)

βœ… Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have manually tested my changes thoroughly
  • I have verified the changes work with different scenarios
  • Any dependent changes have been merged and published

πŸ“ Additional Notes

Summary by Sourcery

Introduce an undici-based proxy agent utility and integrate it into the WhatsApp Baileys service for improved proxy handling

New Features:

  • Add makeProxyAgentUndici utility to create undici ProxyAgent instances for HTTP, HTTPS, SOCKS4, and SOCKS5 proxies

Enhancements:

  • Use makeProxyAgentUndici for the fetchAgent in the WhatsApp Baileys startup service to ensure compatibility with undici

Build:

  • Add undici dependency to package.json

DavidsonGomes and others added 15 commits October 15, 2025 09:25
- Updated subproject reference in evolution-manager-v2.
- Replaced old JavaScript and CSS asset files with new versions for improved performance and styling.
- Added new CSS file for consistent font styling across the application.
- Updated the evolution logo image to the latest version.
- Added features for Chatwoot enhancements, participants data handling, and LID to phone number conversion.
- Updated Docker configurations to include Kafka and frontend services.
- Fixed PostgreSQL migration errors and improved message handling in Baileys and Chatwoot services.
- Refactored TypeScript build process and implemented exponential backoff patterns.
- Updated the release date for version 2.3.5 to 2025-10-15.
- Adjusted subproject reference in evolution-manager-v2 to the latest commit.
- Integrated telemetry logging for received messages in Evolution, WhatsApp Business, and Baileys services.
- Enhanced message tracking by sending the message type to the telemetry system for better observability.
- Updated subproject reference in evolution-manager-v2 to the latest commit.
- Enhanced the manager_install.sh script to include npm install and build steps for the evolution-manager-v2.
- Replaced old JavaScript asset file with a new version for improved performance.
- Added a new CSS file for consistent styling across the application.
…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.
…upload-failed-on-all-hosts

fix: "Media upload failed on all hosts" utilizando proxy
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 29, 2025

Reviewer's Guide

This PR adds a new undici-based proxy agent factory, integrates it into the WhatsApp Baileys service for fetch requests, and updates project dependencies to include undici.

Sequence diagram for proxy agent selection in BaileysStartupService

sequenceDiagram
    participant BaileysStartupService
    participant ProxyAgentFactory
    participant UndiciProxyAgentFactory
    BaileysStartupService->>ProxyAgentFactory: makeProxyAgent(proxyUrl)
    BaileysStartupService->>UndiciProxyAgentFactory: makeProxyAgentUndici(proxyUrl)
    Note over BaileysStartupService,UndiciProxyAgentFactory: fetchAgent now uses Undici-based proxy agent
Loading

Class diagram for new and updated proxy agent factories

classDiagram
    class makeProxyAgent {
        +makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent<string>
    }
    class makeProxyAgentUndici {
        +makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent
    }
    class Proxy {
        +host: string
        +port: number
        +protocol: string
        +username: string
        +password: string
    }
    makeProxyAgentUndici --> Proxy
    makeProxyAgent --> Proxy
Loading

Class diagram for BaileysStartupService proxy agent usage update

classDiagram
    class BaileysStartupService {
        +options: agent
        +options: fetchAgent
        +localProxy: enabled
        +localProxy: host
        +localProxy: port
        +localProxy: protocol
        +localProxy: username
        +localProxy: password
    }
    class makeProxyAgent {
        +makeProxyAgent(proxy: Proxy | string): HttpsProxyAgent<string>
    }
    class makeProxyAgentUndici {
        +makeProxyAgentUndici(proxy: Proxy | string): ProxyAgent
    }
    BaileysStartupService --> makeProxyAgent : uses for agent
    BaileysStartupService --> makeProxyAgentUndici : uses for fetchAgent
Loading

File-Level Changes

Change Details Files
Introduce undici-based proxy agent factory
  • Imported ProxyAgent from undici
  • Implemented makeProxyAgentUndici to handle string and object proxy inputs
  • Normalized protocols (http, https, socks4, socks5) and constructed proxy URLs with optional auth
  • Switched over supported protocols and threw on unsupported ones
src/utils/makeProxyAgent.ts
Switch fetchAgent calls to use undici ProxyAgent
  • Replaced makeProxyAgent with makeProxyAgentUndici for fetchAgent in random string proxy case
  • Replaced makeProxyAgent with makeProxyAgentUndici for fetchAgent in object proxy case
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Add undici dependency
  • Added undici to dependencies in package.json
  • Updated package-lock.json accordingly
package.json
package-lock.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@DavidsonGomes DavidsonGomes merged commit c555048 into EvolutionAPI:develop Oct 29, 2025
2 of 4 checks passed
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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-62` </location>
<code_context>
+    const { host, password, port, protocol: proto, username } = proxy
+    protocol = (proto || 'http').replace(':', '')
+
+    if (protocol === 'socks') {
+      protocol = 'socks5'
+    }
+
</code_context>

<issue_to_address>
**suggestion:** Protocol normalization for 'socks' is hardcoded to 'socks5'.

Some proxies use 'socks4', so please handle 'socks4' explicitly or document that 'socks' defaults to 'socks5'.

```suggestion
    protocol = (proto || 'http').replace(':', '')

    // Normalize SOCKS protocol: 'socks' defaults to 'socks5', but handle 'socks4' and 'socks5' explicitly
    if (protocol === 'socks') {
      // Default to socks5 if protocol is 'socks'
      protocol = 'socks5'
    } else if (protocol === 'socks4' || protocol === 'socks5') {
      // Leave as is for explicit socks4/socks5
      // No change needed
    }
```
</issue_to_address>

### Comment 2
<location> `src/utils/makeProxyAgent.ts:80-81` </location>
<code_context>
+      return new ProxyAgent(proxyUrl)
+
+    default:
+      throw new Error(`Unsupported proxy protocol: ${protocol}`)
+  }
+}
</code_context>

<issue_to_address>
**suggestion:** Error message for unsupported protocol could be more informative.

Including the full proxy input in the error message will make it easier to trace issues when user input is involved.

```suggestion
    default:
      throw new Error(
        `Unsupported proxy protocol: ${protocol}. Full proxy input: ${typeof proxy === 'string' ? proxy : JSON.stringify(proxy)}`
      )
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click πŸ‘ or πŸ‘Ž on each comment and I'll use the feedback to improve your reviews.

Comment on lines +58 to +62
protocol = (proto || 'http').replace(':', '')

if (protocol === 'socks') {
protocol = 'socks5'
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Protocol normalization for 'socks' is hardcoded to 'socks5'.

Some proxies use 'socks4', so please handle 'socks4' explicitly or document that 'socks' defaults to 'socks5'.

Suggested change
protocol = (proto || 'http').replace(':', '')
if (protocol === 'socks') {
protocol = 'socks5'
}
protocol = (proto || 'http').replace(':', '')
// Normalize SOCKS protocol: 'socks' defaults to 'socks5', but handle 'socks4' and 'socks5' explicitly
if (protocol === 'socks') {
// Default to socks5 if protocol is 'socks'
protocol = 'socks5'
} else if (protocol === 'socks4' || protocol === 'socks5') {
// Leave as is for explicit socks4/socks5
// No change needed
}

Comment on lines +80 to +81
default:
throw new Error(`Unsupported proxy protocol: ${protocol}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Error message for unsupported protocol could be more informative.

Including the full proxy input in the error message will make it easier to trace issues when user input is involved.

Suggested change
default:
throw new Error(`Unsupported proxy protocol: ${protocol}`)
default:
throw new Error(
`Unsupported proxy protocol: ${protocol}. Full proxy input: ${typeof proxy === 'string' ? proxy : JSON.stringify(proxy)}`
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants