text stringlengths 0 152 |
|---|
use a telephone and the dialplan to create and manage your own |
system recordings (or import .wav files). |
To use Playback(), specify a filename as the argument. For example, Playback(file |
name) would play a sound file called filename.wav, assuming it was located in the |
default sounds directory. Note that you can include the full path to a file if you want, |
like this: |
Playback(/home/john/sounds/filename) |
The previous example would play filename.wav from the /home/john/sounds direc‐ |
tory. This can be problematic, however, due to potential file permissions problems. If |
you’re planning on having a lot of custom sounds on your system, you’ll likely want a |
dedicated directory for them, and you’ll need to test to ensure Asterisk can find and |
play the files. |
You can also use relative paths from the Asterisk sounds directory, as follows: |
Playback(custom/filename) |
This example would play filename.wav from the custom subdirectory of the default |
sounds directory (probably /var/lib/asterisk/sounds/en/custom/filename.wav). If the |
specified directory contains more than one file with that filename but with different |
file extensions, Asterisk automatically plays the best file.6 |
The Hangup() application does exactly as its name implies: it hangs up the active |
channel. You should use this application at the end of a context when you want to end |
the current call, to ensure that callers don’t continue on in the dialplan in a way you |
might not have anticipated. The Hangup() application does not require any |
6 Asterisk selects the best file based on translation cost—that is, it selects the file that is the least CPU-intensive |
to convert to its native audio format. When you start Asterisk, it calculates the translation costs between the |
different audio formats (they often vary from system to system). You can see these translation costs by typing |
core show translation at the Asterisk CLI. The numbers shown represent how many microseconds it takes |
Asterisk to transcode one second of audio. |
86 |
| |
Chapter 6: Dialplan Basics |
arguments, but you can pass an ISDN cause code if you want, such as Hangup(16), |
and it will be translated into a comparable SIP message and sent to the far end. |
As we work through the book, we will be introducing you to many more Asterisk |
applications, but that’s enough theory for now; let’s write some dialplan! |
A Basic Dialplan Prototype |
To reiterate, then, the form of all dialplans is built from those four concepts: Context, |
Extension, Priority, and Application (Figure 6-3). |
Figure 6-3. Dialplan prototype |
A Simple Dialplan |
OK, enough theory. Open up the file /etc/asterisk/extensions.conf in your favorite edi‐ |
tor, and let’s take a look at your first dialplan (which was created in Chapter 5). We’re |
going to add to that. |
Hello World |
As is typical in many technology books (especially computer programming books), |
our first example is called “Hello World.” |
In the first priority of our extension, we answer the call. In the second, we play a |
sound file named hello-world, and in the third we hang up the call. The code we are |
interested in for this example looks like this: |
exten => 200,1,Answer() |
same => n,Playback(hello-world) |
same => n,Hangup() |
If you followed along in Chapter 5, you’ll already have a channel or two configured, |
as well as the sample dialplan that contains this code. If not, what you need is an |
extensions.conf file in your /etc/asterisk directory that contains the following code: |
[general] |
[globals] |
[sets] |
A Simple Dialplan |
| |
87 |
exten => 100,1,Dial(PJSIP/0000f30A0A01) ; Replace 0000f30A0A01 with your device name |
exten => 101,1,Dial(PJSIP/SOFTPHONE_A) |
exten => 102,1,Dial(PJSIP/0000f30B0B02) |
exten => 103,1,Dial(PJSIP/SOFTPHONE_B) |
exten => 200,1,Answer() |
same => n,Playback(hello-world) |
same => n,Hangup() |
If you don’t have any channels configured, now is the time to do so. |
There is real satisfaction that comes from passing your first call |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.