feat: support native GIF sending without video conversion#2540
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds native GIF support for WhatsApp media messages by wiring gifPlayback and gifAttribution through validation, DTOs, and Baileys media preparation, enabling GIFs to be sent without video conversion while maintaining backward compatibility. Flow diagram for native GIF fields through validation and Baileysflowchart LR
req[Incoming media message\nwith gifPlayback, gifAttribution] --> schema[mediaMessageSchema\nvalidates gifPlayback, gifAttribution]
schema --> dtoMedia[MediaMessage DTO\nadds gifPlayback, gifAttribution]
dtoMedia --> dtoSend[SendMediaDto\nexposes gifPlayback, gifAttribution]
dtoSend --> service[BaileysStartupService\nassigns gifPlayback, gifAttribution to prepareMedia]
service --> baileys[generateWAMessageFromContent]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider normalizing
gifPlaybackandgifAttributionto their final boolean/number types at the validation or DTO layer so that the Baileys service only deals with strongly-typed values and doesn’t need to handle string variants ('true','0', etc.) directly. - Previously
gifPlaybackwas always set tofalsefor videos, but now it can be left undefined; if Baileys or downstream logic expects an explicit boolean, it may be safer to default tofalsewhen the field is not provided.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider normalizing `gifPlayback` and `gifAttribution` to their final boolean/number types at the validation or DTO layer so that the Baileys service only deals with strongly-typed values and doesn’t need to handle string variants (`'true'`, `'0'`, etc.) directly.
- Previously `gifPlayback` was always set to `false` for videos, but now it can be left undefined; if Baileys or downstream logic expects an explicit boolean, it may be safer to default to `false` when the field is not provided.
## Individual Comments
### Comment 1
<location path="src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts" line_range="2884-2885" />
<code_context>
- prepareMedia[mediaType].gifPlayback = false;
+ prepareMedia[mediaType].gifPlayback = mediaMessage.gifPlayback === true || mediaMessage.gifPlayback === 'true';
+
+ if (mediaMessage.gifAttribution !== undefined) {
+ prepareMedia[mediaType].gifAttribution = Number(mediaMessage.gifAttribution);
+ }
}
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider validating `gifAttribution` before coercing with `Number` to avoid `NaN` or out-of-range values.
This path can still receive unexpected values (e.g., empty string, malformed payload, or programmatic usage bypassing validation). `Number()` may return `NaN`, which could then be sent to the WhatsApp client API. Please guard by only assigning when the coerced value is 0, 1, or 2, e.g.:
```ts
if (mediaMessage.gifAttribution !== undefined) {
const gifAttribution = Number(mediaMessage.gifAttribution);
if (gifAttribution === 0 || gifAttribution === 1 || gifAttribution === 2) {
prepareMedia[mediaType].gifAttribution = gifAttribution;
}
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Atualizei a base do PR de Pode rebasar em git fetch upstream
git rebase upstream/develop
git push --force-with-leaseA feature está bem feita (backward-compat preservado, schema bem definido, defensivo em parsing de Sugestão opcional para follow-up: considerar detecção automática |
Allow gifPlayback and gifAttribution options to be passed to Baileys video messages.
Add gifPlayback and gifAttribution properties to media DTO definitions.
Add gifPlayback and gifAttribution validation support to media message schema.
Prevent invalid gifAttribution values from reaching Baileys media payload.
68b33a0 to
fd199c2
Compare
|
@AlexisJusviack fiz um rebase na sua branch removendo commits de Force-push aplicado em Obrigado pela contribuição! |
DavidsonGomes
left a comment
There was a problem hiding this comment.
LGTM após rebase em develop. Feature bem feita:
- Backward-compat preservado (default
falsequando cliente não envia o flag) - Schema bem definido (aceita boolean ou string para tolerar JSON com strings)
- Defensivo no parsing de
gifAttribution(validação 0/1/2 antes de setar) - Naming consistente com a Baileys (
gifPlayback,gifAttribution)
Sugestões opcionais para follow-up:
- Detecção automática
mimetype === 'image/gif'para setargifPlayback=truepor default — DX gain importante - Documentar
gifAttribution0/1/2 (Tenor/Giphy/etc.) no Swagger/README
Problem
Currently GIF files are converted to video before sending through Baileys.
This causes unnecessary FFmpeg processing and increased CPU usage.
Solution
This PR adds native GIF support using Baileys gifPlayback and gifAttribution options,
allowing animated GIFs to be sent without video conversion.
Changes
gifPlaybacksupportgifAttributionsupportBenefits
Compatibility
This change is backward compatible and does not affect normal video sending.
Summary by Sourcery
Add support for sending native animated GIFs over WhatsApp by propagating gif playback and attribution options through validation, DTOs, and Baileys media preparation.
New Features:
Enhancements: