SMS without a provider · Daoini
- problem
- Appointment reminders need SMS, and Algeria has no cost-effective A2P (application-to-person) SMS gateway. The per-message fee would have been the largest recurring cost per clinic.
- call
- Messages go into a Postgres outbox (pending → sending → sent | failed). A companion app (Expo plus a native Kotlin module) on one phone per clinic polls every ~30 s. It sends through SmsManager from the clinic's own SIM, multipart-aware with per-part radio confirmation, with a randomised 2–5 s gap so batches don't read as spam. Rows are claimed in one UPDATE … FOR UPDATE SKIP LOCKED … RETURNING, so concurrent polls never double-send. A row stuck in sending is reclaimed after a few minutes, accepting a rare duplicate over a missed reminder. 24 h and 2 h reminders come from a five-minute cron made idempotent by a partial unique index, so the cron needs no leader election. Each clinic registers exactly one sender phone behind a SHA-256-hashed key, and registering a new phone revokes the old one. A specialUse foreground service, a boot receiver and a 15-minute WorkManager watchdog keep it running through reboots and OEM battery managers. The Play Store restricts SEND_SMS, so the app ships as a signed APK with in-app self-update.
- outcome
- Per-message provider fees are gone from the cost model, with no third-party gateway.
clinician app ──▶ NestJS API ──▶ sms_outbox (Postgres)
│ cron */5: 24 h · 2 h reminders
│ (partial unique index = idempotent)
▼
claim: UPDATE … FOR UPDATE SKIP LOCKED … RETURNING
│ x-gateway-key (SHA-256, 1 phone per clinic)
▼
companion app · Android · clinic's own SIM
poll ~30 s · SmsManager · foreground svc · watchdog
│
▼
patient's phone- NestJS
- PostgreSQL
- Expo
- Kotlin
- Android SmsManager
- WorkManager