Here is a basic example that displays information from a call: Asterisk.pde. A List of Call Objects. One of the first things you will likely want to do when receiving phone calls in Processing is spawn an object for every new caller. Most of the time when you want to have multiple objects, a simple array or even ArrayList will do. Example: Asterisk.CLI core set verbose 10 Console verbose was 2 and is now 10. Asterisk.CLI core set debug 10 Core debug was OFF and is now 10. Asterisk.CLI sip set debug on SIP Debugging enabled Asterisk.CLI fax set debug on FAX Debug Enabled dm.CLI Note: Depending on version of your Asterisk system, the sip set debug command may be. If you call.21 and enter the number to which you want to redirect calls, then this number will simply be stored in the Asterisk database (AstDB), if you dial.22, this number will be deleted from the database. In the same file, I had a dialplan for local number 207: exten = 207,1,Dial(SIP/207,60) exten = 207,n,Hangup.
In the previous article, you learned how to configure the PJSIP channel driver to connect a simple softphone client with your Asterisk installation. However, your phones still can’t call each other, and you haven’t given them numerical 'extensions' yet. Connecting channels together in Asterisk is the work of the dialplan. In this article, you’ll learn the basics of the dialplan: What it is, how it’s configured, and how to use it to connect phones together.
As a reminder, this is the setup we're configuring:
Dialplan fundamentals
Using Asterisk In Search
The Asterisk dialplan is responsible for routing calls, so it is often referred to as the heart of an Asterisk system. The dialplan is written in a special scripting language, and it is extremely powerful. You might think of phone systems as simply accepting and connecting calls, but Asterisk is capable of much more. With the dialplan, you can design rich, voice-driven applications. For example, you could create the following call flow for a small business:
- An external call comes into Asterisk from a standard telephone number.
- An Interactive Voice Response (IVR) system might ask the user to enter basic information, such as their account number.
- Asterisk accepts the user’s input. The IVR looks up their account and presents them with information (e.g., information about outstanding invoices).
- Optionally, the user can be routed to a queue of available customer service representatives. When the employee receives the customer’s call, the system provides them with all of the customer’s details and saves the caller some time.
While there are other programming interfaces for interacting with Asterisk, the dialplan is the most basic, and understanding it is fundamental to understanding how Asterisk handles calls. According to Asterisk the Definitive Guide, there are four fundamental components to the Asterisk dialplan:
- Contexts: A context is a logical section in the dialplan. Contexts contain one or more extensions.
- Extensions: An extension is simply a grouping of steps used to handle a particular call. Unlike many traditional phone systems, extensions don’t have to be numerical and they aren’t tied to a single device. You could have an extension called 'mainIVR' if you wanted.
- Priorities: A priority is a step in an extension. Priorities handle ordering, and they can also have labels attached to them so that a call can jump between priorities as needed.
- Applications: Applications are a lot like functions in traditional programming languages. They tell Asterisk what to do with a call. For example, you might have an internal extension of *86. When *86 is dialed, you might have Asterisk play a message of the day using the Playback application.
If you’re new to Asterisk, this breakdown probably sounds complicated. While Asterisk dialplans certainly can be complex, a simple phone system only requires a simple dialplan. Let’s take a look at the dialplan needed to support your intra-office calling scenario. The dialplan is configured in /etc/asterisk/extensions.conf
:
The snippet above is all that is necessary to allow your two phones to call each other. Let’s step through each part of this dialplan:
office-phones
is the context. This context contains two extensions.1001
and1002
are the extensions. Notice how this setup decouples the numbers from the phones themselves. While these numbers are currently hardcoded to dial Alice’s and Bob’s phones, they could just as easily be used for more complex routing (e.g., automatically roll over to an overnight line during certain hours).- The
1
after the extension is the priority. Remember, a priority is just a step in extension handling. The first priority is always1
. In this example, each extension only has a single priority. Dial
is the application. The Dial application is used to ring a remote device. Dialing occurs via SIP or other signaling protocols (if you need a refresher on VoIP protocols, head over to our [first article]). [Note: Don’t forget to add the link.]
To recap: When a call comes into the office-phones
context, Asterisk tries matching that call to an extension. When extension 1001 is dialed, the first step (priority) tells Asterisk to dial the PJSIP endpoint for Alice’s phone. When extension 1002 is dialed, the same thing happens for Bob’s phone.
This is great so far, but how exactly does a call make its way into the dialplan? The answer lies in the PJSIP endpoint configuration from the previous article:
More Linux resources
Notice that the context for each phone is set to office-phones
. This setting tells Asterisk that any calls coming from the alice-softphone
or bob-softphone
endpoints should enter the dialplan in the office-phones
context. When Bob dials a number (say, 9000) from his softphone, Asterisk looks in the office-phones
context for the matching extension 9000. In the sample dialplan above, this call will fail because there is no matching extension.
You don’t have to configure all of your phones to enter the dialplan in the same context. In fact, you’ll likely find good reasons to specifically put phones in other contexts. Consider a business that wants to only allow certain people to make international calls, while everyone else is restricted to local calls. You might have two extensions: One to allow unrestricted calling, and one that only allows calls to numbers that start with the local area code. Those with international calling privileges would be placed in the international
context, while everyone else would be placed in the local-only
context.
Call From Asterisk
That was a lot of theory. Let’s get back to the command line and test out the changes that we made to the dialplan. First, you must non-disruptively reload
the dialplan to enact the changes you made in the config file:
Next, you can inspect the dialplan directly from the Asterisk CLI to ensure that your changes are present:
Notice that Asterisk includes the exact file name and line number where an extension and its priority can be found. This information is useful when troubleshooting behavior in your phone system.
With the dialplan reloaded and your changes clearly in place, you should be able to place a test call from Linphone (or whatever SIP endpoint you’re using). First, launch the Asterisk CLI with extra verbosity using asterisk -rvvv
:
Asterisk Call File Example Pdf
Next, place a call from Alice’s phone to extension 1002. Assuming that you registered an additional softphone (or physical phone) for Bob, the extension should show as ringing
: