Replace FreePBX AMD

FreePBX runs on Asterisk, so it uses the same dc-amd as Replace Asterisk AMD. On FreePBX you call it through a Custom Destination with Return enabled. The call goes into dc-amd, comes back with AMDSTATUS and AMDCAUSE set, and carries on to the destination you choose. Anything that routes on those variables after AMD() keeps working.

You can set it up two ways:

  • The Drop Cowboy® Connect module. A settings page for your key and options, with the dialplan and Custom Destinations created for you.
  • By hand. Paste one context in Config Edit and add a Custom Destination.
What you install dc-amd, one static Linux binary, and optionally the Drop Cowboy Connect module
Where it runs A Custom Destination with Return enabled
What you get AMDSTATUS, AMDCAUSE and DC_AMD_* variables
Where your key lives /etc/dc-amd/dc-amd.conf, mode 0640, and nowhere else
Versions FreePBX 16 and 17

Before you start

  • A Detection key. Create one in the dashboard or with the API. See Create a Detection key. If the key has allowed_cidrs, include the public address your FreePBX server connects from.
  • Outbound access from the FreePBX server to detect.dropcowboy.com on port 443.
  • Root access over SSH, to install dc-amd and the module.
  • The Custom Destinations module, which is part of a standard FreePBX install. It is listed as Admin > Custom Destinations.

Install dc-amd

Run this as root on the FreePBX server:

curl -fsSLO https://github.com/Drop-Cowboy/pbx-connect/releases/latest/download/dc-connect-linux-amd64
curl -fsSLO https://github.com/Drop-Cowboy/pbx-connect/releases/latest/download/SHA256SUMS
sha256sum --ignore-missing -c SHA256SUMS
chmod +x dc-connect-linux-amd64
sudo ./dc-connect-linux-amd64 amd install

On an ARM server, use dc-connect-linux-arm64. The installer asks for your Detection key without showing it, and writes /etc/dc-amd/dc-amd.conf. It checks the key against Detection. To install from a script, pipe the key in with --key-stdin. Replace Asterisk AMD lists every option.

Use the module

Install it

Install the module from its release URL:

fwconsole ma downloadinstall https://github.com/Drop-Cowboy/pbx-connect/releases/latest/download/dcconnect.tgz
fwconsole reload

Don't add a module repository for it. downloadinstall is the only supported way to install it.

The module is unsigned until Sangoma signs it. FreePBX warns that the Drop Cowboy Connect module is unsigned. The module still installs and runs. The warning goes away once a signed release is out and you install it with the same command.

Set it up

Open Applications > Drop Cowboy AMD.

Setting Values What it does
Detection key Your key Saved only in /etc/dc-amd/dc-amd.conf. Leave it blank to keep the current key.
Mode Replace, Shadow, Off See Modes.
When Detection is unavailable NOTSURE, Native AMD See Fail open.
Wait for the beep Yes, No Yes makes every call wait for the voicemail beep. See Wait for the beep.
After detection, go to Any FreePBX destination Where both Custom Destinations return to, with AMDSTATUS set.

Choose After detection, go to, then Submit and Apply Config. The module then creates two Custom Destinations, both with Return enabled:

Custom Destination Target Use it for
Drop Cowboy AMD dc-amd,s,1 Most calls. Answers as soon as Detection decides.
Drop Cowboy AMD (wait for beep) dc-amd,beep,1 Calls that leave a voicemail message. Answers machines at the end of the greeting.

You can rename them and edit their notes in Admin > Custom Destinations. The module keeps their target and return destination in step with the settings page, so change those on the settings page.

To pass AMD() arguments, add a Custom Destination of your own with Return enabled, such as dc-amd,s,1(2000,2000,1000,8000,120,50,4,256). See Set it up by hand.

Your key on the server

The key is stored in /etc/dc-amd/dc-amd.conf and nowhere else. It isn't in the FreePBX database or in FreePBX backups. The settings page never shows it, only its last four characters.

