A Twilio API mock for testing SMS replies.
Give your agent seeded phone numbers and message history. Check its SMS creation call, then retrieve the message’s sender, recipient and body.
sms_sentCalls POST /2010-04-01/Accounts/*/Messages.json
Starting records
messages
- from
+14155550100- to
+17755550162
numbers
- phoneNumber
+14155550100
Connect your agent to the Twilio mock
When ancha runs your agent, it sets:
TWILIO_API_URLTWILIO_ACCOUNT_SIDTWILIO_AUTH_TOKEN
Point the client you already use at them.
import twilio from 'twilio';
class Replica extends twilio.RequestClient {
request(opts: any) {
const url = new URL(opts.uri), host = url.hostname.split('.')[0];
return super.request({ ...opts, uri: process.env.TWILIO_API_URL + (host === 'api' ? '' : '/' + host) + url.pathname + url.search });
}
}
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN, { httpClient: new Replica() });
const messages = await client.messages.list({ limit: 20 });Locally, ancha runs your agent as an ordinary process, so keep real Twilio credentials out of its environment.
See all 20 endpoints
2010-04-01
/2010-04-01/Accounts/{AccountSid}.json/2010-04-01/Accounts/{AccountSid}/Balance.json/2010-04-01/Accounts/{AccountSid}/Calls.json/2010-04-01/Accounts/{AccountSid}/Calls.json/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json/2010-04-01/Accounts/{AccountSid}/Messages.json/2010-04-01/Accounts/{AccountSid}/Messages.json/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.jsonlookups
/lookups/v2/PhoneNumbers/{PhoneNumber}verify
/verify/v2/Services/verify/v2/Services/{Sid}/verify/v2/Services/{Sid}/VerificationCheck/verify/v2/Services/{Sid}/Verifications/verify/v2/Services/{Sid}/Verifications/{VerificationSid}/verify/v2/Services/{Sid}/Verifications/{VerificationSid}Seed your own data
The data the Twilio mock starts with on every run, cut to a few records. ancha twins seed twilio prints every field.
Full seed YAML
twins:
- twilio
seed:
twilio:
account:
friendlyName: Acme
balance: 250
numbers:
- phoneNumber: "+14155550100"
friendlyName: Acme Support
created: -4000h
directory:
- phoneNumber: "+14155550161"
carrier: T-Mobile USA, Inc.
callerName: GREG WILSON
messages:
- from: "+14155550100"
to: "+17755550162"
body: "Acme: scheduled reports are coming soon. Reply STOP to opt out."
at: -2000h
calls:
- from: "+14155550100"
to: "+16085550134"
at: -25h
duration: 372
verifyServices:
- friendlyName: Acme Login
verifications:
- to: "+14155550148"
at: -44m
status: canceled
Check what your agent did
Checks YAML
checks:
- id: sms_sent
trace:
called: POST /2010-04-01/Accounts/*/Messages.jsonMore chat and email tools
All 43 toolsTwilio API mock FAQ
Can an SMS-agent test catch messages addressed to an opted-out recipient?
Set optedOut: true on the recipient in seed.twilio.directory. An otherwise valid SMS creation request to that number returns 400 with code 21610 in Ancha’s Twilio mock.
How does an unreachable phone affect simulated Twilio message status?
For a seeded mobile recipient with reachable: false, an accepted SMS moves from queued to sent after one second on the simulated clock. After three seconds it becomes undelivered with error_code: 30003.
What does Twilio Verify return when an agent checks an expired code?
A pending verification in the mock expires ten minutes after creation on the simulated clock. A subsequent POST / returns 404.
Install the CLI and run your agent against the Twilio mock.
Ancha is not affiliated with Twilio.