Professional Documents
Culture Documents
Predefined Channel Variables in Asterisk Thecodeblocks
Predefined Channel Variables in Asterisk Thecodeblocks
ASTERISK
There are some channel variables set by Asterisk that you can refer to in your dial
plan definitions. Asterisk-defined variables, in contrast to user-defined variables, are
case sensitive.
${CHANNEL}
The ${CHANNEL} variable contains the name of the current channel. It typically
consists of a channel technology prefix, followed by a unique identifier. For example,
"SIP/1234-00000123" or "DAHDI/2-1". You can use this variable to log or display the
channel name in your dial plan or custom applications. Here's an example:
In this example, when the call reaches extension 100, the channel name is displayed
using the ${CHANNEL} variable. The Verbose application logs the channel name in
the Asterisk console.
${CALLERID(num)}
The ${CALLERID(num)} variable represents the Caller ID number of the calling party.
It contains the incoming caller's phone number. You can use this variable for call
routing, database lookups, or to customize call handling based on the caller's
number. Here's an example:
In this example, when the call reaches extension 200, the caller's number is stored in
the caller_num variable using ${CALLERID(num)}. The Verbose application logs the
caller's number in the Asterisk console.
${CALLERID(name)}
Similar to ${CALLERID(num)}, ${CALLERID(name)} holds the Caller ID name associated
with the calling party. It represents the incoming caller's name if available. You can
use this variable to personalize call handling or display the caller's name on a display
device. Here's an example:
In this example, when the call reaches extension 300, the caller's name is stored in
the caller_name variable using ${CALLERID(name)}. The Verbose application logs the
caller's name in the Asterisk console.
${EXTEN}
The ${EXTEN} variable holds the current extension being dialed or processed in the
dial plan. It provides information about the intended destination of the call. You can
utilize this variable to determine the specific extension dialed and perform specific
actions or routing based on the dialed extension. Here's an example:
In this example, when a call reaches an extension starting with "4" followed by three
digits, the ${EXTEN} variable captures the dialed extension. The NoOp application
logs the dialed extension in the Asterisk console.
${CONTEXT}
The ${CONTEXT} variable stores the current context in the dial plan. A context
defines a section of the dial plan that determines call routing and call handling rules.
It represents the section of the dial plan where the call is currently located. This
variable is useful for conditional routing or executing different actions based on the
current context. Here's an example:
[internal]
exten => 500,1,Set(context_name=${CONTEXT})
${UNIQUEID}
The ${UNIQUEID} variable contains the unique identifier assigned to the channel
when it was created. It provides a unique reference to the call throughout its
lifecycle. This identifier is useful for tracking and correlating events related to a
specific call. Here's an example:
In this example, when the call reaches extension 600, the unique ID of the channel is
stored in the unique_id variable using ${UNIQUEID}. The Verbose application logs
the unique ID in the Asterisk console.
${DIALEDPEERNAME}
In outbound calls, the ${DIALEDPEERNAME} variable stores the name of the called
peer. It represents the peer or endpoint being dialed to establish the outbound call.
You can use this variable to extract the called party's name and perform actions
specific to the dialed peer. Here's an example:
In this example, when the call reaches extension 700, an outbound call is made to a
SIP provider using the ${EXTEN} variable. The ${DIALEDPEERNAME} variable
captures the name of the called peer, and the Verbose application logs it in the
Asterisk console.
${DIALEDPEERNUMBER}
Similar to ${DIALEDPEERNAME}, ${DIALEDPEERNUMBER} holds the number dialed
to reach the called peer in outbound calls. It contains the dialed number, which can
be extracted and used for call routing, database lookups, or customized call
handling. Here's an example:
In this example, when the call reaches extension 800, an outbound call is made to a
SIP provider using the ${EXTEN} variable. The ${DIALEDPEERNUMBER} variable
captures the dialed number, and the Verbose application logs it in the Asterisk
console.
${CALLERID(dnid)}
The ${CALLERID(dnid)} variable represents the Dialed Number Identification Service
(DNIS) information. It contains the number that was dialed to reach the current
context. This variable can be used to extract the dialed number and perform specific
actions or routing based on the dialed number, such as IVR (Interactive Voice
Response) menu selections. Here's an example:
In this example, when the call reaches extension 900, the ${CALLERID(dnid)} variable
captures the dialed number, and the Verbose application logs it in the Asterisk
console.
${CHANNEL(language)}
The ${CHANNEL(language)} variable stores the language setting for the channel. It is
often used to determine the preferred language for playing prompts or interacting
with the caller. Here's an example:
In this example, when the call reaches extension 1000, the ${CHANNEL(language)}
variable captures the language setting of the channel, and the Verbose application
logs it in the Asterisk console.
${SIP_CODEC}
The ${SIP_CODEC} variable contains the codec negotiated for the SIP channel. It
represents the audio codec being used for the call. This variable is particularly useful
for implementing custom call handling based on the codec in use. Here's an
example:
In this example, when the call reaches extension 1100, the ${SIP_CODEC} variable
captures the codec negotiated for the SIP channel, and the Verbose application logs
it in the Asterisk console.
${STRFTIME}
The ${STRFTIME} variable allows you to retrieve the current date and time in a
specified format. It can be used to generate timestamps or time-related information
during the call. Here's an example:
${CHANNEL(state)}
The ${CHANNEL(state)} variable represents the state of the current channel. It
indicates the current state of the channel, such as "Ring", "Up", "Down", or "Ringing".
Here's an example:
In this example, when the call reaches extension 1600, the ${CHANNEL(state)}
variable captures the state of the channel after a brief wait. The Verbose application
logs the channel state in the Asterisk console.
${MIXMONITOR_FILENAME}
The ${MIXMONITOR_FILENAME} variable contains the file name of the recorded
call when the MixMonitor application is used. It allows you to access the recorded
file name for further processing or storage. Here's an example:
${DIALSTATUS}
To get the state of the called channel in an Asterisk dial plan, you can use the
${DIALSTATUS} channel variable. The ${DIALSTATUS} variable stores the status of
the last attempted dial operation. Here's an example of how to use it:
In this example, when the call reaches extension 1000, the Dial application is used to
dial the SIP endpoint "device1". After the dial operation, the ${DIALSTATUS} variable
captures the status of the call. The Verbose application is then used to log the dial
status in the Asterisk console.
"TORTURE": The call was considered too demanding for the system.
By accessing the ${DIALSTATUS} variable, you can perform different actions or make
decisions based on the state of the called channel within your dial plan.
READ NEXT
COMMENTS (0)
Sign up now
Subscribe to thecodeblocks
Don't miss out on the latest news and tutorials
Subscribe now
Copyright by @ thecodeblocks