API reference / Voice and AI
Replace Twilio AMD
If you already use Twilio answering machine detection (AMD), you can switch to
Drop Cowboy® Detection without rewriting anything. Point your Twilio SDK at the
Drop Cowboy bridge instead of api.twilio.com. Your calls, TwiML, Studio flows
and AMD webhooks stay the same. Calls that ask for MachineDetection are then
detected by Drop Cowboy, and your webhooks get the result as Twilio's own
AnsweredBy values.
| Bridge URL | https://twilio.dropcowboy.com (the dashboard shows the address for your account) |
| What you connect | Your Twilio Account SID and main Auth Token |
| What you change | The API host your Twilio SDK calls |
| What your webhooks get | Twilio's parameters and AnsweredBy values, signed with your Auth Token, plus optional Detection* parameters |
To build on Detection events directly instead, over a WebSocket or Twilio Media Streams, see Detection.
Connect your Twilio account
In the dashboard, open Building Blocks > Detection > Replace Twilio AMD and enter your Account SID and Auth Token. You need the developers permission on your team.
- Use the main Auth Token, not an API Key. Drop Cowboy signs every request
it sends you with
X-Twilio-Signature, exactly as Twilio does, so your signature checks keep passing. Twilio signs with the Auth Token, and an API Key secret can't produce the same signature. Your SDK can still sign in with an API Key. - Trial accounts can't be used. A trial account plays a notice and waits for a key press before your TwiML runs, so detection would hear the notice instead of the person. Upgrade the account first.
- One Drop Cowboy account per Twilio account. A Twilio account that is already connected elsewhere is refused.
A new connection starts in Shadow mode, so nothing changes for your calls until you choose Replace. See Shadow, Replace and Off.
Change the base URL
Change the API host and nothing else. The paths, parameters and credentials are Twilio's.
Node.js (twilio):
const twilio = require('twilio');
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
client.api.baseUrl = 'https://twilio.dropcowboy.com';
await client.calls.create({
to: '+13125550142',
from: '+13125550147',
url: 'https://example.com/twiml',
machineDetection: 'Enable',
asyncAmd: true,
asyncAmdStatusCallback: 'https://example.com/amd'
});
Python (twilio):
from twilio.rest import Client
client = Client(account_sid, auth_token)
client.api.base_url = "https://twilio.dropcowboy.com"
cURL:
curl -X POST "https://twilio.dropcowboy.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Calls.json" \
-u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" \
--data-urlencode "To=+13125550142" \
--data-urlencode "From=+13125550147" \
--data-urlencode "Url=https://example.com/twiml" \
--data-urlencode "MachineDetection=Enable"
The other Twilio SDKs have no public base URL setting. Give each one a small
HTTP client that swaps api.twilio.com for the bridge host and changes nothing
else. The dashboard shows a ready-to-paste version for each:
| SDK | Override |
|---|---|
C# (Twilio) |
A DelegatingHandler that rewrites the request URI, passed to TwilioRestClient through SystemNetHttpClient. |
Java (twilio) |
An HttpClient subclass whose makeRequest copies each request to the bridge host. |
PHP (twilio/sdk) |
A CurlClient subclass whose request replaces the host, passed to Client. |
Ruby (twilio-ruby) |
A Twilio::HTTP::Client subclass whose request replaces the host, passed to Twilio::REST::Client.new. |
Go (twilio-go) |
An http.RoundTripper that sets the request host, on the HTTPClient of the base client. |
Don't set Twilio's edge or region in the SDK, or the TWILIO_EDGE and
TWILIO_REGION environment variables. The SDK would then build a host that
skips the bridge. To use a Twilio edge and region, put them in the bridge
path instead: https://twilio.dropcowboy.com/r/{region}/{edge}, for example
https://twilio.dropcowboy.com/r/ie1/dublin.
Only requests that ask for machine detection change. Everything else (messages, numbers, recordings, call updates) goes to Twilio as you sent it, and Twilio's response comes back as Twilio sent it.
Shadow, Replace and Off
| Mode | What happens on a call with MachineDetection |
Use it to |
|---|---|---|
| Shadow | Twilio AMD decides, and your webhooks get Twilio's answer. Drop Cowboy listens to the same call and records its own answer next to Twilio's. | Compare before you switch. |
| Replace | Drop Cowboy decides, and your webhooks get its answer. Twilio AMD isn't requested. | Run on Drop Cowboy Detection. |
| Off | The call goes to Twilio unchanged, and Twilio's own AMD runs. | Pause Drop Cowboy Detection without changing your code. |
Off still routes your requests through the bridge. To stop routing through Drop
Cowboy entirely, point your SDK back at api.twilio.com.
In Shadow mode, the dashboard shows how often the two answers agree, how much sooner or later Drop Cowboy decided, and the mix of answers. Switch to Replace when you're satisfied. You can switch back at any time.
What your webhooks get
Drop Cowboy calls your Url, AsyncAmdStatusCallback and other callbacks the
way Twilio would. It sends the parameters Twilio sends on that request
(CallSid, AccountSid, From, To, CallStatus and so on), signs the
request with your Auth Token, and adds the AMD result.
AnsweredBy is always one of Twilio's values, so code that reads it keeps
working:
AnsweredBy |
With MachineDetection=Enable |
With MachineDetection=DetectMessageEnd |
|---|---|---|
human |
A live person answered. | A live person answered. |
machine_start |
A voicemail greeting, phone menu or call screener answered. | Not used. |
machine_end_beep |
Not used. | The greeting ended with a beep. Play your message now. |
machine_end_silence |
Not used. | The greeting ended in silence. |
machine_end_other |
Not used. | A full or unset mailbox, a carrier message, or a greeting that never ended. |
fax |
A fax machine answered. | A fax machine answered. |
unknown |
No decision: silence, or nothing Drop Cowboy could classify. | Same. |
MachineDetectionDuration is the time to the decision, in milliseconds.
MachineDetectionTimeout (3 to 59 seconds, default 30) and
MachineDetectionSilenceTimeout (2000 to 10000 milliseconds, default 5000)
work as they do on Twilio.
When human is decided
Some voicemail greetings start like a person picking up ("Hello? ... Hi, you've reached..."). You choose how the result handles them:
first(the default) answershumanas soon as a person is heard. It is the fastest, and a greeting that opens like a person can be reported ashuman.finalwaits until Detection is sure. Those greetings come back as machines, and a real person is reported a few seconds later than withfirst.
Set it on the profile, or for one call by adding DetectionHumanVerdict=first
or DetectionHumanVerdict=final to the Calls.json or Participants.json
request. The call's value wins. Drop Cowboy removes the parameter before the
request reaches Twilio. TwiML and Studio calls use the profile they name.
Detection parameters
When the profile has extra parameters on (the default), each result also carries these, and an empty value is left out:
| Parameter | Meaning |
|---|---|
DetectionType |
The detailed verdict, such as speech.voicemail.greeting. See Verdict types. |
DetectionConfidence |
0 to 1. |
DetectionBeep |
detected, or assumed_silence when the greeting ended without a beep. |
DetectionBeepFrequencyHz, DetectionBeepAtMs |
The beep's frequency, and when it ended. |
DetectionScreeningType, DetectionScreeningAction |
The call screener that answered, and what was done about it. |
DetectionFaxSignal |
ced, ansam, v21 or cng. |
DetectionSessionId |
The Detection session, for support. |
DetectionScreeningRestart |
true when your Url is fetched again after a call screener was answered. |
Ignore any parameter you don't recognize, so a new one doesn't break your code.
Detection profiles
A profile holds the settings for a call. Every connection has a profile named
default, and you can have up to 10 in total. In the dashboard you also pick
which one is the default, for calls that don't name a profile.
| Setting | What it does |
|---|---|
| Fax detection | Report fax machines as fax. On by default. |
| Extra parameters | Add the Detection* parameters. On by default. |
| Call screening | off, dtmf (press the key a call screener asks for), or dtmf_and_speak (also say a short message, up to 300 characters, in the voice you pick). |
| Restart after screening | On calls with AsyncAmd=true, answer the call screener and fetch your Url again. Without it, screeners are left alone on async calls, because your TwiML is already running. |
| Dead-end action | hangup ends the call on a full or unset mailbox or a carrier message, after your webhook gets the result. |
When to answer human |
first (default) or final. See When human is decided. |
| Detection webhook | An HTTPS URL that also gets Detection's own events, in the format described in Detection webhooks. Each one's call_id is the call's CallSid. It must be a public address of up to 2048 characters, and you can list up to 20 event names, each 1 to 64 lowercase letters, digits, ., - or _. |
Profile names are 1 to 32 lowercase letters, digits, - or _. A voice name is
1 to 64 letters, digits, ., - or _, such as Polly.Joanna, the default.
Call screening is answered only in Replace mode, and never for conference participants, because redirecting a participant would pull it out of the conference.
To pick a profile for one call, add detection_profile=<name> to its Url or
AsyncAmdStatusCallback. The bridge removes the parameter before it calls
you, so your signature checks still pass:
https://example.com/twiml?detection_profile=screened
A call that names no profile, or one that doesn't exist, uses the default.
What works
| You use | What to do |
|---|---|
POST /Calls.json with MachineDetection |
Nothing. Change the base URL. |
Conference participants with MachineDetection |
Nothing. |
Inline Twiml on a call, with <Number> or <Sip> asking for machineDetection |
Nothing. |
<Dial><Number machineDetection="..."> in TwiML that Twilio fetches from your server |
Wrap the number or TwiML App. See Wrap numbers and TwiML Apps. |
| Studio's Make Outgoing Call or Connect Call To widget with machine detection | Rewrite the flow. See Studio flows. |
Wrap numbers and TwiML Apps
When Twilio fetches TwiML from your server for an incoming call or a TwiML App, your SDK isn't involved, so the base URL doesn't reach it. Wrap the number or app instead. On Building Blocks > Detection > Replace Twilio AMD, load your numbers and apps, pick the ones to wrap and a profile, review the change, then wrap them. You can wrap up to 50 in one go; to wrap more, wrap the first 50, then select the next batch.
Wrapping changes two settings in Twilio:
- Voice URL points at the bridge. It fetches your TwiML from your original
URL and passes it on. A
<Number>or<Sip>that asks formachineDetectionis detected by Drop Cowboy, and itsamdStatusCallbackgets the result. Every other verb reaches Twilio as you wrote it. - Voice fallback URL becomes your original Voice URL.
That fallback is what keeps calls safe. If the bridge can't answer, Twilio
calls your own URL directly and the call runs as it did before. When the bridge
fetches your TwiML but can't set up detection on a <Number>, that number keeps
Twilio's own AMD.
Some resources can't be wrapped:
| Shown as | Why | What to do |
|---|---|---|
| SIP trunk | The number routes to an Elastic SIP Trunk, not a Voice URL. | Nothing to wrap. |
| Uses a TwiML App | The number takes its Voice URL from an app. | Wrap the app. |
| No Voice URL | There is nothing to fetch. | Set a Voice URL first. |
| Studio flow | The number runs a Studio flow. | Rewrite the flow. |
Change a wrapped number in the dashboard, not in the Twilio Console. If you edit its Voice URL, method or fallback in Twilio, the wrap is reported as drifted when you check for drift. Restore it, then wrap it again if you still want it. Restoring puts back the Voice URL and fallback you had before. If you already changed them in Twilio, restoring leaves Twilio as it is and only stops tracking the wrap.
Studio flows
Studio runs machine detection on its own, so the base URL doesn't reach it either. On the same page, list your flows and preview a flow that uses machine detection. The preview shows, widget by widget, what changes:
- Machine detection is turned off on the widget.
- A TwiML Redirect widget is added on its answered path. It holds the call while Drop Cowboy decides, then returns it to the flow.
- References such as
{{widgets.call_user.AnsweredBy}}are pointed at the new widget, so your splits keep working.
Publish to make the change a new revision of the flow. If the flow changed in Studio after your preview, publishing is refused; preview again.
Some references can't be pointed at the new widget, such as a widget name
built at run time with Liquid. The preview lists them. Fix them in Studio and
preview again, or accept them to publish anyway; those references then read an
empty AnsweredBy.
If detection fails during a call, the call always returns to the flow with an
empty AnsweredBy, so it takes the answered path, as it would with machine
detection off.
To undo the change, roll the flow back. That publishes the revision from before the rewrite as a new revision.
Look up a call
Enter a CallSid on the page to see the bridge's record for that call: the
mode, Drop Cowboy's answer and its details, Twilio's answer in Shadow mode, and
whether your webhook accepted the result. Records are kept for 30 days.
Disconnect
Disconnect on the same page. Every wrapped number and app gets its original Voice URL back, every rewritten Studio flow is rolled back, and detection stops for the account.
Point your SDK back at api.twilio.com before you disconnect. After it, the
bridge refuses requests for the account with 403 and account_not_enrolled.
The connection's Detection key
Each connection uses a Detection key of its own. It appears in your Detection
key list (GET /register/public/detection-keys) with managed_by set to
twilio_amd, the connection's integration_id, and revocable set to
false. It is listed rather than hidden because it is a live key that bills
detection and counts toward your key limit. It can't be revoked from the key
list: revoking it answers 409 with detection_key_managed and "Disconnect
the Twilio AMD connection to remove this key". Disconnecting removes it.
The key list covers every connection and your own carrier pool, if you have one. Revoking a key finds it on whichever of them holds it. A key you create yourself goes on your carrier pool, or on your first Twilio AMD connection if you don't have one.
Errors from the bridge
Errors that come from the bridge itself use Twilio's error shape, with a code
string, so your SDK raises them like a Twilio error:
| Status | code |
What to do |
|---|---|---|
403 |
account_not_enrolled |
The Twilio account has no Detection connection. Connect it, or point your SDK at api.twilio.com. |
400 |
invalid_region |
The region or edge in /r/{region}/{edge} isn't valid. Use Twilio's names. |
504 |
twilio_timeout |
Twilio didn't answer in time. Check whether the call was created before you send it again. |
502 |
twilio_unreachable or bridge_error |
The request may not have reached Twilio. Check before you send it again. |
The bridge never retries a call create, because a retry could place the call
twice. Before you retry one after a 502 or 504, list your recent calls in
Twilio to see whether it went through.
Any other error is Twilio's own, passed through unchanged.
Common problems
- My webhook rejects the bridge's requests. Check that the connection uses
the main Auth Token. If you validate against a fixed URL, remember that
detection_profileis removed before the request is signed. - Calls still use Twilio AMD. The connection is in Shadow mode, or the SDK sets an edge or region and skips the bridge.
- Incoming calls aren't detected. Wrap the number or TwiML App that serves them.
- A Studio flow isn't detected. Rewrite it on the Studio list. A flow you edited after the rewrite shows as drifted; preview and publish it again.