SMS Module Documentation
Overview
The SMS Module is the notification router. It abstracts the complexity of multiple gateways (Hormuud, Somtel, WhatsApp) and provides a unified API for the rest of the system to "Send Message". It features Intelligent Routing to save costs by choosing the correct local carrier.
Architecture
Core Services (app/Domain/Sms)
SmsRouter (SmsRouter.php)
Purpose: Determines which pipe to send the message through.
Key Methods:
route(phone, property)
Returns the SmsChannel.
- Logic:
- Normalization: Cleans phone to international format (
252...). - International: If not
252(Somalia), routes to WhatsApp. - Local: Checks prefixes.
61,68,77-> Hormuud.62-> Somtel.- Critique: This map is currently hardcoded in a protected array
$defaultPrefixMap.
- Normalization: Cleans phone to international format (
SmsService (SmsService.php)
Purpose: Facade for delivery.
Key Methods:
send(templateKey, phone, context)
- Logic:
- Locates Template.
- Compiles Content (Replace ).
- Calls Router.
- Dispatches Job to Worker.
Integration
Provider Configs
Channels are configured via sms_channels table, but the Driver Factory logic often requires code changes to support new providers.
| Provider | Type | API Type |
|---|---|---|
| Hormuud | SMS | Bearer Token |
| Somtel | SMS | REST |
| Meta | Graph API |
Audit Findings & Improvements
Strengths
- Cost Optimization: The automatic routing to Hormuud for Hormuud numbers (On-Net) vs Somtel (Off-Net) can save ~30% in SMS costs.
- International Fallback: Automatically upgrading international numbers to WhatsApp is smart, as international SMS is unreliable and expensive.
Issues Identified
Major
- Hardcoded Prefix Map: The
SmsRoutercontains a hardcoded array of prefixes. If a carrier releases a new prefix range (e.g.25263), the code must be deployed to support it.- Fix: Move prefix mapping to the database (
sms_carrierstable).
- Fix: Move prefix mapping to the database (
Minor
- Driver Factory: To add a new Gateway (e.g. Twilio), you must modify the core
SmsServiceclass code.
Module Version
Version: 1.0 Status: Stable