Connect Asterisk

This page connects an Asterisk server to Drop Cowboy® in three ways:

  • Text to speech. dc-tts speaks text in Drop Cowboy voices from the dialplan, and keeps a cache of the audio it has fetched.
  • AI agents. A Dial() line sends a live call to one of your published AI agents over SIP.
  • Sends. The dialplan triggers a send preset, such as a voicemail or a text after a missed call. The preset fixes what is sent.

For answering machine detection, see Replace Asterisk AMD. It uses the same binary.

What you install dc-connect, one static Linux binary, linked as dc-tts
What you need A connector key, with the scopes for the parts you use
Where secrets live /etc/dc-tts/dc-tts.conf and your Asterisk config, mode 0640
Versions Asterisk 13 to 22. The AI agent example uses PJSIP

Before you start

  • A connector key. Create one in the dashboard or with the API. See Create a connector key. Give it tts:synthesize for text to speech, connect:trigger for sends, and the SIP scope for AI agents described in SIP login. Set allowed_cidrs to the public address your Asterisk server connects from.
  • Outbound access from the server to api-v2.dropcowboy.com on port 443. AI agents also need sip.dropcowboy.com on the SIP port you choose, and RTP back to your server.
  • Root access on the server.
  • A voice_id. Each voice's voice_id is in the dashboard, or comes from GET /voice/public/voices. See Pick a voice.

Text to speech

Install dc-tts

Run this as root:

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 tts install --default-voice VOICE_ID

On an ARM server, use dc-connect-linux-arm64. The installer:

  1. copies the binary to /var/lib/asterisk/agi-bin/dc-connect and links dc-tts to it;
  2. asks for your connector key and its secret without showing them;
  3. writes /etc/dc-tts/dc-tts.conf, mode 0640, owned by root:asterisk;
  4. creates the cache, /var/lib/asterisk/sounds/dc-tts, and /var/log/dc-tts;
  5. runs dc-tts check, which checks the key.

To install from a script, pipe the key and then the secret in, one per line, with --key-stdin. If dc-amd is already installed, the two share the binary, and uninstalling one leaves the other working.

Speak in the dialplan

same => n,AGI(dc-tts,VOICE_ID,Thanks for calling. Press 1 to talk to us.)
same => n,GotoIf($["${DC_TTS_STATUS}" = "OK"]?spoken,1:fallback,1)

The first argument is a voice_id or a name from the [voices] section of the config file. Leave it empty, as in AGI(dc-tts,,Hello), to use default_voice. The text may contain commas.

The first call with a text fetches the audio. Later calls with the same voice and text play it from the cache. You're billed per character fetched, and each fetch counts toward the key's daily spend cap.

Set these before the AGI line to change what it does:

Variable Effect
DC_TTS_PLAY=no Fetch the audio but don't play it. Play ${DC_TTS_FILE} later with Playback() or Background().
DC_TTS_ESCAPE Digits that stop playback, such as 0123456789#.
DC_TTS_FORMAT wav_8k, the default, or wav_16k for wideband calls.

dc-tts sets:

Variable Value
DC_TTS_STATUS OK, FAILED, TIMEOUT or HANGUP.
DC_TTS_ERROR Why there is no audio, such as http_401, http_402, http_5xx, timeout, unknown_voice, no_text or config. Empty after OK.
DC_TTS_SOURCE cache or api.
DC_TTS_FILE The audio file, without its extension.
DC_TTS_DTMF The digit that stopped playback.

dc-tts never hangs up a call. If new audio takes longer than timeout_ms, the call carries on with DC_TTS_STATUS=TIMEOUT. Route on DC_TTS_STATUS to play a recording instead.

The config file

/etc/dc-tts/dc-tts.conf holds the key and the cache settings. Set DC_TTS_CONFIG in the environment to use another path.

Setting Values Default
api_key, api_secret The connector key and its secret Written by the installer
timeout_ms How long to wait for new audio 8000
cache_dir Where fetched audio is kept /var/lib/asterisk/sounds/dc-tts
cache_max_mb, cache_max_age_days Cache limits. 0 turns a limit off. 500, 90
default_voice A voice_id, or a name from [voices] The --default-voice you installed with
log_file A path, or none /var/log/dc-tts/dc-tts.log
[voices] One name = voice_id line per voice

For example:

default_voice = support

[voices]
support = 7d2a9e4b-1c6f-4b3a-8e5d-2f9c7a1b4e63

dc-tts refuses the file if other users can read it. The key never goes on a command line, in a URL or in the log. The log records the voice, the length of the text and the outcome, never the text.

Commands

Run these from /var/lib/asterisk/agi-bin:

Command What it does
./dc-tts check Checks the config file and the key.
./dc-tts synth --voice VOICE_ID --format wav_8k "Hello" Fetches one prompt into the cache and prints its path. Use it to test a voice.
./dc-tts prune Applies the cache limits now.
sudo ./dc-tts uninstall Removes the link. Add --purge to remove the config file, cache and logs too.

AI agents over SIP

A call you send to sip:<agent_id>@sip.dropcowboy.com is answered by that AI agent. Your server signs in with the connector key's SIP login:

  • The username is the key's key_id.
  • The password is its sip_secret, shown once when the key gets the SIP scope.
  • The realm is sip.dropcowboy.com.

Your account must have SIP calls to AI agents turned on. The key's allowed_cidrs apply to these calls, so include the address your server sends SIP from. The agent must be published. See Publish an agent.

Add the endpoint

Add this to pjsip.conf. It uses TLS on port 5081. For UDP or TCP, use port 5080 and a UDP or TCP transport.

[transport-tls]
type=transport
protocol=tls
bind=0.0.0.0:5061
cert_file=/etc/asterisk/keys/asterisk.pem
method=tlsv1_2

[dropcowboy-agents-auth]
type=auth
auth_type=userpass
username=<key_id>
password=<sip_secret>

[dropcowboy-agents]
type=aor
contact=sip:sip.dropcowboy.com:5081\;transport=tls

[dropcowboy-agents]
type=endpoint
transport=transport-tls
context=from-dropcowboy
outbound_auth=dropcowboy-agents-auth
aors=dropcowboy-agents
disallow=all
allow=ulaw,alaw
direct_media=no
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes

Keep your existing TLS transport if you have one, and name it on the endpoint. Make pjsip.conf readable only by root and the Asterisk group, because it holds the SIP secret. Then run asterisk -rx "pjsip reload". A new transport only starts when Asterisk restarts, so restart it if you added one.

Dial the agent

exten => 7001,1,Dial(PJSIP/4c8e2a6f-3b9d-4e1a-9c7b-5d2f8a3e6b19@dropcowboy-agents,45)
 same => n,GotoIf($["${DIALSTATUS}" = "ANSWER"]?done)
 same => n,Goto(fallback,s,1)
 same => n(done),Hangup()

The user part of the dial string is the agent's agent_id. Asterisk answers the sign-in challenge on its own. Anything that can reach an extension, such as an IVR option or a queue's failover, can send calls to 7001.

Hand calls back

The agent can send a call back to your phone system with a blind transfer. Where it can send calls is set by a preset on the key. See Connector presets:

  • refer_targets lists transfers the agent can choose during the call, each a name and the user on your phone system.
  • outcome_routes maps an outcome the agent reports to the user the call goes back to when the agent finishes.

The transfer arrives on the endpoint's context, from-dropcowboy above, at the extension named by user. Add only the extensions you expect:

[from-dropcowboy]
exten => 2001,1,Goto(from-internal,2001,1)
exten => 2002,1,Queue(sales)

Transfers go only to the address the call came from. The result of every call also arrives on the ai_agent.* webhooks. See Call results.

Sends from the dialplan

A send preset fixes what is sent: the action, the content, the phone line, the dispositions that may trigger it, its consent rule and the connector key it uses. The dialplan supplies only who to send it to.

Create a preset

  1. In the dashboard, open Settings > PBX Connect and click New send preset.
  2. Choose what it sends: Ringless voicemail, Text message, Voice broadcast or AI voice broadcast, and its content and phone line.
  3. Under Connector key, choose a key with connect:trigger.
  4. Under Dispositions that trigger it, list the dial results that may send, such as NOANSWER and BUSY. Leave it empty to allow any.
  5. Choose the consent rule. See Consent.
  6. Copy the Dispo Call URL. It is shown once.

The URL carries the preset's send token, so keep it as secret as a key. For Asterisk, use the part before the ?. It is SEND_URL below.

Call it after the call

CURL() posts the fields from a hangup extension, after the caller is gone. Keep the send URL in a file that only root and Asterisk can read, such as extensions_dropcowboy.conf included from extensions.conf:

[globals]
DC_SEND_URL=SEND_URL

[outbound-calls]
exten => _1NXXNXXXXXX,1,Set(DC_PHONE=+${EXTEN})
 same => n,Dial(PJSIP/${EXTEN}@my-trunk,30)
 same => n,Hangup()
exten => h,1,Set(CURLOPT(httptimeout)=5)
 same => n,Set(DC_RESULT=${CURL(${DC_SEND_URL},lead_id=${UNIQUEID}&uniqueid=${UNIQUEID}&phone_number=${URIENCODE(${DC_PHONE})}&dispo=${DIALSTATUS})})
 same => n,Verbose(1,Drop Cowboy send: ${DC_RESULT})

CURL() needs func_curl, which most builds load. Check with asterisk -rx "module show like func_curl".

Field Required Meaning
lead_id Yes Your id for the lead: 1 to 64 letters, digits, ., _, : or -.
uniqueid Yes Your id for the call, with the same characters.
phone_number Yes The number to send to, with + and the country code, or without them and with phone_code.
phone_code No The country code of a number without +. Defaults to 1.
dispo No The dial result. It must be one of the preset's dispositions, compared without regard to case.
postal_code No The lead's postal code, passed on as postal_code is in an API send.
Your consent field With a lead field rule The field the rule names, with the lead's value.

A preset, lead_id and uniqueid name one send. Calling the URL again with the same three never sends twice, so it is safe to retry.

What comes back

The route answers 200 with a JSON body:

{ "status": "queued", "send_id": "a9c3e8f1-4b2d-4a7c-8e9b-1c2d3e4f5a6b" }
status Meaning
queued Accepted. It goes through the same checks as a send made with the API, including Do Not Call and calling hours. The outcome shows under Sends on the PBX Connect page.
refused The consent rule wasn't met. reason is Opt-in Missing and reason_code is 6011.
skipped The disposition isn't one that triggers the preset. Nothing is sent.
duplicate This send was already made. send_status is its status.

Errors come back as problem details:

Status Problem type What to do
400 invalid-request A required field is missing. The message names it.
401 unauthorized The preset's connector key was revoked. Bind another key on the PBX Connect page.
403 preset-not-bound The preset has no connector key. Bind one on the PBX Connect page.
403 ip-not-allowed Add the server's address to the key's allowed_cidrs.
404 not-found The send token is wrong, or the preset was revoked.
429 daily-cap-reached The key reached a daily cap. Wait for 00:00 UTC, or raise it.
503 service-unavailable Retry in a few seconds with the same fields.

Texts need a 10DLC line

A preset that sends a text sends from its phone line. That line must be linked to a registered texting (10DLC) campaign, or the preset can't be created.

Every preset has a consent rule, and a send that doesn't meet it is refused with 6011:

  • A lead field records consent. Name the field and the value that means consent, such as rvm_optin and Y. Pass the field on every call, as in &rvm_optin=${DB(optin/${DC_PHONE})}. A missing or different value is refused.
  • We attest every lead consented. Your account attests that every number this preset sends to has consented.

A send that passes its consent rule then goes through the same checks as a send made with the API. See Consent.

Common problems

  • DC_TTS_STATUS is FAILED with http_401. The key or secret in dc-tts.conf is wrong, or the key was revoked. Run ./dc-tts check.
  • http_403, or dc-tts check says the address isn't allowed. Add the server's public address to the key's allowed_cidrs.
  • http_402. The account balance or the key's daily spend cap ran out.
  • unknown_voice. The voice isn't a voice_id and isn't under [voices]. Check the spelling, or use the voice_id.
  • dc-tts refuses the config file. Other users can read it. Run chmod 0640 /etc/dc-tts/dc-tts.conf.
  • Every prompt is TIMEOUT. The server can't reach api-v2.dropcowboy.com on port 443 in time. Check the firewall, or raise timeout_ms.
  • The agent call fails with 403. The SIP username or secret is wrong, the key lacks the SIP scope, or the server's address isn't in allowed_cidrs.
  • The agent call fails with 404. The agent_id is wrong, or the agent isn't published.
  • The agent call fails with 402. The balance or the key's daily minute cap ran out.
  • The agent call fails with 486. The call went past max_concurrent or max_cps on the key. Raise them, or clear them for no cap.
  • The agent can't hear the caller. RTP from Drop Cowboy can't reach the server. Open your RTP ports to it, or keep rtp_symmetric and rewrite_contact on.
  • A transfer back fails. The user has no extension in from-dropcowboy, or allow_transfer is off on the endpoint.
  • Every send comes back refused. The consent field is missing from the call, or its value differs from the preset's.
  • Every send comes back skipped. dispo doesn't match the preset's dispositions. Asterisk's DIALSTATUS values are upper case, such as NOANSWER.

Ringless voicemail technology delivers messages directly to voicemail inboxes. Delivery success depends on carrier compatibility, device type, and recipient settings. While designed for voicemail delivery, technical factors may affect performance. Drop Cowboy does not guarantee delivery rates or specific outcomes.

While Drop Cowboy provides tools to support compliance efforts, customers remain solely responsible for obtaining proper consent, maintaining opt-out lists, and complying with all federal and state telemarketing regulations. Consult with your legal counsel to ensure your specific use case and consent mechanisms comply with applicable laws.

This information is for educational purposes only and does not constitute legal advice. Regulations vary by jurisdiction and use case. Always consult with qualified legal counsel to ensure your specific practices comply with applicable federal and state laws.

Code samples

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

Install dc-tts
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 tts install --default-voice VOICE_ID