Skip to content

Track WhatsApp outbound delivery receipts and terminal failures - #178

Open
Obiajulu-gif wants to merge 1 commit into
EF-CHAIN:mainfrom
Obiajulu-gif:issue-159-whatsapp-delivery-receipts
Open

Track WhatsApp outbound delivery receipts and terminal failures#178
Obiajulu-gif wants to merge 1 commit into
EF-CHAIN:mainfrom
Obiajulu-gif:issue-159-whatsapp-delivery-receipts

Conversation

@Obiajulu-gif

Copy link
Copy Markdown

Closes #159

Summary

  • Parse the statuses[] array from the WhatsApp Cloud API webhook payload and record each delivery-status callback (sent/delivered/read/failed) idempotently in a new WhatsappStatusEvent audit table, keyed on (providerMessageId, status, statusTimestamp) so exact-duplicate redeliveries are a no-op.
  • Extend Notification with delivery-lifecycle fields (sentAt, deliveredAt, readAt, failedAt, lastStatusAt, failureCode, failureMessage, retryable, retryCount, referenceType/referenceId) and advance a matching row through queued -> sent -> delivered -> read, or a terminal failed. Out-of-order callbacks (older timestamp or lower-rank status) and callbacks on an already-terminal failed notification are detected and ignored rather than regressing state.
  • sendTextMessage gained an opt-in notification option; callers that care about delivery lifecycle (transaction receipts in assistant.service.js, deposit alerts in deposits.jobs.js, voice replies in voice.service.js) now pass reference metadata so status callbacks have a row to correlate against. Low-stakes replies are unaffected and still don't touch the DB.
  • A failed callback's Meta error code is classified as retryable (transient) or permanent via classifyWhatsappFailure. Safe/transient failures on messages with a domain reference are retried once via a new bounded (max 2 attempts) whatsapp-outbound-retry queue job, registered in whatsapp.jobs.js.
  • New Prisma migration 20260821090000_add_whatsapp_delivery_status adds the new columns/table, following the style of the existing ProcessedMessage/KycWebhookEvent migrations.
  • Delivery-status metrics (sendam_whatsapp_delivery_status_total, sendam_whatsapp_status_webhook_total, sendam_whatsapp_retry_total) are emitted via the existing observability/metrics module, so they're already exposed on the app's /metrics endpoint.

Test plan

  • Added apps/api/test/whatsapp.deliveryStatus.test.js covering: valid status recording, malformed payloads, exact-duplicate idempotency, unmatched provider ids, out-of-order/regression guarding, terminal-failure lock-in, error-code classification, and bounded/gated retry enqueueing (retryable+referenced, permanent, unreferenced, and retry-cap-exhausted cases).
  • npm test / npm run lint --workspace=apps/apicould not be run locally: this sandbox's disk is essentially full host-wide (independent of this change) and npm install could not complete, so please rely on CI for the actual run.

🤖 Generated with Claude Code

…HAIN#159)

Parse the `statuses[]` array from the WhatsApp Cloud API webhook, record
each callback in a new WhatsappStatusEvent audit table (idempotent on
providerMessageId+status+statusTimestamp), and advance a matching
Notification through queued -> sent -> delivered -> read, or a terminal
failed state. Out-of-order and duplicate callbacks are detected and
ignored rather than regressing state.

Outbound sends that report a domain reference (transaction receipts,
deposit alerts, voice replies) now create a Notification row via
sendTextMessage's new opt-in `notification` option, so status callbacks
have something to correlate against.

A failed callback is classified as retryable or permanent from Meta's
error code; safe/transient failures on referenced messages are retried
once via a new bounded (max 2 attempts) `whatsapp-outbound-retry` queue
job, registered alongside the existing WhatsApp job processors.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
send-am-admin Skipped Skipped Aug 21, 2026 7:34am
senda Skipped Skipped Aug 21, 2026 7:34am

@vercel
vercel Bot temporarily deployed to Preview – senda August 21, 2026 07:34 Inactive
@vercel
vercel Bot temporarily deployed to Preview – send-am-admin August 21, 2026 07:34 Inactive
@Gozirimdev

Copy link
Copy Markdown
Contributor

@Obiajulu-gif resolve conflict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Track WhatsApp outbound delivery receipts and terminal failures

2 participants