Skip to main content
coreydaley.dev
Docs menu

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:8200

The SMS server implements the Twilio Messages API endpoint:

POST /2010-04-01/Accounts/{AccountSid}/Messages.json

Required 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/ErrorCode fields, magic numbers and --twilio-callback-delay are on main and listed under Unreleased in the changelog. MessagePit v1.3.0 sends a single signed callback per message with MessageSid, MessageStatus, To and From.

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 → delivered

The 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:

FieldNotes
MessageSid / SmsSidStable across the whole progression
MessageStatus / SmsStatusqueued, sent, delivered, undelivered, failed
To, FromAs submitted
AccountSidFrom the request path
ApiVersion2010-04-01
ErrorCode, ErrorMessagePresent 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.

NumberFieldCodeMeaning
+15005550001To21211Not a valid phone number
+15005550002To21612Not currently reachable via SMS
+15005550003To21408Region not enabled for SMS
+15005550004To21610Unsubscribed recipient
+15005550009To21614Not a valid mobile number
+15005550001From21212Not a valid sender
+15005550007From21606Not an SMS-capable number on this account
+15005550008From21611Sender queue full

Delivery failures

A MessagePit extension: the send succeeds, and the failure surfaces through the callback progression.

To numberProgressionErrorCode
+15005550010queued → failed30008 (unknown error)
+15005550011queued → sent → undelivered30003 (unreachable handset)
+15005550012queued → sent → undelivered30005 (unknown handset)
+15005550013queued → sent → undelivered30006 (landline / unreachable carrier)
+15005550014queued → sent— (carrier never confirms)

SMS API

The management API on port 8025 exposes the captured messages:

MethodPathDescription
GET/api/v1/sms/messagesList SMS messages
GET/api/v1/sms/message/{id}Get single SMS message
PUT/api/v1/sms/message/{id}/readMark as read
DELETE/api/v1/sms/message/{id}Delete message
DELETE/api/v1/sms/messagesDelete all messages

The full REST API is documented by the running server at http://localhost:8025/api/v1.