A Simple Dialplan

OK, enough theory. Open up the file /etc/asterisk/extensions.conf, and let’s take a look at your first dialplan (which was created in Chapter 5, User Device Configuration). 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, User Device Configuration, 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:

[LocalSets] ; this is the context name
exten => 100,1,Dial(SIP/0000FFFF0001) ; Replace 0000FFFF0001 with your device name

exten => 101,1,Dial(SIP/0000FFFF0002) ; Replace 0000FFFF0002 with your device name

exten => 200,1,Answer()
   same => n,Playback(hello-world)
   same => n,Hangup()

Tip

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 into an Asterisk dialplan on a system that you’ve built from scratch. People get this funny grin on their faces as they realize that they have just created a telephone system. This pleasure can be yours as well, so please, don’t go any further until you have made this little bit of dialplan work. If you have any problems, get back to Chapter 5, User Device Configuration and work through the examples there.

If you don’t have this dialplan code built yet, you’ll need to add it and reload the dialplan with this CLI command:

*CLI> dialplan reload

or from the shell with:

$ sudo /usr/sbin/asterisk -rx "dialplan reload"

Calling extension 200 from either of your configured phones should reward you with the voice of Allison Smith saying “Hello World.”

If it doesn’t work, check the Asterisk console for error messages, and make sure your channels are assigned to the LocalSets context.

Important

We do not recommend that you move forward in this book until you have verified the following:

  1. Calls between extension 100 and 101 are working

  2. Calling extension 200 plays “Hello World”

Even though this example is very short and simple, it emphasizes the core concepts of contexts, extensions, priorities, and applications. You now have the fundamental knowledge on which all dialplans are built.