From Wikislax
Jump to: navigation, search


The extensions.conf file contains at the beginning a [general] and a [global] contexts, that you probably won't need to modify, and a set of additional contexts - that define how Asterisk handles calls, the dialplan. All of the instructions placed after a context definition are part of that context, until the next context.

The sip.conf file affords defining which users and which channels are associated with which contexts, and this affords ensuring who can do what, and specially who can access expensive communication ressources.


An extension is a line composed of :

exten => name,priority,application()     or
exten => name,priority(label),application()
  • name is generally actually a number, the extension
  • priority is a sequence number, ex- or implicitely numbered
  • label is an optional tag you can specify to address a specific line
  • application is the action performed at this line of the extension processing

An example of extension processing would be as follows. Priority n means the next sequence value. The call is answered then extension 1 is dialed and transferred if successful, otherwise return is with busy or unavail string and the call is transferred to the voicemail which gives a b (busy) or u (unavail) message then records :

exten => 1,1,Answer()
exten => 1,n,Dial(SIP/1,20,m)
exten => 1,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)
exten => 1,n(unavail),Voicemail(1@default,u)
exten => 1,n,Hangup()
exten => 1,n(busy),VoiceMail(1@default,b)
exten => 1,n,Hangup()

Special extensions

  • a is for when the asterisk key (*) is pressed while recording a voicemail message.
  • h is for when the call is hung up to execute some cleanup code.
  • i is for when the extension entered is not valid in the context.
  • o is for when the zero key is pressed while recording a voicemail message.
  • t is for when no entension is entered within the TIMEOUT duration.
  • s is for when a call enters a context without a specific destination extension.


Let's mention a few useful applications :

  • Answer() answers a ringing channel.
  • Background(basename) plays a sound file also listening for input at the same time. If the caller presses keys, the application interrupts and goes to the corresponding extension. basename is absolute or relative from the default sound directory /usr/local/var/lib/asterisk/sounds. Asterisk automatically adds a sub-directory for the language code.
  • ConfBridge(conference,[bridge_profile,[user_profile,[menu]]]) connects to conference optionnally using a bridge profile, user profile and DTMF menu.
  • Dial(channel/user&channel/user,timeout,option,url) rings the specified destinations simultaneously and bridges the inbound call with whichever destination answers the call first. If Dial() can't contact any of the destinations, Asterisk sets a variable called DIALSTATUS with the reason that it couldn't dial, and continues on with the next priority. timeout is in seconds. The m options plays musiconhold.
  • Goto(context,extension,priority) sends the call to another part of the dialplan.
  • GotoIf(expression?destination1:destination2) sends the call to another part of the dialplan. destination can be a priority, extension:priority, or context:extension:priority.
  • HangUp() hangs up.
  • MusicOnHold plays music on hold indefinitely.
  • Playback(basename) plays a sound file. Input from the caller is ignore. basename is absolute or relative from the default sound directory /usr/local/var/lib/asterisk/sounds. Asterisk automatically adds a sub-directory for the language code.
  • Record(file.ext) plays a beep and begins recording audio until you press the hash key (#). It then saves the audio to the file name specified. If you hangup before pressing the hash key the audio is not recorded.
  • VoiceMail(mailbox@context,option) sends the caller to the specified mailbox so that she can leave a message. The mailbox should be specified as mailbox@context. The option letters b or u can be added to give a busy or unavailable greeting.
  • VoiceMailMain() affords the caller to access her voicemail messages.
  • WaitExten(seconds) waits for the caller to enter DTMF digits and is frequently used directly after Background(). It is possible to specify as first argument a number of seconds to wait otherwise the default TIMEOUT value is used.


Variables can be defined in the [global] using VARIABLE=value, or in the extensions using Set(VARIABLE=value) or Set(GLOBAL(VARIABLE)=value. It is also possible to use Linux environment variables thru ${ENV(VARIABLE)}. The ${EXTEN:start:number} gives back number characters starting at position start of the extension just dialed. ${EXTEN:-4:4} would start four digits from the end and return four digits.

Pattern Matching

To avoid always giving exact extensions it is possible to specify patterns. When several patterns match Asterisk chooses the more specific.

Patterns always start with an underscore _ then can include any of the below :

  • X matches any single digit from 0 to 9.
  • Z matches any single digit from 1 to 9.
  • N matches any single digit from 2 to 9.
  • [15-7] matches any single digit from the range specified. In this case the pattern matches a single 1 5 6 or 7.
  • . (period) (wildcard) matches one or more characters no matter what they are.
  • ! (bang) (wildcard) matches zero or more characters no matter what they are.


Here is an example of a very simple extensions.conf file with the following behaviour :

  • [freephonie] includes only the [inside] context so can access only the inside.
  • [internal] includes both [inside] and [outside] so can access the inside and the outside.
  • If the caller presses a sip user extension in LDAP the call is transferred to the corresponding extension.
  • If the caller presses 7 the call is transferred to the default_bridge conference bridge.
  • If the caller presses 9 the call is transferred to the voicemail.
  • If the caller presses a number starting by 0 the call is transferred to the freephonie channel.
  • Not pressing any key will trigger a timeout message and the call will be hung up.

The users and extensions are loaded from the LDAP directory using switch => Realtime/@. Which users and extensions are loaded in which context depend on the values in the multivalued AstAccountContext field. One AstAccountContext value and the section name must match for the record to be loaded into the section. Having several values affords including the extensions in several contexts. In our example this affords having a different treatment for internal and freephonie users: the latter cannot rebound and call an external number.



exten => _0.,1,Dial(SIP/freephonie/${EXTEN})
exten => _0.,n,Hangup()

exten => 7,1,Answer()
exten => 7,n,ConfBridge(default_bridge)
exten => 7,n,Hangup()

exten => 9,1,Answer()
exten => 9,n,VoiceMailMain()
exten => 9,n,Hangup()

exten => i,1,Playback(pbx-invalid)
exten => i,n,Hangup()

exten => t,1,Playback(vm-goodbye)
exten => t,n,Hangup()

switch => Realtime/@
include => inside
include => outside

exten => s,1,NoOp()
exten => s,n,Answer()
exten => s,n,Background(enter-ext-of-person)
exten => s,n,WaitExten()
switch => Realtime/@
include => inside

Voicemail.conf Main Page Desktop software