feat(backend): deliver SMS claim receipts via Twilio#139
Merged
kilodesodiq-arch merged 3 commits intoJun 18, 2026
Conversation
Add an SmsProvider abstraction with Twilio and mock implementations, selected by credential presence (mirrors VERIFICATION_MODE=mock). The notification processor now delivers SMS jobs through the provider, so a Twilio API error throws and feeds the existing retry/DLQ/outbox path. Email delivery remains mocked. Adds TWILIO_* env vars and unit tests.
Wire ClaimsService.sendReceiptViaSMS to NotificationsService.sendSms so receipts are delivered asynchronously through the existing BullMQ outbox path instead of being logged. Each phone number is enqueued independently; enqueue failures are logged so receipt generation still succeeds. Import NotificationsModule into ClaimsModule and cover the new path with tests.
kilodesodiq-arch
approved these changes
Jun 18, 2026
kilodesodiq-arch
left a comment
Contributor
There was a problem hiding this comment.
Nice @i-sayankh — Twilio slots in cleanly behind the existing BullMQ/DLQ infrastructure and your spec coverage (provider + processor + claims) is thorough. Merging.
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 #8
Summary
ClaimsService.sendReceiptViaSMSwas a TODO stub that only logged[SMS STUB], so SMS receipts were never sent to recipients. This PR wires claim receipts into the existing async notification harness and plugs in a real Twilio provider.While investigating, two gaps surfaced — not one:
[Mock] Sending...), so no SMS was delivered for any caller — includingverification-flow.Both are now fixed. The existing async machinery (BullMQ queue,
NotificationOutbox, 3× exponential-backoff retries, dead-letter queue, metrics) was reused as-is rather than rebuilt.Scope is SMS only, as agreed — the email receipt stub and email mock are intentionally left untouched.
Changes
src/notifications/providers/)SmsProviderinterface (send(to, body)), with a DI token.TwilioSmsProvider— wraps thetwilioSDK; validates E.164 numbers; throws on API errors so the existing retry/DLQ path engages.MockSmsProvider— logs and returns a synthetic id; selected automatically when Twilio credentials are absent (mirrors theVERIFICATION_MODE=mockidiom), so dev/test/CI need no credentials and don't flood the DLQ.notifications.processor.ts) routes by job type:SMS → smsProvider.send(...), email unchanged. A Twilio failure now throws → retries → DLQ → outboxfailed+ metric.ClaimsService.sendReceiptViaSMSis now async and enqueues viaNotificationsService.sendSmsper phone number, with per-number isolation so one bad number (or a Redis outage) is logged without aborting the rest or failing receipt generation.ClaimsModuleimportsNotificationsModule.twiliodependency andTWILIO_ACCOUNT_SID/TWILIO_AUTH_TOKEN/TWILIO_FROM_NUMBERto.env.example(empty → mock mode).Error handling
failed+ metricMockSmsProvider: logs + succeeds (no DLQ noise)Testing
TwilioSmsProvider— success path, non-E.164 rejection, API-error propagation.MockSmsProvider— resolves without throwing.sendReceiptViaSMSenqueues per number and survives an enqueue failure while still returning the receipt.Verification:
nest build✅ ·tsc --noEmit✅ · full unit suite 400 passed, 10 skipped ✅ · ESLint clean on touched files ✅Notes for reviewers
TWILIO_*env vars to enable real delivery; without them the logging mock runs.verification-flow's SMS path, which shared the same mock.