fix(whatsapp): improve audio upsert reliability and add GHCR workflow#2427
Open
alexandrereyes wants to merge 3 commits intoEvolutionAPI:mainfrom
Open
fix(whatsapp): improve audio upsert reliability and add GHCR workflow#2427alexandrereyes wants to merge 3 commits intoEvolutionAPI:mainfrom
alexandrereyes wants to merge 3 commits intoEvolutionAPI:mainfrom
Conversation
Contributor
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
|
Contributor
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.
Author
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: