SMS integration
New to testing this locally? Start with How to test SMS locally, which compares MessagePit with the provider’s own test mode.
Point your application’s Twilio SDK at the SMS ingest server instead of api.twilio.com:
http://localhost:8200The SMS server implements the Twilio Messages API endpoint:
POST /2010-04-01/Accounts/{AccountSid}/Messages.jsonRequired form fields: From, To, Body. Authentication uses HTTP Basic Auth (AccountSid:AuthToken); set MP_TWILIO_AUTH_TOKEN to the token your app sends. Captured messages appear in the SMS tab of the web UI.
For a complete twilio-ruby setup, including the HTTP client that rewrites the API host, see the Rails example.
SMS status callbacks
Coming in the next release. The status progression, the
SmsSid/SmsStatus/ErrorCodefields, magic numbers and--twilio-callback-delayare onmainand listed under Unreleased in the changelog. MessagePit v1.3.0 sends a single signed callback per message withMessageSid,MessageStatus,ToandFrom.
When MP_TWILIO_WEBHOOK_URL is set (or a per-request StatusCallback form field is provided), MessagePit replays the message’s full status progression to that URL, one signed POST per state change, exactly as Twilio does:
queued → sent → deliveredThe POST /Messages.json response still reports "status": "queued", matching real Twilio: the terminal state only ever arrives via callback.
Each callback body is application/x-www-form-urlencoded:
| Field | Notes |
|---|---|
MessageSid / SmsSid | Stable across the whole progression |
MessageStatus / SmsStatus | queued, sent, delivered, undelivered, failed |
To, From | As submitted |
AccountSid | From the request path |
ApiVersion | 2010-04-01 |
ErrorCode, ErrorMessage | Present only on failed / undelivered |
When MP_TWILIO_AUTH_TOKEN is set, every callback carries an X-Twilio-Signature HMAC-SHA1 header so your handler can validate it with the standard Twilio SDK.
Priority: the StatusCallback field in the send request takes precedence over the global MP_TWILIO_WEBHOOK_URL.
Set --twilio-callback-delay (MP_TWILIO_CALLBACK_DELAY, e.g. 750ms) to space the callbacks out. The default is 0: the states still arrive in order, just without the wall-clock gap.
Magic numbers
Twilio reserves the +1500555xxxx range for test numbers. MessagePit honours the real ones and adds its own in the same range for the delivery-failure branches, which real Twilio has no way to trigger on demand.
API rejections
Real Twilio behaviour: the send returns HTTP 400 with a Twilio error code, nothing is stored, and no callback fires.
| Number | Field | Code | Meaning |
|---|---|---|---|
+15005550001 | To | 21211 | Not a valid phone number |
+15005550002 | To | 21612 | Not currently reachable via SMS |
+15005550003 | To | 21408 | Region not enabled for SMS |
+15005550004 | To | 21610 | Unsubscribed recipient |
+15005550009 | To | 21614 | Not a valid mobile number |
+15005550001 | From | 21212 | Not a valid sender |
+15005550007 | From | 21606 | Not an SMS-capable number on this account |
+15005550008 | From | 21611 | Sender queue full |
Delivery failures
A MessagePit extension: the send succeeds, and the failure surfaces through the callback progression.
To number | Progression | ErrorCode |
|---|---|---|
+15005550010 | queued → failed | 30008 (unknown error) |
+15005550011 | queued → sent → undelivered | 30003 (unreachable handset) |
+15005550012 | queued → sent → undelivered | 30005 (unknown handset) |
+15005550013 | queued → sent → undelivered | 30006 (landline / unreachable carrier) |
+15005550014 | queued → sent | — (carrier never confirms) |
SMS API
The management API on port 8025 exposes the captured messages:
| Method | Path | Description |
|---|---|---|
| GET | /api/v1/sms/messages | List SMS messages |
| GET | /api/v1/sms/message/{id} | Get single SMS message |
| PUT | /api/v1/sms/message/{id}/read | Mark as read |
| DELETE | /api/v1/sms/message/{id} | Delete message |
| DELETE | /api/v1/sms/messages | Delete all messages |
The full REST API is documented by the running server at http://localhost:8025/api/v1.