Because all the programming logic must occur via extensions, we need some additional system-defined extensions.
The h is the standard "hang-up" extension. The
h extension, if it is configured, is called when a caller
hangs up the phone. Note that as soon as this happens, the content of
${EXTEN} changes to h.
Say we want the global variable CONNECTIONS to
reflect the number of currently active conversations at any given
time. This means we need the value of CONNECTIONS to
increase by one every time a connection is initiated and decrease by
one every time someone hangs up. The following dialplan illustrates
the basic idea:
[global]
CONNECTIONS=0
[from-internal]
exten => _X.,1,Set(CONNECTIONS=$[${CONNECTIONS} + 1]|g)
exten => _X.,2,Dial(SIP/${EXTEN})
exten => h,1,Set(CONNECTIONS=$[${CONNECTIONS} - 1]|g)
To make a context gracefully handle every conceivable
circumstance, we use the special extension i ("i" stands
for invalid) which handles all dialed numbers which are not explicitly
handled handled within the context. Again, as with the h
extension, once the i extension is invoked the
${EXTEN} will no longer contain the dialed number. To get
the dialed number while in the i extension, use
${INVALID_EXTEN}.
In our example business, Widgets, Inc., employees in department B can only dial extensions 100 to 199. Callers dialing any other numbers hear the message, "I'm sorry. That is not a valid extension. Please try again."
[department-b]
exten => _1XX,1,Dial(${EXTEN})
exten => i,1,NoOp(An invalid number ${INVALID_EXTEN} was dialed.)
exten => i,2,Answer()
exten => i,3,Playback(invalid)
exten => i,4,Hangup()
If operator=yes is set in
voicemail.conf, the call will be directed to the o
extension (o is for operator, kids!) if the caller presses
"0".
Pressing * (asterisk) will direct the call to the
a extension (abort).
The t and T extensions are for handling
timeouts in the context.
If there is no input in an IVR menu within a certain time, the
t extension is called.
Example:
[mainmenu] exten => 10,1,Answer() exten => 10,n,Background(marryme) ; "Marry me? Press 1 for y es, 2 for no." exten => 1,1,Playback(thank-you-cooperation) ; 1 => "Thank you." exten => 1,n,Hangup() exten => 2,1,Playback(hangup-try-again) ; 2 => "Hang up and try ag ain." exten => 2,n,Hangup() exten => t,1,Hangup() ; no input => hang up
The T extension is called after the absolute
timeout has been exceeded. You can set this timeout value with
Set(TIMEOUT(absolute)=<seconds>).
|
|
|
Be careful not to have any spaces before and after the "=" character. |
The timer starts whenever the timeout value is set (in
other words, it does not automatically start with the connection, it
must be started explicitly with the Set() command).
Set(TIMEOUT(absolute)=0) deactivates the absolute
timeout.
Example:
exten => 20,1,Answer() exten => 20,2,Set(TIMEOUT(absolute)=120) exten => 20,3,Playback(hello-world) exten => 20,4,Wait(1) exten => 20,5,Goto(3) exten => T,1,Wait(1) exten => T,2,Playback(thank-you-for-calling) exten => T,3,Wait(1) exten => T,4,Hangup()
The first entry in any extension is always the name or number
dialed by the caller. When a call comes in from the PSTN, however,
Asterisk doesn't know what was dialed or whom the caller is trying to
reach. For any scenario in which we cannot determine the number dialed,
we use the s extension.
|
|
|
If you are using an ATA device (analog telephone
adapter) you don't need the |
Example:
exten => s,1,Answer() exten => s,2,Wait(1) exten => s,3,Play(tt-monkeys) exten => s,4,Wait(1) exten => s,5,Hangup()