The page saves the file with mode 0640 and the Asterisk group, so only root and the Asterisk user and group can read it. fwconsole chown keeps those permissions.

FreePBX backups don't include the key. If you add /etc/dc-amd to a custom file backup, that backup holds your key, so keep it as safe as the server.

Send calls through it

A call reaches dc-amd wherever FreePBX lets you pick a destination after the call is answered. Pick the Drop Cowboy AMD Custom Destination.

To send calls you place yourself, originate into the Custom Destination. The settings page shows each one's address for this, such as customdests,dest-3,1. With the Asterisk Manager Interface:

Action: Originate
Channel: Local/13125550142@from-internal
Context: customdests
Exten: dest-3
Priority: 1
Async: true

Detection listens from the moment the call reaches dc-amd. Send calls there as soon as they're answered, before anything is played.

Route on the result

After dc-amd returns, the call goes to the destination you chose. Branch there on AMDSTATUS:

  • Dynamic Routes, if you have that module: add a route with source type Asterisk Variable and ${AMDSTATUS} as the variable. Add matches for HUMAN, MACHINE, NOTSURE and HANGUP.
  • A small context in Config Edit. Paste this into extensions_custom.conf, change the ring group and the recording to yours, then add a Custom Destination with target dc-amd-route,s,1 and Return off. Choose it as After detection, go to.
[dc-amd-route]
exten => s,1,NoOp(AMDSTATUS=${AMDSTATUS} AMDCAUSE=${AMDCAUSE} DC_AMD_SOURCE=${DC_AMD_SOURCE})
exten => s,n,GotoIf($["${AMDSTATUS}" = "MACHINE"]?machine)
exten => s,n,GotoIf($["${AMDSTATUS}" = "HANGUP"]?gone)
exten => s,n,Goto(ext-group,600,1)
exten => s,n(machine),Playback(custom/voicemail-message)
exten => s,n(gone),Hangup()

HUMAN and NOTSURE both go to the ring group here, so a call with no answer in time still reaches a person.

Set it up by hand

Without the module, add the context and a Custom Destination yourself.

  1. Install dc-amd as above.
  2. In Admin > Config Edit, open extensions_custom.conf. Paste this at the end, then Save and Apply Config.
[dc-amd]
exten => s,1,Set(AMDSTATUS=)
exten => s,n,Set(AMDCAUSE=)
exten => s,n,EAGI(dc-amd,${ARG1},${ARG2},${ARG3},${ARG4},${ARG5},${ARG6},${ARG7},${ARG8},${ARG9},${ARG10})
exten => s,n(done),GotoIf($["${AMDSTATUS}" != ""]?ret)
exten => s,n,Set(AMDSTATUS=NOTSURE)
exten => s,n,Set(AMDCAUSE=TOOLONG-0)
exten => s,n,Set(DC_AMD_SOURCE=failopen)
exten => s,n,Set(DC_AMD_ERROR=agi_${TOLOWER(${AGISTATUS})})
exten => s,n(ret),Return()

exten => beep,1,Set(AMDSTATUS=)
exten => beep,n,Set(AMDCAUSE=)
exten => beep,n,EAGI(dc-amd,${ARG1},${ARG2},${ARG3},${ARG4},${ARG5},${ARG6},${ARG7},${ARG8},${ARG9},${ARG10},profile=beep)
exten => beep,n,Goto(s,done)
  1. In Admin > Custom Destinations, add a destination:
    • Target: dc-amd,s,1. To pass AMD() arguments, add them in brackets: dc-amd,s,1(2000,2000,1000,5000,120,50,4,256).
    • Description: for example, Drop Cowboy AMD.
    • Return: Yes.
    • Destination after return: where the call goes next, with AMDSTATUS set.
  2. For calls that leave a voicemail message, add a second one with target dc-amd,beep,1. Add this to /etc/dc-amd/dc-amd.conf too:
[beep]
wait_for_beep = yes
  1. Submit and Apply Config.

