Now we're ready to create our first dialplan. We'll start with a very simple example. We are going to instruct Asterisk to answer a call, play a sound file, and hang up. We'll use this simple example to point out the most important dialplan fundamentals.
For the examples in this chapter to work correctly, we're assuming
that at least one channel (either Zap or SIP or IAX2) has been created and
configured (as described in the previous chapter), and that all calls
coming into that channel enter the dialplan at the [incoming] context. If you have been creative
with any previous examples, you may need to make adjustments to fit your
particular channel names.
Because of the technology we are using in our channels, we need to
cover one more thing before we get started with our dialplan. We need to
explain extension "s". When calls
enter a context without a specific destination extension (for example, a
ringing FXO line), they are passed to the s extension. (The s stands for "start", as this is where a call
will start if no extension information was passed with the call.)
Since this is exactly what we need for our dialplan, let's begin
to fill in the pieces. We will be performing three actions on the call
(answer it, play a sound file, and hang it up), so our extension called
s will need three priorities. We'll
place the three priorities below [incoming], because we have decided that all
incoming calls should start in this context[75].
[incoming]
exten => s,1,application()
exten => s,n,application()
exten => s,n,application()
Now all we need to do is fill in the applications, and we've created our first dialplan.
[75] There is nothing special about any context name. We could have named this context [stuff_that_comes_in], and as long as that was the context assigned in the channel definition in (sip.conf, iax.conf, zaptel.conf, et al), the channel would enter the dialplan in that context. Having said that, it is strongly recommended that you give your contexts names that help you to understand their purpose. Some good context names might include: [incoming], [local_calls]. [long_distance], [sip_telephones], [user_services], [experimental], [remote_locations] and so forth. Always remember that a context determines how a channel enters the dialplan, so name accordingly.