Repository navigation
feat(messaging): improve reliability of Telegram and WhatsApp message delivery (#493) - #502
Merged
robertocarlous merged 2 commits intoOct 15, 2026
Conversation
|
@OAKVISUALZ Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
fix conflicts |
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.
Summary
Closes #493
Strengthens message delivery, queue behavior, fallback handling, and manual recovery for Telegram bot notifications and WhatsApp communication.
Key Goals & Acceptance Criteria Addressed
PENDING,SENDING,DELIVERED,FAILED, andDEAD_LETTERbacked by the PrismaMessageDeliverymodel and indexed queries.min(maxDelay, baseDelay * 2^(attempts-1)) * (1 + jitter)) preventing thundering herds.retry_afterparameters for Telegram and Twilio/WhatsApp transient error codes.alertingServicetrigger integrated when dead-letter threshold is exceeded during periodic background sweep.Architectural Changes
Database Schema & Migrations (
prisma/schema.prisma):MessageChannel,MessageDeliveryStatus, andMessagePriority.MessageDeliverymodel with compound indexes for queue sweeping ([status, nextAttemptAt],[channel, status]) and filtering (userId,recipient,createdAt).prisma/migrations/20260927000000_add_message_deliveries/.Core Delivery Engine (
src/messaging/):MessageDeliveryService: Unified singleton managing message dispatch, lifecycle tracking, backoff calculation, fallback orchestration, and administrative recovery.Client Adapters:
src/utils/telegram-client.ts: Dedicated Telegram Bot API client with HTTP client adapter injection for deterministic unit testing, transient error classification, HTML mode, and retry-after header/response parsing.src/utils/twilio-client.ts: Enhanced with transient error classifier (isWhatsAppTransientError) and retry-after extractor (extractWhatsAppRetryAfter).Background Resilient Sweep Job (
src/jobs/messageDeliverySweep.ts):PENDINGmessages ordered by priority (CRITICAL,HIGH,NORMAL,LOW) and timestamp.src/index.ts.Admin Tooling & Operations (
src/routes/admin.ts):GET /api/v1/admin/messages: Paginated list of tracked message deliveries with status/channel filters.GET /api/v1/admin/messages/stats: Overview counts of messages across statuses and per-channel breakdown.GET /api/v1/admin/messages/:id: Detailed message inspection.POST /api/v1/admin/messages/:id/retry: Safe manual retry of failed or dead-lettered message.POST /api/v1/admin/messages/retry-dead-letters: Bulk re-enqueueing of dead-lettered messages.DELETE /api/v1/admin/messages/:id: Safe cancellation of pending or dead messages.src/middleware/adminAuth.ts:messages:read,messages:write.Service & Notification Integrations:
src/routes/telegram.ts: Telegram webhook bot replies routed throughmessageDeliveryService.src/jobs/alertRules.ts: Alert notification deliveries routed throughmessageDeliveryService.src/strategy/service.ts: Strategy update notifications to followers routed throughmessageDeliveryService.Documentation:
docs/MESSAGING_DELIVERY.md.docs/NOTIFICATIONS.md,docs/RUNBOOK.md, anddocs/DOCUMENTATION_INDEX.md.Verification & Testing
npm run typecheckpassed with 0 errors across the entire codebase.tests/unit/messaging/telegramClient.test.ts: PASSEDtests/unit/messaging/messageDeliveryService.test.ts: PASSEDtests/unit/jobs/messageDeliverySweep.test.ts: PASSEDtests/unit/routes/admin-messages.test.ts: PASSEDtests/unit/telegram/telegramHandler.test.ts: PASSEDtests/unit/telegram/telegramConfirmations.test.ts: PASSEDtests/unit/strategy/service.test.ts: PASSEDtests/unit/jobs/alertRules.test.ts: PASSED