Help centre
العربية Back to sayvara.com

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.

Updated

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

  1. Turn on the manager CDR backend in /etc/asterisk/cdr_manager.conf and add the call's linked id:
[general]
enabled = yes

[mappings]
linkedid => LinkedID
  1. Create a manager user for the relay in manager.conf (FreePBX: manager_custom.conf) with read = cdr and permit set to the server itself only. Never open the manager port to the internet.
  2. Run the relay on the same server: it logs in to the manager interface, and for each Event: Cdr it turns the Key: Value lines into one JSON object with the same keys and posts it to https://api.sayvara.com/v1/triggers/pbx/asterisk with Authorization: Bearer <your API key>. When signed triggers are on, it also adds the Sayvara-Signature (see Phone systems). This shell step signs and posts one record ($body holds 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
  1. 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.
  2. 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.