We should have two extensions already set for our sip accounts. In this lesson we will modify the 100 and 101 extension, to connect them to the the voicemail accounts in the voicemail.conf file.
To get started, open up the dialplan using the command:
sudo nano /etc/asterisk/extensions.conf
The VoiceMail() application is what we will need to send calls to voicemail when appropriate. We will add this application after the Dial() application. After Dial() the system will then send you to the Voicemail() application on the following line to connect to the entered voicemail. Within the parenthesis of the VoiceMail() application we will add the extension@context from the voicemail.conf file.
Modifying the dialplan
The first thing we will do is modify extension 100 from the extensions.conf file. To start we can set a time limit on how long the phone should ring for. To do this we will add the number of seconds to dial as an additional parameter in the Dial() application. Modify extension 100 to match the code below and let it ring for 5 seconds:
exten => 100,1,NoOp(Call for matthew)
same => n,Dial(SIP/matthew,5)
same => n,Hangup
Now that the phone will ring for 5 seconds we can add the VoiceMail() application. Within the parentheses we will define the voice mailbox number from the /etc/asterisk/voicemail.conf file and the context that the number resides in. Modify extension 100 to add the VoiceMail() application as seen below:
exten => 100,1,NoOp(Call for matthew)
same => n,Dial(SIP/matthew,5)
same => n,VoiceMail(100@default)
same => n,Hangup
At this point it would be good to reload the dialplan in the Asterisk console and try out the voicemail. Call extension 100 and test the voicemail. At this point in the the Asterisk server is not configured to send out emails, so a notification will not be emailed out.
Retrieving the voicemails
We will create a new extension that the users can use to retrieve their voicemails. A new application VoiceMailMain() can be used to access the voicemail system. Using @default within the parenthesis will allow each user to access their own voicemail. Modify the dialplan to add a new extension using the data below:
exten => 199,1,NoOp(Retrieve Voicemail)
same => n,VoiceMailMain(@default)
Save the extensions file and reload the dialplan in the Asterisk console. Now test to make sure you can access the voicemails. When a voicemail is recorded, it is stored in the /var/spool/asterisk/voicemail/ directory.