fix(whatsapp): improve audio upsert reliability and add GHCR workflow#2427
Conversation
Reviewer's GuideAdjusts WhatsApp Baileys media handling to avoid early returns that skip MESSAGES_UPSERT emissions (with a cache‑guarded fallback path for inbound audio messages), and adds a GitHub Actions workflow to build and publish multi‑arch images to GHCR. Class diagram for BaileysStartupService media and audio upsert handlingclassDiagram
class BaileysStartupService {
- logger
- configService
- prismaRepository
- baileysCache
- instance
- instanceId
+ handleInboundMessage(received, msg, messageRaw)
+ handleMessageUpdate(updateEvent)
+ hasValidMediaContent(message) bool
+ getBase64FromMediaMessage(message, uploadToS3) MediaData
+ sendDataWebhook(event, payload) Promise
}
class MediaData {
+ buffer
+ mediaType
+ fileName
+ size
}
class S3Service {
+ uploadFile(fullName, buffer, fileLength, metadata) Promise
+ getObjectUrl(fullName) Promise
}
class PrismaRepository {
+ media_create(data) Promise
+ message_update(where, data) Promise
+ findMessageByKey(key) Message
}
class BaileysCache {
+ get(key) Promise
+ set(key, value, ttlSeconds) Promise
}
class Message {
+ id
+ key
+ pushName
+ status
+ message
+ contextInfo
+ messageType
+ messageTimestamp
+ instanceId
+ source
}
BaileysStartupService --> S3Service : uses
BaileysStartupService --> PrismaRepository : uses
BaileysStartupService --> BaileysCache : uses
BaileysStartupService --> MediaData : uses
PrismaRepository --> Message : returns
%% New audio upsert cache behavior
BaileysStartupService : + setAudioUpsertEmittedFlag(messageKeyId)
BaileysStartupService : + emitFallbackAudioUpsertIfNeeded(key, findMessage)
File-Level Changes
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 removing the
console.log(messageRaw);in the WhatsApp service or switching it to a structured logger call so it doesn't produce noisy output in production. - The
upsert_emitted_${this.instanceId}_${...}cache key string is duplicated in both the upsert and update paths; extracting a helper or constant for this key format would reduce the risk of typos and keep the behavior consistent if it ever needs to change.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider removing the `console.log(messageRaw);` in the WhatsApp service or switching it to a structured logger call so it doesn't produce noisy output in production.
- The `upsert_emitted_${this.instanceId}_${...}` cache key string is duplicated in both the upsert and update paths; extracting a helper or constant for this key format would reduce the risk of typos and keep the behavior consistent if it ever needs to change.
## Individual Comments
### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:1436-1437` </location>
<code_context>
}
console.log(messageRaw);
- this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw);
</code_context>
<issue_to_address>
**🚨 suggestion (security):** Consider removing or downgrading the raw console.log for message payloads.
Logging full `messageRaw` on every upsert in the main path will flood logs and may expose sensitive message content. Since you already have `this.logger`, consider removing this line or replacing it with a structured debug/trace-level log instead.
```suggestion
} catch (error) {
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
}
this.logger.debug([
'Upsert message processed',
{
key: messageRaw?.key,
messageType: messageRaw?.messageType,
fromMe: messageRaw?.key?.fromMe,
},
]);
await this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw);
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Applied the Sourcery feedback in this PR branch: removed the raw console log from the upsert path and extracted a shared helper for the upsert-emitted cache key used by both upsert and update paths. Commit: 2fd3ee3 |
Integrates 3 key stability improvements: • PR evolution-foundation#2420: Prevent Evolution instances from getting stuck in 'close' state - Auto-connect Evolution instances on startup - Force 'open' state for webhook-based integrations - Update monitor service to handle Evolution integration • PR evolution-foundation#2372: Enhance contact and chat handling with improved JID mapping - Fix remoteLid vs remoteJid mapping in messaging-history.set - Add debug logs for better troubleshooting - Prevent orphaned chats without proper contact association - Clean remoteLid before database storage • PR evolution-foundation#2427: Improve audio upsert reliability and GHCR workflow - Prevent early returns that skip message upsert emission - Add guarded fallback for inbound audio messages - Add GitHub Actions workflow for GHCR image publishing These improvements enhance: - Connection stability for Evolution instances - Contact/chat mapping accuracy - Audio message reliability - CI/CD with GHCR support All changes are non-breaking and backward compatible.
|
Hi! As part of our PR triage, we re-ran CI on this PR and the Check Code Quality workflow is failing. Could you please:
Once CI is green I'll re-review for merge. Thanks! |
Summary
messages.upsertemission for valid incoming media messages.messages.upsertis awaited and add a guarded fallback emit for inboundaudioMessageentries when onlymessages.updateis observed.ghcr.io/<owner>/evolution-api) onmainpushes, tags, and manual dispatch.Why
Audio inbound processing can intermittently miss upsert notifications depending on media handling order, which prevents downstream consumers from reacting to those messages. The GHCR workflow enables faster image publishing on forks while upstream review is pending.
Summary by Sourcery
Improve reliability of inbound WhatsApp audio message upsert events and add automated GHCR image publishing.
Bug Fixes:
Enhancements:
CI: