fix: respect DATABASE_SAVE_DATA_CONTACTS in contact updates
๐ Description
The DATABASE_SAVE_DATA_CONTACTS environment variable was being ignored in specific parts of the contacts.upsert (profile picture updates) and contacts.update handlers.
This PR adds the missing conditional checks to ensure that contact data is only saved to the database when this configuration is explicitly enabled, maintaining consistency with other SAVE_DATA flags.
๐ Related Issue
Closes #(issue_number)
๐งช Type of Change
- [x] ๐ Bug fix (non-breaking change which fixes an issue)
- [ ] โจ New feature (non-breaking change which adds functionality)
- [ ] ๐ฅ Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] ๐ Documentation update
- [ ] ๐ง Refactoring (no functional changes)
- [ ] โก Performance improvement
- [ ] ๐งน Code cleanup
- [ ] ๐ Security fix
๐งช Testing
- [x] Manual testing completed
- [x] Functionality verified in development environment
- [x] No breaking changes introduced
- [x] Tested with different connection types (if applicable)
๐ธ Screenshots (if applicable)
โ Checklist
- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have manually tested my changes thoroughly
- [x] I have verified the changes work with different scenarios
- [x] Any dependent changes have been merged and published
๐ Additional Notes
Summary by Sourcery
Respect database configuration flags when processing WhatsApp contact updates to avoid persisting contacts when disabled.
Bug Fixes:
- Guard WhatsApp contact update and upsert operations behind the DATABASE.SAVE_DATA.CONTACTS flag so contacts are not written when contact persistence is disabled.
Enhancements:
- Minor formatting cleanups in logging and message repository initialization for WhatsApp integration.
Reviewer's Guide
Conditionally persist WhatsApp contact data based on DATABASE.SAVE_DATA.CONTACTS while leaving webhook and Chatwoot integrations intact, and make minor formatting adjustments.
Sequence diagram for conditional WhatsApp contact persistence based on DATABASE.SAVE_DATA.CONTACTS
sequenceDiagram
actor "WhatsApp" as WhatsApp
participant "BaileysStartupService" as Baileys
participant "ConfigService" as Config
participant "PrismaRepository (Database)" as Prisma
participant "Webhook consumer" as Webhook
participant "Chatwoot integration" as Chatwoot
"WhatsApp" ->> "BaileysStartupService": "Contacts update event with contacts list"
activate "BaileysStartupService"
"BaileysStartupService" ->> "Webhook consumer": "sendDataWebhook(\"CONTACTS_UPDATE\", contacts)"
loop "For each updated contact"
"BaileysStartupService" ->> "ConfigService": "get(\"DATABASE\").SAVE_DATA.CONTACTS"
"ConfigService" -->> "BaileysStartupService": "Boolean flag"
alt "SAVE_DATA.CONTACTS is true"
"BaileysStartupService" ->> "PrismaRepository (Database)": "contact.updateMany({ where: { remoteJid, instanceId }, data: { profilePicUrl } })"
else "SAVE_DATA.CONTACTS is false"
"BaileysStartupService" --x "PrismaRepository (Database)": "Skip contact.updateMany"
end
"BaileysStartupService" ->> "ConfigService": "get(\"CHATWOOT\").ENABLED"
"ConfigService" -->> "BaileysStartupService": "Boolean flag"
alt "CHATWOOT is enabled and localChatwoot.enabled"
"BaileysStartupService" ->> "Chatwoot integration": "Sync contact data (e.g., profile picture)"
else "CHATWOOT disabled"
"BaileysStartupService" --x "Chatwoot integration": "Skip Chatwoot sync"
end
end
deactivate "BaileysStartupService"
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Gate contact profile update operations on the DATABASE.SAVE_DATA.CONTACTS flag. |
|
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts |
| Conditionally upsert contacts into the database during bulk contact sync based on configuration. |
|
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts |
| Apply minor code formatting adjustments for logging and message repository initialization. |
|
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts |
Possibly linked issues
- #(not specified): PR adds conditional checks so contacts are only persisted when DATABASE_SAVE_DATA_CONTACTS is enabled, fixing reported bug.
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
@Vitordotpy ty! I'm new when it comes to open source contributions, what else we need to ship?