Creating a dialplan for the users

Rather than using the existing extensions.conf file, a new file will be created in this lesson. Similar to moving the original sip.conf file in the previous section the extensions.conf will also be moved so that it may be reviewed at a later time. To move the extensions.conf file use the following command:
sudo mv /etc/asterisk/extensions.conf /etc/asterisk/extensions.conf.sample

Now to create a new file to work with, the touch command can be used to create an empty text file. To do that use the command:
sudo touch /etc/asterisk/extensions.conf

As mentioned in the previous lesson, there is usually a section for the [general] and [globals] contexts at the beginning of the extensions.conf file. They will be created in this lesson but nothing will be defined in either section. To edit the extensions.conf file use the command:
sudo nano /etc/asterisk/extensions.conf

Add the two contexts to the file:
[general] [globals]

In the sip.conf file, a context named [phones] was assigned to the accounts. This context can be added after the [globals] context. This will define a section that will be used to program execution of each call associated with the sip peers. Add the new context on a new line following the [globals] context:
[phones]

Now it is time to add the first extension. They are usually three or four digit extensions. In this lesson, three digit extensions will be used. For the first sip peer created, [matthew], we can assign extension 100. To do this add the following information in the [phones] context:
exten => 100,1,NoOp(Call for Matthew)
exten => 100,2,Dial(SIP/matthew)
exten => 100,3,Hangup

There are several things to look at with the first line exten => 100,1,NoOp(Call for Matthew). The first line of an extension use keyword exten followed by setting the extension number. In this case the extension number is 100. After the extension number the next item is order number. This sets the order the operations are executed. NoOp() is an application that is often used at the start of an application. The text within the parenthesis is display in the Asterisk Console, indicating the operation.

The second line exten => 100,2,Dial(SIP/matthew) defines which SIP user is called  when extension 100 is dialed. The application Dial() will look to the sip.conf in this case and find the user/peer named [matthew].

The third line exten => 100,3,Hangup is used to close the call after the Dial() application is terminated.

Another extension can be created for the second SIP account [eva]. We can use extension 101. This time the syntax will be changed a little to show an alternative way of defining the order of execution. Add the following code to the extensions.conf file:
exten => 101,1,NoOp(Call for Eva)
same => n,Dial(SIP/eva)
same => n,Hangup

Rather than having to define the extension number on each line, same => n is used starting on the second line to continue to flow of operation. In this case the operations are performed in sequential order.

Now that the changes have been made to the extensions.conf file, open the asterisk console using the command:
sudo asterisk -rvvv

The dialplan will need to be reloaded to have the new extensions applied. To do this use the command:
dialplan reload

Now test the new extensions by calling from one phone to another extension.