Complete Guide to Asterisk Functions for Call Center Development

Published On: February 7, 2026
Follow Us
Installing Asterisk 20 from source on Ubuntu

When building a call center with Asterisk/FreePBX and FastAGI (Java), tracking all call events—incoming, ring, answer, end—is critical. Asterisk provides built-in functions, variables, and dialplan commands that make this straightforward.

This article will cover:

  1. Time & Date Functions
  2. CDR Variables
  3. Caller & Channel Info
  4. Dialplan Functions
  5. Queue & Agent Variables
  6. Hangup / Post-call Functions
  7. Example Dialplan for Call Tracking
  8. Best Practices

1. Time & Date Functions

Asterisk can provide both epoch time and formatted time, which is crucial for logging and reporting.

Function / VariablePurposeExample
${EPOCH}Current Unix timestamp (seconds since 1970-01-01 UTC)Set(INCOMING_EPOCH=${EPOCH})
STRFTIME(epoch,[timezone],format)Convert epoch to human-readable date/timeSet(INCOMING_TIME=${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
${TIME}Current system time (HH:MM:SS)NoOp(Time now: ${TIME})
${DATE}Current system date (YYYYMMDD)NoOp(Date now: ${DATE})
${HOUR}Current hourNoOp(Hour: ${HOUR})
${MINUTE}Current minuteNoOp(Minute: ${MINUTE})
${SECOND}Current secondNoOp(Second: ${SECOND})

Usage: Store these values at different stages—call arrival, agent answer, call end—to log or calculate durations.


2. Call Detail Record (CDR) Variables

CDR is Asterisk’s built-in call logging system. It tracks important metrics:

VariablePurposeExample
${CDR(start)}Call start timestampNoOp(Call start: ${CDR(start)})
${CDR(answer)}Call answer timestampNoOp(Call answered: ${CDR(answer)})
${CDR(end)}Call end timestampNoOp(Call ended: ${CDR(end)})
${CDR(duration)}Total call duration (seconds)NoOp(Total duration: ${CDR(duration)})
${CDR(billsec)}Duration from answer to hangupNoOp(Billable seconds: ${CDR(billsec)})
${CDR(disposition)}Call result (ANSWERED, NO ANSWER, BUSY, FAILED)NoOp(Result: ${CDR(disposition)})
${CDR(userfield)}Custom field for trackingSet(CDR(userfield)=SupportQueue)

Tip: For call center metrics, combine CDR with custom channel variables for detailed reporting.


3. Caller & Channel Information

These variables provide caller identification and channel context:

VariablePurposeExample
${CALLERID(num)}Caller’s numberNoOp(Caller ID: ${CALLERID(num)})
${CALLERID(name)}Caller’s nameNoOp(Caller Name: ${CALLERID(name)})
${CHANNEL}Current channel nameNoOp(Channel: ${CHANNEL})
${UNIQUEID}Unique call IDNoOp(Unique call ID: ${UNIQUEID})
${EXTEN}Current extension dialedNoOp(Extension: ${EXTEN})
${CONTEXT}Current dialplan contextNoOp(Context: ${CONTEXT})
${HANGUPCAUSE}Reason for hangupNoOp(Hangup cause: ${HANGUPCAUSE})
${DIALEDTIME}Duration of dial attempt (seconds)NoOp(Dialed duration: ${DIALEDTIME})
${ANSWEREDTIME}Time when channel was answeredNoOp(Answered at: ${ANSWEREDTIME})

4. Dialplan Functions / Commands

Function / CommandPurposeExample
SET(variable=value)Set a channel variableSet(INCOMINGTIME=${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
GET VARIABLE(variable)Read a variableNoOp(Caller ID: ${CALLERID(num)})
NoOp(text)Log message to consoleNoOp(Incoming call from ${CALLERID(num)})
Dial(tech/endpoint,timeout,options)Connect to agent or endpointDial(SIP/100,30,tT)
Queue(name[,options])Send call to queueQueue(support,t,,,30)
AGI(script,args...)Call AGI/FastAGI scriptAGI(log_call_times.agi,${CALLERID(num)},${INCOMINGTIME})
Hangup()End the callHangup()
Gosub(context,exten,priority,args...)Call another subroutineGosub(log_call,h,1,${UNIQUEID})

5. Queue & Agent Variables

For call centers using Asterisk Queues:

Variable / FunctionPurposeExample
${QAGENT}Agent who answeredNoOp(Agent answered: ${QAGENT})
${QUEUENAME}Queue nameNoOp(Queue: ${QUEUENAME})
${QUEUEPOSITION}Caller’s position in queueNoOp(Queue position: ${QUEUEPOSITION})
${QUEUEWAIT}Time caller waited in queueNoOp(Queue wait time: ${QUEUEWAIT})
${QUEUECALLERID}Caller ID in queueNoOp(Queue caller: ${QUEUECALLERID})
Queue()Send call to queueQueue(support,t,,,30)

6. Hangup / Post-Call Functions

To capture call end details:

Variable / FunctionPurposeExample
h extensionTrigger on hangupexten => h,1,NoOp(Call ended)
${HANGUPCAUSE}Reason for hangupNoOp(Hangup cause: ${HANGUPCAUSE})
${DIALEDTIME}Dial durationNoOp(Dial duration: ${DIALEDTIME})
${ANSWEREDTIME}Time call answeredNoOp(Answered at: ${ANSWEREDTIME})
AGI(script)Call AGI/FastAGI for loggingAGI(log_call_times.agi,${CALLERID(num)},${INCOMINGTIME},${ANSWEREDTIME},${ENDTIME})

7. Full Example Dialplan for Call Tracking

[call-center]
exten => 100,1,NoOp(Incoming call from ${CALLERID(num)})
 same => n,Set(INCOMINGTIME=${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
 same => n,NoOp(Call received at ${INCOMINGTIME})

 ; Send to queue
 same => n,Queue(support,t,,,30)
 same => n,Set(ANSWEREDTIME=${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
 same => n,NoOp(Call answered at ${ANSWEREDTIME}, by agent ${QAGENT})

 ; Hangup extension logs end
exten => h,1,NoOp(Call hangup)
 same => n,Set(ENDTIME=${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)})
 same => n,AGI(log_call_times.agi,${CALLERID(num)},${INCOMINGTIME},${ANSWEREDTIME},${ENDTIME})

Explanation:

  1. Incoming time captured with EPOCH → formatted with STRFTIME.
  2. Call sent to a queue → after answer, record ANSWEREDTIME.
  3. Hangup triggers h extension → record ENDTIME.
  4. FastAGI is used to log all times to database.

8. Best Practices for Call Center Call Tracking

  1. Use EPOCH for precision, store as DATETIME in DB.
  2. Combine CDR + custom channel variables for metrics like agent answer time.
  3. Use h extension for end-of-call logging to capture hangup details.
  4. For queue-based call centers, log ${QAGENT}, ${QUEUEWAIT}, ${QUEUEPOSITION}.
  5. Always format times for readability using STRFTIME.
  6. For Java FastAGI, pass all variables as parameters rather than computing times in Java.

✅ This is a complete reference for all Asterisk functions and variables used in call centers for time tracking, call logging, and queue management.

sapan singh

👨‍💻 About Sapan Singh Hi, I’m Sapan Singh — a passionate software developer with a strong love for technology, gaming, and building useful digital tools.

Join WhatsApp

Join Now

Join Telegram

Join Now

Leave a Comment