Creating Dialplans

The dialplan is the central piece of any Asterisk system. Simply put, the dialplan is the "road map" for how Asterisk will work. The dialplan specifies how Asterisk should should handle calls. The dialplan consists of a list of instructions or steps that Asterisk should follow. To sucessfully set up your own Asterisk system, it is absolutely vital that you understand dialplans.

This chapter will explain how dialplans work in a step-by-step manner, and give you the skills to create your own dialplan. The examples in this chapter have been designed to build upon one another, so feel free to go back and reread a section if something doesn't make sense. While this chapter is by no means an exhaustive survey of all the possible things that dialplans can do, our aim is to cover all the fundamentals.

Introduction to Creating Dialplans

The majority of the dialplan is specified in the file extension.conf. This file is made up of four main parts: contexts, extensions, priorities, and applications. In this section, we'll cover each of these parts, and explain how they work together to create a dialplan.

If you installed the Asterisk sample files, you probably have an existing extensions.conf file. Instead of modifying the existing file, we recommend you start from scratch in creating your extensions.conf file, so that you can learn about how each part of the file plays a role in the dialplan. The sample extensions.conf is an excellent resource for learning about many of the variables and other subleties of dialplans. You may want to rename your existing extensions.conf file, and refer to it later.

Contexts

Contexts play an organizational role within the dialplan. Contexts also define scope. You can think of contexts as a way to keep different parts of the dialplan separate. As a simple example, contexts can be used to make Asterisk answer one phone line differently than another. All calls that Asterisk handles will begin in a certain context. The instructions defined in this context will determine what things may happen to the call.

NoteContexts and IVR
 

Contexts are often used to create "voice menus" that give callers a list of extensions to choose from by pressing keys on a touch-tone phone. This functionality is commonly called IVR, which stands for Interactive Voice Response. We'll cover IVR in more depth later in the chapter.

Contexts are denoted by their name inside of square brackets. For example, if we were to create a context called "incoming" for incoming calls, we would define it like this:


				[incoming]
				

All of the instructions placed after a context definition are considered part of that context, until another context is defined.

At the very beginning of the extensions.conf file, there is a special context called [globals]. The globals context is where certain settings can be defined that can be used throughout your dialplan. For right now, we won't use the [globals] context, but you should be aware of why it exists.

Extensions

Within each context, we will define one or more extensions. Extensions determine how the call flows. Although extensions can be used to specify phone extensions in the traditional sense (i.e. Please call John at extension 153), they can be used for more than that in Asterisk. In our extensions.conf file, an extensions is declared by the word "exten", followed by an arrow formed by the equal sign and the greater-than sign like this:


				exten =>
				

This is followed by the number (or name) of the extension, a comma, the priority, another comma, and finally the application we'd like to call on the channel. We'll explain priorities and applications next, but first let's finish covering the syntax. The syntax looks like this:


				[context-name]
				exten => extension,priority,application
				

Priorities

Priorities are numbered steps in the execution of each extension. Each priority calls one specific application. Typically these priority numbers simply start at 1 and increment consecutively for each line in the context. Priority numbers aren't always consecutive, but we'll worry about that later.

Applications

Applications perform certain actions on a voice channel, such as playing sounds, accepting touch-tone input, or hanging up the call. Options called arguments can be passed to applications to effect how they perform their actions. To see a listing of the possible applications that are built into Asterisk, see Appendix C. As we build our first dialplan below, you'll learn to use applications to your advantage.