FreeSWITCH voicemail detection with one Lua script
RingValee brings FreeSWITCH voicemail detection that listens to the answer. A short Lua script hands the opening seconds of every answered call to mod_audio_stream, and about 2 seconds later your dialplan has AMDSTATUS set to HUMAN, MACHINE or FALLBACK.
FreeSWITCH never shipped an AMD() of its own
Asterisk has a built-in answering machine detector; FreeSWITCH doesn't. Here's what people usually reach for, and what each one actually tells you.
| Option | What it really detects | The catch |
|---|---|---|
mod_avmd | The beep at the end of a voicemail greeting | It hears the beep, not who answered, and only after the greeting has played |
| Timing-based modules | Silence and speech lengths, like Asterisk AMD() | The same mistakes on hesitant people and short greetings |
| Your carrier's AMD | Whatever that carrier offers on its own calls | Tied to one carrier and its API |
| RingValee | Whether a person or a recording answered; also tones (busy, SIT, fax, ringback) and recorded hellos | Works with any trunk; needs mod_audio_stream |
It's the same detection VICIdial users of RingValee get. How it decides
What happens after the callee picks up
- AnsweredThe call lands in your AMD extension, which runs
ringvalee_amd.lua. - Streaming
mod_audio_streamsends the callee's audio (8 kHz, mono) to RingValee over a secure WebSocket, your key in the request header. - ~2 s · VerdictRingValee answers once. Unclear calls get up to 3.2 s. The answer comes back to FreeSWITCH as an event.
- Routed
AMDSTATUSandAMDCAUSEare filled in, the stream is closed, and control goes back to your dialplan.
mod_audio_stream all give FALLBACK before any audio is used. If something breaks after streaming has started, the call is treated as MACHINE / UNKNOWN. Agents only get calls RingValee is sure about.Three things on the server
Load mod_audio_stream
mod_audio_stream, an open-source FreeSWITCH module, sends call audio to a WebSocket. Follow its README to install it (there are packages for recent Debian with SignalWire's FreeSWITCH repository) and load it:
fs_cli -x "load mod_audio_stream"
# load it on every start too: add to autoload_configs/modules.conf.xml
# <load module="mod_audio_stream"/>
mod_audio_stream isn't ours and isn't shipped by us. The community edition carries its own license, AGPL-3.0 plus a linking exception for FreeSWITCH. Check that it fits your setup.
Drop in the script
cd /usr/share/freeswitch/scripts # some installs use /etc/freeswitch/scripts
curl -fsSLO https://www.ringvalee.com/assets/ringvalee_amd.lua
It needs mod_lua, which comes with FreeSWITCH, and nothing else.
Make a key
Create a free account, open WS keys and make a key. One per FreeSWITCH server keeps the dashboard easy to read.
Route on the answer
One extension runs the script; three small ones pick up the result. They can live in dialplan/default.xml or a context of your own:
<extension name="ringvalee_amd">
<condition field="destination_number" expression="^ringvalee_amd$">
<action application="lua" data="ringvalee_amd.lua wss://amd.ringvalee.com/ YOUR_KEY 4500"/>
<action application="transfer" data="after_amd_${AMDSTATUS} XML default"/>
</condition>
</extension>
<extension name="after_amd_human">
<condition field="destination_number" expression="^after_amd_HUMAN$">
<action application="transfer" data="sales_queue XML default"/> <!-- your agents -->
</condition>
</extension>
<extension name="after_amd_machine">
<condition field="destination_number" expression="^after_amd_MACHINE$">
<action application="hangup"/> <!-- or play your message first -->
</condition>
</extension>
<extension name="after_amd_fallback">
<condition field="destination_number" expression="^after_amd_FALLBACK$">
<action application="transfer" data="sales_queue XML default"/> <!-- or your old detection -->
</condition>
</extension>
FreeSWITCH fills in ${AMDSTATUS} when the transfer runs, which is after the script has finished, so the call lands on after_amd_HUMAN, after_amd_MACHINE or after_amd_FALLBACK. Want a separate route for screened calls or tones? Check AMDCAUSE: SCREENING, TONE, BUSY, SILENCE and so on.
Point outbound calls at it
Have the dialer originate each call into that extension. It only runs once the callee answers, which is exactly when detection should start:
originate {origination_caller_id_number=15550002222}sofia/gateway/carrier_a/15557654321 ringvalee_amd XML default
Dialers on the event socket do the same thing with bgapi originate.
Check it before going live
Is the module there?
Run
fs_cli -x "uuid_audio_stream". Usage text means it's loaded; "command not found" means it isn't.Call your own phone
Let it ring to voicemail: the log says
MACHINE. Pick up and say hello:HUMAN. Log lines start withringvalee_amd:.Open the dashboard
Every test call is there: verdict, reason, how long it took, and a recording of what was heard.
FreeSWITCH questions
FusionPBX and other FreeSWITCH-based systems?
They work if two things are possible: loading mod_audio_stream and adding one dialplan entry. In FusionPBX the dialplan editor in the admin screens does the second part.
Which audio leaves my server?
Just the far end of the call (mono, 8 kHz, 16-bit) between answer and verdict, so normally 2 to 3.2 seconds of it. The stream is closed the moment the verdict lands.
Where does the key go?
Into an Authorization header on the WebSocket handshake, sent over TLS through mod_audio_stream's STREAM_EXTRA_HEADERS. It's never in the URL.
Can mod_avmd stay?
Yes. It finds the voicemail beep, which is handy for timing a voicemail drop once RingValee has said MACHINE.
No mod_audio_stream on my system?
If your system can push 16-bit, 8 kHz audio over a WebSocket, it can call the voicemail detection API directly.
Let your agents talk to people, not greetings
25,000 calls a month free, no card. If anything goes wrong, your dialer quietly falls back to Asterisk AMD() for that call.