| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Reviewer's GuideRefactors Baileys WhatsApp message upsert handling to preserve Meta Ads/CTWA webhook messages (even without resolved phone numbers), enrich webhook payloads with campaign metadata and LID info, and isolate per-message failures within batches while adding better error handling and media/webhook processing logic. Sequence diagram for Meta Ads message upsert and webhook preservationsequenceDiagram
participant BaileysStartupService
participant PhoneResolver as resolvePhoneNumber
participant Webhook as sendDataWebhook
participant DB as prismaRepository
participant S3 as s3Service
participant Chatbot as chatbotController
BaileysStartupService->>BaileysStartupService: prepareMessage(received)
BaileysStartupService->>BaileysStartupService: getCampaignMetadata(messageRaw.contextInfo)
BaileysStartupService->>PhoneResolver: resolvePhoneNumber(messageRaw.key)
PhoneResolver-->>BaileysStartupService: phoneNumber or null
BaileysStartupService->>BaileysStartupService: createWebhookMessage()
BaileysStartupService->>Webhook: sendDataWebhook(Events.MESSAGES_UPSERT, webhookMessage)
alt isMetaAdsMessage
Note over BaileysStartupService,Webhook: Webhook sent early, before DB/media/chatbot
else nonMetaAdsMessage
BaileysStartupService->>Webhook: sendDataWebhook(Events.MESSAGES_UPSERT, webhookMessage)
end
BaileysStartupService->>DB: message.create(messageData)
BaileysStartupService->>S3: uploadFile(fullName, buffer, size)
BaileysStartupService->>DB: media.create({ messageId, instanceId, type, fileName })
BaileysStartupService->>Chatbot: emit({ instance, remoteJid, msg, pushName })
BaileysStartupService->>Webhook: sendDataWebhook(Events.CONTACTS_UPDATE | CONTACTS_UPSERT, contactRaw)
Sequence diagram for per-message error isolation and placeholder resendsequenceDiagram
participant BaileysStartupService
participant Client as client
participant Logger as logger
loop for each received in messages
BaileysStartupService->>BaileysStartupService: [per-message try]
alt messageStubParameters indicate decryption error
BaileysStartupService->>Client: requestPlaceholderResend(received.key)
Client-->>BaileysStartupService: resendId
BaileysStartupService->>Logger: warn("requested resend", keyId, resendId)
BaileysStartupService-->>BaileysStartupService: continue to next message
else normal processing
BaileysStartupService->>BaileysStartupService: full message handling (DB, media, webhook, chatbot)
end
BaileysStartupService->>Logger: error on per-message failure
end
BaileysStartupService->>Logger: error on outer handler failure
File-Level Changes
Tips and commands Interacting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
What changed
Why
Meta Ads conversations can arrive through Baileys with an @lid JID and without a phone number or remoteJidAlt. The previous processing path could discard the message before the webhook reached the CRM workflow.
Validation
This PR does not add payload persistence or a retry queue.
Summary by Sourcery
Improve WhatsApp Baileys message upsert handling to reliably surface Meta Ads conversations and harden per-message processing against failures.
New Features:
Bug Fixes:
Enhancements: