Failed SMS
Make SMS fail with Twilio's real error codes, at send time or after, and check how your app handles it.
Try it in the demo.
The situation: your app should handle an SMS that cannot be sent (invalid number, opted out) and one that is accepted but never arrives (unreachable handset, carrier filter). On Twilio these are hard to produce on demand.
You need: your app's SMS client pointing at SendMock (http://127.0.0.1:8026 for Twilio SDKs, or the native API). See Connect your app.
Steps
- Fail at send time. Send from your app to
+15005550001. SendMock answers at once with HTTP 400 and Twilio's error JSON, code21211(invalid number), exactly as Twilio's test credentials do. Your app should show its error. - Fail after sending. Send to
+15005550103. The message is accepted, then turns undelivered with30007(filtered by the carrier), and your status callback is called with it. - Open the conversation in SMS: the failed message shows a red tick with the code on hover; Message details shows the status history and each callback attempt.
Other numbers and codes are on Delivery and test numbers.
With cURL
curl -s http://127.0.0.1:8025/api/v1/sms \
-H 'content-type: application/json' \
-d '{"from": "+15550001111", "to": "+15005550001", "body": "Hi"}'
# 400: Rejected with error 21211 (magic number)In your code
A test that marks a sent SMS undelivered with Twilio's 30007, so your status callback handler runs. Sending to +15005550103 does the same by itself.
The examples call SendMock's REST API with each language's usual HTTP client and test framework. JavaScript, Go, Java, Rust, Ruby and C# use the small call helper shown under Test helper on their page in Connect your app.
# In your app: text the order update to +8801700000000
sms=$(sendmock sms wait --to +8801700000000 --timeout 10s --json)
failed=$(sendmock sms status "$(jq -r '.id' <<<"$sms")" undelivered --error-code 30007 --json)
jq -e '.status == "undelivered"' <<<"$failed" >/dev/null
jq -e '.error_code == "30007"' <<<"$failed" >/dev/nullWhat you should see
The 400 with code 21211 in your app's logs for the first send; for the second, an undelivered message and your callback handler receiving 30007.
Try it in the demo
- Open Settings > SMS.
- Type
+15005550001in Test a number: it says "Magic number: Invalid number (21211)". - Type
+15559990000: a custom rule applies, "Accepted, then undelivered, 30007".
Next
- Advanced: SMS outcome numbers: your own failing numbers.
- Delivery and test numbers