The arguments are the same nine as AMD(), in the same order. An empty argument takes its value from amd.conf, as AMD() does. See Arguments.

If you later install the module, delete this [dc-amd] context from extensions_custom.conf first. The module writes the same context, and FreePBX logs a warning while both exist.

Modes

Mode What happens on the call Use it to
Replace Detection decides, and dc-amd sets the variables. Run on Drop Cowboy Detection.
Shadow AMD() decides, as before. dc-amd records the same audio and sends it to Detection after the call returns to the dialplan. Both answers go to /var/log/dc-amd/results.jsonl. Compare before you switch.
Off AMD() decides. Nothing goes to Detection. Turn Detection off without changing your call flow.

Set the mode on the settings page, or with mode in /etc/dc-amd/dc-amd.conf if you set things up by hand. A change applies from the next call, with no reload. To compare the two in Shadow mode, run as root:

/var/lib/asterisk/agi-bin/dc-amd stats --since 24h

What gets set

AMDSTATUS is always one of AMD()'s values.

Result AMDSTATUS AMDCAUSE
A live person HUMAN HUMAN-<ms>-0
A voicemail greeting MACHINE GREETING-<ms>-0
The greeting ended with a beep MACHINE BEEP-<ms>-<beep end ms>
The greeting ended without a beep MACHINE GREETINGEND-<ms>-0
A full mailbox, or one that isn't set up MACHINE FULLMAILBOX-<ms>-0, NOTSETUP-<ms>-0
A carrier message or phone menu MACHINE INTERCEPT-<ms>-0, IVR-<ms>-0
A fax machine MACHINE FAX-<ms>-0
A call screener NOTSURE CALLSCREEN-<ms>-0
Nobody spoke MACHINE INITIALSILENCE-<ms>-<initialSilence>
No decision in time NOTSURE TOOLONG-<ms>
The caller hung up HANGUP Empty

<ms> is the time to the decision in milliseconds. The statuses for call screeners and silence can be changed in the config file, and dialers that match on AMD()'s own cause names can turn those on. See What gets set.

Variable Value
DC_AMD_TYPE Detection's answer: human, machine_start, machine_end_beep, machine_end_silence, machine_end_other, fax or unknown. Empty when Detection didn't decide.
DC_AMD_BEEP 1 when the greeting ended with a beep, otherwise 0.
DC_AMD_BEEP_MS When the beep ended, in milliseconds. Empty when there was none.
DC_AMD_SCREENER 1 for a call screener, otherwise 0.
DC_AMD_FAX 1 for a fax machine, otherwise 0.
DC_AMD_MS The time to the result, in milliseconds.
DC_AMD_SESSION The Detection session ID, for support. Empty when Detection didn't decide.
DC_AMD_SOURCE detection, native when AMD() decided, or failopen.
DC_AMD_ERROR Why Detection wasn't used. Empty otherwise.

Fail open

dc-amd never hangs up a call, and never holds it longer than the time limit: totalAnalysisTime, 5 seconds by default, or 30 seconds when waiting for the beep. If Detection can't answer, the call returns with AMDSTATUS=NOTSURE, AMDCAUSE=TOOLONG-<ms>, DC_AMD_SOURCE=failopen and the reason in DC_AMD_ERROR, then goes on to your next destination.

With When Detection is unavailable set to Native AMD (fail_open = native), dc-amd runs AMD() instead for the time that remains, if no audio has been read yet.

The [dc-amd] context also covers dc-amd itself failing to run, such as after it has been uninstalled. The call then returns at once with AMDSTATUS=NOTSURE, AMDCAUSE=TOOLONG-0 and DC_AMD_ERROR=agi_notfound or agi_failure.

