fix(baileys): send mediaUrl in webhook without SAVE_DATA.NEW_MESSAGE#2571
fix(baileys): send mediaUrl in webhook without SAVE_DATA.NEW_MESSAGE#2571renatomjr wants to merge 2 commits into
Conversation
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
|
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.
|
🔴 👎 O objetivo (enviar o |
📋 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: