Asterisk Voicemail

Asterisk has a built-in voicemail system. This is similar to built-in systems used by companies with other PBX systems installed.  Asterisk Voicemail allows message leaving, retrieval forwarding and so on. As with the rest of Asterisk, the voicemail system is highly configurable (but perhaps not as configurable as developing your own system).

VOIP-INFO page on voicemail commands This application lets the caller leave a voicemail for another person.
VOIP-INFO page on Voicemail Main commands. This application allows the caller to access and manage their voicemail.
VOIP-INFO page on voicemail tips

The Voicemail application is slightly different for various Asterisk versions. We are using 11.12.0.

Voicemail Command
(for use in Dialplans)

VoiceMail(boxnumber[@context][&boxnumber2[@context]][&boxnumber3],[flags])

Example:

exten => s,1,VoiceMail(10@ck987,u); (Note: the "u" means play "unavailable" message.)

In my extensions.conf:

[ck987_easy_voicemail]
exten => s,1,Voicemail(10@voicemail_ck987);  play "unavailable" message, box 10, redial_ck987 voicemail context.
exten => s,n,Goto(ck987,s,1); go back to my main dialplan context

(You see that I created a new “context” for my voicemail (ck987_easy_voicemail). I use a “goto” command in my main context to get to it.)

To create your own voicemail box on the asterisk system you need to create a file called voicemail.conf inside your asterisk_conf directory.

This file should contain something like the following:

[voicemail_NETID]

;extension_number => voicemail_password,user_name,user_email_address,user_pager_email_address,user_option(s)

10 => 10,ck987,chris@myemail.com,,attach=yes|serveremail=ck987@nyu.edu|tz=eastern|saycid=yes|callback=fromvm|operator=no|envelope=yes

The first line is the voicemail “context”. The next line is a comment which shows the syntax that you should use for any remaining lines. For this class, you should use the “voicemail” context and set the “extension_number” the same as your extension. Since we are using our own contexts you can add in more voicemail extensions if you like.

In the Asterisk mail system, voicemail messages are saved to a specific location on the file system.

/var/spool/asterisk/voicemail/context/boxnumber/INBOX/

My voicemail messages are therefore located here: /var/spool/asterisk/voicemail/voicemail_ck987/10/INBOX/

Looking in this directory, you will see that the naming convention for the files is pretty simple:

msg####.format starting with number 0.

Asterisik also saves data of the call in a text file. Furthermore, it converts the audio to multiple formats so you can use it in other ways on the server.

msg0000.gsm msg0000.txt msg0000.wav msg0000.WAV

Voicemail to Email
One of the most powerful features of the built-in voicemail system is that it can easily be configured to send any voicemail messages to email. This is our first foray into something that breaks us out of standard telephony applications and lets us doing more than is typical with phone systems.

The contents of the emailed message are follows:

Format String (in configuration, not per user or per context unfortunately): ${VM_NAME}\n${VM_DUR}\n${VM_MSGNUM}\n${VM_MAILBOX}\n${VM_CALLERID}\n${VM_DATE}

This is all of the variables that are available in the built-in system. I configured it to put a line break in between each variable and to attach the audio file of the message itself.

This results in messages that have a body as follows:

ck987
0:15
1
300
"6466422920" <16466422920>
Saturday, February 5, 2011 at 03:29:07 PM

If we need to come up with a different format for specific uses, we can change this but since we all have to use the same format I don’t want to change it around too much or too many times.

What can you do with this?

Shawn has used this system in the past to automatically post audio to his blog.

This Perl script automatically downloads email from a specific mailbox and uses a protocol¬†called “XML-RPC” to post the messages to a blog:

Shawn’s Parse Mail Script

Voicemail Management
Asterisk has another command “VoiceMailMain()” which allows a caller into the management portion of the voicemail system.

VoiceMailMain(mailbox@context[|options])
Example: exten => a,1,VoiceMailMain(10@redial);

Notice the “a” extension listed above. If you are in the normal VoiceMail application and you press the asterisk “*”, it will kick you out to where you came from but with the extension “a”. I am using this to put the caller into the VoiceMailMain application.

Full Example:

[ck987_easy_voicemail]
exten => s,1,Voicemail(10@voicemail_ck987);
exten => s,n,Hangup();
;Voicemail will go to the "a" extension if * is hit during voicemail app.
exten => a,1,VoiceMailMain(10@voicemail_ck987);
exten => a,n,Hangup()

One of the options that is particularly useful in the VoiceMailMain application is the ability to record personal messages to playback for different purposes:

This is where the “flags” when going to the VoiceMail command come in handy. Check this page for a rundown:

Asterisk cmd VoiceMail – voip-info.org

Try it out!