Feat/whatsapp/convert-to-jpeg by nestordavalos · Pull Request #1884 · EvolutionAPI/evolution-api · GitHub
Skip to content

Feat/whatsapp/convert-to-jpeg#1884

Merged
DavidsonGomes merged 1 commit intoEvolutionAPI:developfrom
nestordavalos:feat/whatsapp/convert-to-jpeg
Aug 29, 2025
Merged

Feat/whatsapp/convert-to-jpeg#1884
DavidsonGomes merged 1 commit intoEvolutionAPI:developfrom
nestordavalos:feat/whatsapp/convert-to-jpeg

Conversation

@nestordavalos
Copy link
Copy Markdown
Contributor

@nestordavalos nestordavalos commented Aug 28, 2025

All images sent via the Baileys integration are now pre-processed and converted to JPEG format using the sharp library. This ensures better compatibility and prevents potential issues with unsupported formats.

  • Images from URLs are now downloaded via axios before processing, which allows for the use of a proxy.
  • The default filename and mimetype are updated to image.jpg and image/jpeg to reflect the conversion.

Summary by Sourcery

Preprocess WhatsApp image attachments by fetching them via axios (respecting local proxy settings), converting buffers to JPEG using sharp, and updating file metadata to ensure compatibility.

New Features:

  • Convert all WhatsApp image media to JPEG format using sharp before sending
  • Download remote images via axios with optional proxy support for preprocessing

Enhancements:

  • Set default image filename to image.jpg and mimetype to image/jpeg after conversion

All images sent via the Baileys integration are now pre-processed and converted to JPEG format using the `sharp` library. This ensures better compatibility and prevents potential issues with unsupported formats.

- Images from URLs are now downloaded via axios before processing, which allows for the use of a proxy.
- The default filename and mimetype are updated to `image.jpg` and `image/jpeg` to reflect the conversion.
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Aug 28, 2025

Copy link
Copy Markdown
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/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:2470` </location>
<code_context>
+            };
+          }
+
+          const response = await axios.get(mediaMessage.media, config);
+          imageBuffer = Buffer.from(response.data, 'binary');
+        } else {
</code_context>

<issue_to_address>
Network errors from axios.get are not explicitly handled.

Catch errors from axios.get to prevent unhandled promise rejections when the image URL is unreachable or returns a non-200 status.
</issue_to_address>

### Comment 2
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:2477` </location>
<code_context>
+        }
+
+        mediaInput = await sharp(imageBuffer).jpeg().toBuffer();
+        mediaMessage.fileName ??= 'image.jpg';
+        mediaMessage.mimetype = 'image/jpeg';
+      } else {
</code_context>

<issue_to_address>
Redundant fileName assignment logic exists below.

Consolidate the fileName assignment to a single location to improve clarity and maintain consistency.

Suggested implementation:

```typescript
        mediaInput = await sharp(imageBuffer).jpeg().toBuffer();
        mediaMessage.fileName ??= 'image.jpg';
        mediaMessage.mimetype = 'image/jpeg';
      } else {
        mediaInput = isURL(mediaMessage.media)
          ? { url: mediaMessage.media }
          : Buffer.from(mediaMessage.media, 'base64');

```

If there is another assignment to `mediaMessage.fileName` elsewhere in this function or code path, it should be removed to ensure the assignment is consolidated to this single location.
</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.

};
}

const response = await axios.get(mediaMessage.media, config);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue: Network errors from axios.get are not explicitly handled.

Catch errors from axios.get to prevent unhandled promise rejections when the image URL is unreachable or returns a non-200 status.

}

mediaInput = await sharp(imageBuffer).jpeg().toBuffer();
mediaMessage.fileName ??= 'image.jpg';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Redundant fileName assignment logic exists below.

Consolidate the fileName assignment to a single location to improve clarity and maintain consistency.

Suggested implementation:

        mediaInput = await sharp(imageBuffer).jpeg().toBuffer();
        mediaMessage.fileName ??= 'image.jpg';
        mediaMessage.mimetype = 'image/jpeg';
      } else {
        mediaInput = isURL(mediaMessage.media)
          ? { url: mediaMessage.media }
          : Buffer.from(mediaMessage.media, 'base64');

If there is another assignment to mediaMessage.fileName elsewhere in this function or code path, it should be removed to ensure the assignment is consolidated to this single location.

@bergpinheiro
Copy link
Copy Markdown
Contributor

@DavidsonGomes DavidsonGomes merged commit 78f7618 into EvolutionAPI:develop Aug 29, 2025
1 check passed
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.

3 participants