Extensions.conf
From Wikislax
Contexts
The extensions.conf file contains at the beginning a [general] and a [global] section, that you probably won't need to modify, and a set of additional sections - here named 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.
Extensions
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.
Applications
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.
- 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.
- MeetMe(conference,options,password) connects to conference using options and password.
- 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
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.
Example
Here is an example of extensions.conf file with the below behaviour :
- External can only access the [incoming] context so can access only the inside.
- Internal can access both [incoming] and [outgoing] so can access the inside and the outside.
- The s extension rings simultaneously extensions 1 and 2 transferring to the voicemail 1 in case of no answer and finishes there, unless the caller presses * during the voicemail session which makes processing proceed to the a extension.
- If the caller presses 1 or 2 the call is transferred to the corresponding extension.
- If the caller presses 7 the call is transferred to the conference number 7.
- If the caller presses 8 music on hold is played indefinitely.
- If the caller presses 9 she will access the messages in her voicemail.
- If the caller presses a number starting by 0 she will be transferred to the outgoing channel.
- Any other key press will trigger the invalid message and processing will restart at the a extension.
- Not pressing any key will trigger a timeout message and the call will be hang up.
[globals]
[general]
autofallthrough=yes
[incoming]
exten => s,1,Answer()
exten => s,n,Dial(SIP/1&SIP/2,20,m)
exten => s,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)
exten => s,n(unavail),Voicemail(1@default,u)
exten => s,n,Hangup()
exten => s,n(busy),VoiceMail(1@default,b)
exten => s,n,Hangup()
exten => a,1,Answer()
exten => a,n,Background(enter-ext-of-person)
exten => a,n,WaitExten()
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()
exten => 2,1,Answer()
exten => 2,n,Dial(SIP/2,20,m)
exten => 2,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)
exten => 2,n(unavail),Voicemail(2@default,u)
exten => 2,n,Hangup()
exten => 2,n(busy),VoiceMail(2@default,b)
exten => 2,n,Hangup()
exten => 7,1,Answer()
exten => 7,n,MeetMe(7,M,77)
exten => 7,n,Hangup()
exten => 8,1,Answer()
exten => 8,n,Playback(tt-allbusy)
exten => 8,n,MusicOnHold()
exten => 9,1,Answer()
exten => 9,n,VoiceMailMain()
exten => 9,n,Hangup()
exten => i,1,Playback(pbx-invalid)
exten => i,n,Goto(internal,a,1)
exten => t,1,Playback(vm-goodbye)
exten => t,n,Hangup()
[outgoing]
exten => _0.,1,NoOp()
exten => _0.,n,Dial(SIP/free/${EXTEN},60)
exten => _0.,n,Playtones(congestion)
exten => _0.,n,Hangup()
[internal]
include => incoming
include => outgoing
[external]
include => incoming
| Voicemail.conf | Main Page | Desktop software |