Asterisk and FreePBX
Send a survey after each answered call on Asterisk or FreePBX, from the call detail record Asterisk writes when a call ends.
What it does
When a call ends, Asterisk writes a call detail record (CDR) and can publish it as the manager event Cdr. A small
relay on the phone system's server sends that record to Sayvara, which queues one survey for each answered call with a
customer.
Status
Add-on, available on request. The recipe below is built into Sayvara and tested with records in Asterisk's Cdr
event format. Our team sets it up with you and checks it on your Asterisk or FreePBX before your first surveys go
out. Ask at support@sayvara.com.
The recipe
- Turn on the manager CDR backend in
/etc/asterisk/cdr_manager.confand add the call's linked id:
[general]
enabled = yes
[mappings]
linkedid => LinkedID- Create a manager user for the relay in
manager.conf(FreePBX:manager_custom.conf) withread = cdrandpermitset to the server itself only. Never open the manager port to the internet. - Run the relay on the same server: it logs in to the manager interface, and for each
Event: Cdrit turns theKey: Valuelines into one JSON object with the same keys and posts it tohttps://api.sayvara.com/v1/triggers/pbx/asteriskwithAuthorization: Bearer <your API key>. When signed triggers are on, it also adds theSayvara-Signature(see Phone systems). This shell step signs and posts one record ($bodyholds the JSON):
t=$(date +%s)
sig=$(printf '%s.%s' "$t" "$body" | openssl dgst -sha256 -hmac "$SECRET" -hex | sed 's/^.* //')
curl -sS -m 5 -H 'Content-Type: application/json' -H "Authorization: Bearer $SAYVARA_API_KEY" \
-H "Sayvara-Signature: t=$t,v1=$sig" --data "$body" https://api.sayvara.com/v1/triggers/pbx/asterisk- Asterisk writes local time without a zone. Add
?utcOffset=+03:00(the server's time zone) to the address if it differs from your country's. - Make an answered test call. The call appears in Sayvara under Contacts.
Direction
Asterisk records no direction. Sayvara treats a call as inbound when only the destination is a short extension, and
as outbound when only the source is. To set it yourself, add Direction (inbound, outbound or internal) to the
record, for example as a [mappings] field filled from a channel variable your inbound and outbound routes set.
How the call is read
| Sayvara | Asterisk Cdr |
|---|---|
| Call id | LinkedID, else UniqueID |
| Customer number | Source (inbound) or Destination (outbound) |
| Answered | Disposition is ANSWERED |
| Talk time | BillableSeconds |
| End time | EndTime |
For the answers Sayvara gives, see Phone systems.
Was this page helpful?
Thanks. Need more help? Email support@sayvara.com