fix(baileys): expose delivery receipts for group messages - #2674
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRoutes Baileys group-message delivery/read receipts into the existing MESSAGES_UPDATE webhook path by emitting a flat status payload for each receipt and inferring DELIVERY_ACK vs READ from the receipt timestamps, fixing missing delivery confirmations for group chats without introducing new event types. Sequence diagram for routing Baileys group receipts to MESSAGES_UPDATEsequenceDiagram
participant WhatsApp
participant Baileys as BaileysCore
participant Startup as BaileysStartupService
participant Webhook as WebhookEndpoint
WhatsApp->>Baileys: handleReceipt
Baileys->>Baileys: ev.emit(message-receipt.update)
Baileys->>Startup: message-receipt.update(payload)
loop for each event
Startup->>Startup: sendDataWebhook(Events.MESSAGES_UPDATE)
Startup->>Webhook: sendDataWebhook(Events.MESSAGES_UPDATE)
end
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:
- The status derivation based solely on
typeof event.receipt.receiptTimestamp === 'number'may misclassify read receipts if bothreceiptTimestampandreadTimestampare present; consider explicitly checking forreadTimestamp(or Baileys’statusfield) to distinguish DELIVERY vs READ more robustly. - You’re emitting
MESSAGES_UPDATEfor everymessage-receipt.updateevent before the existingreadTimestamphandling; double-check whether this causes duplicated updates for reads and, if so, gate the emission to avoid sending two different updates for the same read event. - The in-code explanation comment is quite long and specific; consider tightening it and/or linking to an issue or reference so future readers get context without carrying too much narrative in the implementation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The status derivation based solely on `typeof event.receipt.receiptTimestamp === 'number'` may misclassify read receipts if both `receiptTimestamp` and `readTimestamp` are present; consider explicitly checking for `readTimestamp` (or Baileys’ `status` field) to distinguish DELIVERY vs READ more robustly.
- You’re emitting `MESSAGES_UPDATE` for every `message-receipt.update` event before the existing `readTimestamp` handling; double-check whether this causes duplicated updates for reads and, if so, gate the emission to avoid sending two different updates for the same read event.
- The in-code explanation comment is quite long and specific; consider tightening it and/or linking to an issue or reference so future readers get context without carrying too much narrative in the implementation.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Baileys routes receipts for group messages to `message-receipt.update` instead of `messages.update` (see `handleReceipt` in messages-recv.ts). In that branch, delivery arrives as `receiptTimestamp` while read arrives as `readTimestamp` — but only `readTimestamp` was being consumed, and `sendDataWebhook` was never called. The practical effect is that delivery confirmation for group messages never reaches the webhook. Individual chats confirm normally (SERVER_ACK, DELIVERY_ACK, READ); groups produce no event at all, even though WhatsApp does send the receipt and Baileys does receive it — one per participant. Verified on 2.3.7 with `LOG_BAILEYS=debug`: a single group message produced four `tag: "receipt"` stanzas, and zero webhook calls. This emits MESSAGES_UPDATE using the same flat payload as the individual-chat branch, so no new event type is needed and existing consumers keep working — `participant` is already part of the status schema. The existing `readTimestamp` handling is untouched.
c55a529 to
164421f
Compare
|
Thanks for the review. I looked into all three points — one is addressed, two don't apply, and I think it's worth showing why. 1.
|
Problem
Delivery confirmation for group messages never reaches the webhook.
Individual chats confirm normally (
SERVER_ACK→DELIVERY_ACK→READ), but group messages produce no event at all — even though WhatsApp does send the receipt and Baileys does receive it, one per participant.Root cause
Baileys routes receipts for group messages to
message-receipt.updateinstead ofmessages.update(handleReceiptinmessages-recv.ts):Note that delivery arrives as
receiptTimestamp, while read arrives asreadTimestamp. The handler for that event consumes onlyreadTimestampand never callssendDataWebhook, so the delivery signal is silently dropped.Evidence
Measured on 2.3.7 with
LOG_BAILEYS=debug. A single message sent to a 3-participant group produced four receipt stanzas (identifiers redacted):{"recv":{"tag":"receipt","attrs":{"from":"<group>@g.us","id":"<msg-id>","participant":"<user-a>:11@lid"}}} {"recv":{"tag":"receipt","attrs":{"from":"<group>@g.us","id":"<msg-id>","participant":"<user-b>:6@lid"}}} {"recv":{"tag":"receipt","attrs":{"from":"<group>@g.us","id":"<msg-id>","participant":"<user-b>@lid"}}} {"recv":{"tag":"receipt","attrs":{"from":"<group>@g.us","type":"read","id":"<msg-id>","participant":"<user-a>:11@lid"}}}Webhook calls in the same window: zero.
With this patch applied, the same test produces four
MESSAGES_UPDATEevents withparticipantpopulated and statusDELIVERY_ACK/READ.Approach
Emits
MESSAGES_UPDATEusing the same flat payload as the individual-chat branch, so that:Eventsenum or in the per-integration schemas (webhook, RabbitMQ, NATS, SQS, Kafka, Pusher);participantis already part of the status schema;readTimestamphandling is left untouched.Notes
npm run buildandnpm run lint:checkpass.