fix(baileys): send mediaUrl in webhook without SAVE_DATA.NEW_MESSAGE#2571
Open
renatomjr wants to merge 2 commits into
Open
fix(baileys): send mediaUrl in webhook without SAVE_DATA.NEW_MESSAGE#2571renatomjr wants to merge 2 commits into
renatomjr wants to merge 2 commits into
Conversation
Contributor
Reviewer's GuideEnsures media messages uploaded to S3 always get a mediaUrl added to the webhook payload, even when DATABASE.SAVE_DATA.NEW_MESSAGE is disabled, by decoupling media handling from message persistence and guarding DB operations behind presence of a saved message. Sequence diagram for sending mediaUrl in webhook without SAVE_DATA.NEW_MESSAGEsequenceDiagram
participant BaileysStartupService
participant PrismaRepository
participant S3Service
participant WebhookConsumer
BaileysStartupService->>BaileysStartupService: [isMedia]
alt SAVE_DATA.NEW_MESSAGE enabled
BaileysStartupService->>PrismaRepository: message.create(messageData)
PrismaRepository-->>BaileysStartupService: msg
else SAVE_DATA.NEW_MESSAGE disabled
BaileysStartupService->>BaileysStartupService: msg remains null
end
BaileysStartupService->>BaileysStartupService: hasValidMediaContent(message)
alt has valid media
BaileysStartupService->>BaileysStartupService: getBase64FromMediaMessage(message, true)
BaileysStartupService-->>BaileysStartupService: buffer, mediaType, fileName, size
BaileysStartupService->>S3Service: uploadFile(fullName, buffer, size.fileLength.low, headers)
S3Service-->>BaileysStartupService: upload complete
BaileysStartupService->>S3Service: getObjectUrl(fullName)
S3Service-->>BaileysStartupService: mediaUrl
BaileysStartupService->>BaileysStartupService: messageRaw.message.mediaUrl = mediaUrl
alt msg.id exists
BaileysStartupService->>PrismaRepository: media.create({ messageId: msg.id, ... })
BaileysStartupService->>PrismaRepository: message.update({ id: msg.id }, messageRaw)
else no persisted message
BaileysStartupService->>BaileysStartupService: skip DB updates
end
else no valid media
BaileysStartupService->>BaileysStartupService: skip upload
end
BaileysStartupService->>WebhookConsumer: sendDataWebhook(MESSAGES_UPSERT, messageRaw)
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 left some high level feedback:
- Consider giving
msga more specific type thanany(e.g., the Prisma message model type or a narrowed interface) to make it clearer which fields are expected and to catch potential misuse at compile time. - Now that the media handling block can run even when
SAVE_DATA.NEW_MESSAGEis disabled, double-check whether thereturninside theisVideo && !SAVE_VIDEObranch is still the desired behavior, since it exits before the webhook send and may skip non-media-related processing for those messages.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider giving `msg` a more specific type than `any` (e.g., the Prisma message model type or a narrowed interface) to make it clearer which fields are expected and to catch potential misuse at compile time.
- Now that the media handling block can run even when `SAVE_DATA.NEW_MESSAGE` is disabled, double-check whether the `return` inside the `isVideo && !SAVE_VIDEO` branch is still the desired behavior, since it exits before the webhook send and may skip non-media-related processing for those messages.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
📋 Description
Fixes sending mediaUrl via webhook even when DATABASE.SAVE_DATA.NEW_MESSAGE is not enabled.
🔗 Related Issue
Closes #(issue_number)
🧪 Type of Change
🧪 Testing
📸 Screenshots (if applicable)
✅ Checklist
Summary by Sourcery
Bug Fixes: