Skip to main content

Build a simple call - Dialplan

The dialplan is truly the heart of any Asterisk system, as it defines how Asterisk handles inbound and outbound calls. In a nutshell, it consists of a list of instructions or steps that Asterisk will follow. Unlike traditional phone systems, Asterisk’s dialplan is fully customizable. To successfully set up your own Asterisk system, you will need to understand the dialplan.
The dialplan is specified in the file called extensions.conf (Location: /etc/asterisk/extensions.conf).
A dialplan has four main concepts:
  • contexts
  • extensions
  • priorities
  • applications
Arrow Contexts
Dialplans are divided into sections called contexts. The name of the context is placed inside square brackets ([ ]).
The context for internal calls looks like this:
Arrow Extensions
An extension is simply a named set of actions. Asterisk will perform each action in sequence.
The syntax for an extension is the word exten, followed by an arrow formed by the equals sign and the greater-than sign, like this:
exten => name,priority,application()
A complete extension is composed of three components:
• The name (or number) of the extension
• The priority (each extension can include multiple steps; the step number is called the “priority”)
• The application (or command) that performs some action on the call.
Let’s take a closer look. Each line begins with the command exten. This is a directive inside Asterisk. You do not change this for each extension.
Here’s a simple example of what a real extension might look like:
  • exten => 123,1,Answer()
In this example, the extension name is 123, the priority is 1, and the application is Answer().
Now, let’s move ahead and explain priorities and applications.
Each extension can have multiple steps, called priorities. Each priority is numbered  sequentially, starting with 1, and executes one specific application. As an example, the following extension would answer the phone (in priority number 1), and then hang it up (in priority number 2):
  • exten => 123,1,Answer()
  • exten => 123,2,Hangup()
The key point to remember here is that for a particular extension, Asterisk follows the priorities in order.
Beginning with version 1.2, Asterisk addressed this problem. It introduced the use of the n priority, which stands for “next.” Each time Asterisk encounters a priority named n, it takes the number of the previous priority and adds 1. This makes it easier to make changes to your dialplan, as you don’t have to keep renumbering all your steps. For example, your dialplan might look something like this:
  • exten => 123,1,Answer()
  • exten => 123,n,do something
  • exten => 123,n,do something else
  • exten => 123,n,do one last thing
  • exten => 123,n,Hangup()
Internally, Asterisk will calculate the next priority number every time it encounters an n. You should note, however, that you must always specify priority number 1. If you accidentally put an n instead of 1 for the first priority, you’ll find that the extension will not be available.
Applications are the workhorses of the dialplan. Each application performs a specific action on the current channel, such as playing a sound, accepting touch-tone input, dialing a channel, hanging up the call, and so forth. In the previous example, you were introduced to two simple applications: Answer() and Hangup().
The Answer() application is used to answer a channel that is ringing. Answer() takes no arguments.
The Hangup() application hangs up the active channel. The Hangup() application takes no arguments.
The Playback() application is used for playing a previously recorded sound file over a channel. Playback() takes an argument, the name of the file to play. (Playback(/var/lib/asterisk/sounds/hello-world.gsm)
Basic Dialplan
Add the following lines a the end of the extensions.conf file (Location: /etc/asterisk/extensions.conf).
exten => 100,1,Answer()
exten => 100,n,Playback(/var/lib/asterisk/sounds/hello-world)
exten => 100,n,Hangup()
Dial number 100 and asterisk will play the “hello-world” file.
In the first priority of extension, we’ll answer the call. In the second, we’ll play a sound file named hello-world.gsm, and in the third we’ll hang up the call.
If you have a channel or two configured, go ahead and try it out (In fact, if you don’t have any channels configured, now is the time to do so. There is a real satisfaction that  comes from passing your first call into an Asterisk system that you built from scratch. People get this funny grin on their face 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 littledialplan work).
Simply create a file called extensions.conf, (probably in /etc/asterisk) and insert the four lines of dialplan code above . If it doesn’t work, check the Asterisk console for error messages, and make sure your channels are assigned to the [incoming] context.
Even though this example is very short and simple, it emphasizes the core concepts of  contexts, extensions, priorities, and applications. If you can get this to work, you have the fundamental knowledge on which all dialplans are built.
Let’s build upon that example. After all, a phone system that simply plays a sound file and then hangs up the channel isn’t that useful!


Popular posts from this blog

Asterisk – CLI commands

Agent commands agent logoff  - Sets an agent offline agent show  - Show status of agents agent show online  - Show all online agents AGI commands agi dump html  - Dumps a list of AGI commands in HTML format agi exec  - Add AGI command to a channel in Async AGI agi set debug [on|off]  - Enable/Disable AGI debugging agi show commands [topic]  - List AGI commands or specific help dnsmgr refresh  - Performs an immediate refresh dnsmgr reload  - Reloads the DNS manager configuration dnsmgr status  - Display the DNS manager status Calendar commands calendar dump sched  - Dump calendar sched context calendar show calendar  - Display information about a calendar calendar show calendars  - Show registered calendars Channel commands channel originate  - Originate a call channel redirect  - Redirect a call channel request hangup  - Request a hangup on a given channel Cli commands cli check permissions  - Try a permissions config for a user cli reload permi

Step by step: Configure call recording - Asterisk tutorials

This article will cover enabling asterisk to record calls. You may want this to interview people over the phone, podcast, or some other purpose. In features.conf, under: [featuremap] uncomment the line that looks like this: automixmon => *3 ; One Touch Record a.k.a. Touch MixMonitor — Make sure to set the X and/or x option in the Dial() or    Queue() app call! Then, enable the X option for Dial() in your dialplan in extensions.conf: PLEASE NOTE:  change you need to make – add the X  your dial rule make look different with me. exten => s,n,Dial(SIP/100,60) make it this instead: exten => s,n,Dial(SIP/100,60,X) The X is what tells Asterisk to allow callers to dial *3 during a call to enable or disable recording. From the asterisk console (run asterisk -r), you should see a line like this appear when the user starts a recording: – User hit ‘*3′ to record call. filename: auto-xxxxx-EXTENSION-DIALEDNUMBER When the recording ends, un

Making video calls – Asterisk tutorial

sip.conf To be able to send video during a call, codec h263 and video support must be enabled. This is done by adding three lines in the sip.conf file (Location: /etc/asterisk/sip.conf). Add the following lines in the [general] tab of the file. videosupport = yes ; Enable video allow = h263 ; H.263 is our video codec allow = h263p ; H.263p is the enhanced video codec Reload Reload the sip.conf file by running the following command in the CLI console:  reload Config in Softphone  Click “Softphone”  Click “Preferences”    Click “Video Codecs”  Verify that h263 and h263+ are selected Click “OK”  Click the video (Webcam) icon to display the video  Dial the other sip phone (number 1002)  Click “Show Video” on the two sip phones.