The standard Asterisk sound set includes a file called
marryme.gsm, containing the announcement "Will you
marry me? Press 1 for yes or 2 for no."[24]To build a "marriage proposal" application, the following
dialplan will suffice:[25]
exten => 30,1,Answer() exten => 30,2,Background(marryme) exten => 30,3,Hangup() exten => 1,1,Playback(thank-you-cooperation) exten => 1,2,Hangup() exten => 2,1,Playback(sorry) exten => 2,2,Hangup()
If the caller dials extension 30,
Asterisk answers and plays the file marryme.gsm.
Through use of the Background() application, the user
is allowed to enter input at any time during playback. The input is
interpreted as an extension and the call is passed to that extension. If
the caller presses 1, he hears "Thank you for your cooperation," after
which Asterisk hangs up.
Playback() (see
the section called “Playback()”) only plays back sound files;
input is ignored.
Background() (see the section called “Background()”) plays sound files back while
listening for caller input, which is interpreted as an extension as
though it had been dialed as one.
To address the challenge of extensions beginning with the same digits, let's examine the following example:
exten => 30,1,Answer() exten => 30,2,Background(marryme) exten => 30,3,Hangup() exten => 1,1,Playback(thank-you-cooperation) exten => 1,2,Hangup() exten => 10,1,NoOp(Test mit 10) exten => 10,2,Hangup() exten => 100,1,NoOp(Test mit 100) exten => 100,2,Hangup() exten => 2,1,Playback(sorry) exten => 2,2,Hangup()
Background() waits a set time after each digit
in order to distinguish between 1, 10 and 100. Once this time
(TIMEOUT) has expired, input is deemed to be
complete.
|
|
|
|
TIMEOUT is defined in seconds and may be
set in the dialplan like so.
exten => 123,1,Set(TIMEOUT(digit)=3)
An invalid entry (any entry for which no extension in the dialplan
matches) can be handled by the i extension. A simple
example would look like this:
exten => 30,1,Answer() exten => 30,2,Background(marryme) exten => 30,3,Hangup() exten => 1,1,Playback(thank-you-cooperation) exten => 1,2,Hangup() exten => 2,1,Playback(sorry) exten => 2,2,Hangup() ; Any other input is caught by the i extension. exten => i,1,Background(sorry) exten => i,2,Hangup()
The easiest way to create pauses for input is to play back empty
sound files. A series of silent sound files of between 1 and 9 seconds
in length may be found in
/var/lib/asterisk/sounds/silence/. If we need to
allow five seconds following the prompt (a marriage proposal requires
careful consideration, after all), here's how we can accomplish
that:
exten => 30,1,Answer() exten => 30,2,Background(marryme) exten => 30,3,Background(silence/5) exten => 30,4,Hangup() exten => 1,1,Playback(thank-you-cooperation) exten => 1,2,Hangup() exten => 2,1,Playback(sorry) exten => 2,2,Hangup() exten => i,1,Background(marryme) exten => i,2,Hangup()