Track WhatsApp outbound delivery receipts and terminal failures - #178
Open
Obiajulu-gif wants to merge 1 commit into
Open
Track WhatsApp outbound delivery receipts and terminal failures#178Obiajulu-gif wants to merge 1 commit into
Obiajulu-gif wants to merge 1 commit into
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
Contributor
|
@Obiajulu-gif resolve conflict |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #159
Summary
statuses[]array from the WhatsApp Cloud API webhook payload and record each delivery-status callback (sent/delivered/read/failed) idempotently in a newWhatsappStatusEventaudit table, keyed on(providerMessageId, status, statusTimestamp)so exact-duplicate redeliveries are a no-op.Notificationwith delivery-lifecycle fields (sentAt,deliveredAt,readAt,failedAt,lastStatusAt,failureCode,failureMessage,retryable,retryCount,referenceType/referenceId) and advance a matching row throughqueued -> sent -> delivered -> read, or a terminalfailed. Out-of-order callbacks (older timestamp or lower-rank status) and callbacks on an already-terminalfailednotification are detected and ignored rather than regressing state.sendTextMessagegained an opt-innotificationoption; callers that care about delivery lifecycle (transaction receipts inassistant.service.js, deposit alerts indeposits.jobs.js, voice replies invoice.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.failedcallback's Meta error code is classified as retryable (transient) or permanent viaclassifyWhatsappFailure. Safe/transient failures on messages with a domain reference are retried once via a new bounded (max 2 attempts)whatsapp-outbound-retryqueue job, registered inwhatsapp.jobs.js.20260821090000_add_whatsapp_delivery_statusadds the new columns/table, following the style of the existingProcessedMessage/KycWebhookEventmigrations.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/metricsendpoint.Test plan
apps/api/test/whatsapp.deliveryStatus.test.jscovering: 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/api— could not be run locally: this sandbox's disk is essentially full host-wide (independent of this change) andnpm installcould not complete, so please rely on CI for the actual run.🤖 Generated with Claude Code