DC_AMD_ERROR Meaning
config_missing, config_unreadable The config file is missing, or Asterisk can't read it.
config_insecure Other users have permission on the config file.
unknown_profile The beep destination was used and the config file has no [beep] section.
no_api_key No key is set.
connect_timeout, dns, connect_refused, tls, connect_failed The connection to Detection didn't open.
http_401, http_403 The key was refused, or this server's address is outside the key's allowed ranges.
http_402 The account has no funds.
http_429 The key reached its daily minute cap.
http_503 Detection is at capacity or briefly unavailable.
deadline No result within the time limit.
agi_notfound, agi_failure dc-amd isn't installed, or couldn't start.

Fail open lists the rest.

Wait for the beep

To leave a voicemail message, start it when the greeting ends. Use the wait for beep Custom Destination (dc-amd,beep,1) for those calls.

  • A machine comes back as MACHINE at the end of the greeting: at the beep, or when the greeting ends without one. Play your message right away.
  • A person still comes back as HUMAN as soon as they're heard.
  • The time limit is 30 seconds instead of 5.
  • A full mailbox, or one that isn't set up, comes back as MACHINE with AMDCAUSE starting FULLMAILBOX or NOTSETUP. Hang up on those instead of playing the message.

Wait for the beep on the settings page turns this on for every call, including the Drop Cowboy AMD destination. Leave it at No to keep fast answers on most calls and wait only where you use the beep destination.

Switch back

  • Right away: set Mode to Off, or mode = off in the config file. The next call runs AMD() instead.
  • For good, with the module: point everything that uses the Drop Cowboy Custom Destinations somewhere else. Then run fwconsole ma uninstall dcconnect and fwconsole reload. Uninstalling removes the context and the two Custom Destinations, and leaves /etc/dc-amd/dc-amd.conf in place.
  • For good, by hand: point those destinations elsewhere, delete the Custom Destinations and the [dc-amd] context, and Apply Config.
  • Then remove dc-amd with /var/lib/asterisk/agi-bin/dc-amd uninstall --purge, which also deletes the config file and logs.

Calls that still reach [dc-amd] after dc-amd is removed return as NOTSURE and carry on.

Dialer modules

A dialer module that writes its own AMD() step into the dialplan, such as XactDialer, keeps using AMD(). Replacing that step isn't supported yet. If the dialer lets you choose a destination for answered calls, choose a Drop Cowboy AMD Custom Destination there instead.

Common problems

  • The settings page says dc-amd is not installed. Run the dc-amd installer as root. See Install dc-amd.
  • Saving the settings page fails with a permissions error. Run fwconsole chown, then save again.
  • Every call comes back NOTSURE with DC_AMD_ERROR=unknown_profile. The beep destination was used and the config file has no [beep] section. Save the settings page once, or add the section by hand.
  • Every call comes back NOTSURE with config_insecure. Something made the config file readable by other users. Run fwconsole chown.
  • Machines come back NOTSURE with TOOLONG. The greeting outlasted the 5 second limit. Use the wait for beep destination, or a Custom Destination of your own that passes a longer totalAnalysisTime, such as dc-amd,s,1(,,,8000).
  • The call doesn't reach my next destination. Check that the Custom Destination has Return set to Yes and a destination after return.
  • FreePBX logs that extensions_custom.conf already defines [dc-amd]. Delete the hand-pasted context. The module writes its own.

Code samples

The requests from this page, ready to copy. Set DC_KEY and DC_SECRET to your API key pair first.

Install dc-amd
curl -fsSLO https://github.com/Drop-Cowboy/pbx-connect/releases/latest/download/dc-connect-linux-amd64
curl -fsSLO https://github.com/Drop-Cowboy/pbx-connect/releases/latest/download/SHA256SUMS
sha256sum --ignore-missing -c SHA256SUMS
chmod +x dc-connect-linux-amd64
sudo ./dc-connect-linux-amd64 amd install
Install it
fwconsole ma downloadinstall https://github.com/Drop-Cowboy/pbx-connect/releases/latest/download/dcconnect.tgz
fwconsole reload
Modes
/var/lib/asterisk/agi-bin/dc-amd stats --since 24h