In our previous three installments we set up Asterisk as a PBX for four PSTN lines. We set up incoming and outgoing calling and restricted outgoing calls to authorized users only. Our fine example users Alrac, Stan, and Ollie still need voicemail. Our mission today is to give it to them.
Setting up voicemail
Voicemail is configured in /etc/asterisk/voicemail.conf. The values you want are mailbox_number => password, username, plus optional email, phone, or pager, because Asterisk can forward voicemails or notifications to almost any device. Usually the mailbox number is the same as the extension number, but it can be anything you wanta different number or even a name:
250 => 1234,Alrac Smith,email@example.com
251 => 3456,Stan Laurel,firstname.lastname@example.org
252 => 4567,Ollie Hardy,email@example.com
While you're editing voicemail.conf, set serveremail=asterisk to whatever is appropriate for your server. This is what will appear in the "send" line when Asterisk emails users voicemail notifications.
Another popular option is attach=yes, which will attach a soundfile of the voicemail message to email. This can also be configured on a per-user basis, like this:
250 => 1234,Alrac Smith,firstname.lastname@example.org|attach=yes
Next, you need to change extensions.conf by adding the new voicemail
boxes to each user. This builds on the example from our
previous article. We'll use our old friend Alrac to illustrate:
exten => 250,1,Dial(SIP/alrac,10,r)
exten => 250,2,VoiceMail(u250@local-vm-users)
exten => 250,dial+101,VoiceMail(b250@local-vm-users)
This introduces a number of new options. "10" means the line will ring for ten seconds before going to the next priority. "r" tells Asterisk to play a ringing sound.
"u250@local-vm-users" sends the caller to voice mailbox 250 if there is no answer and plays the "unavailable" message, using the [local-vm-users] voicemail context.
"b250@local-vm-users" sends the caller to voice mailbox 250 on a busy signal and plays the "busy" message. Asterisk comes with prefab "unavailable" and "busy" messages, or users can record their own.
There is a quirk of numbering in the Dial application; it sends callers to priority n+ 101 on a busy signal. Specifying "Dial" saves you the hassle of trying to figure out the correct value, which as your configuration files expand becomes a real pain.
Any messages left by callers are stored in /var/spool/asterisk/voicemail/[context]/[mailbox]/INBOX/.
You need to set up an extension in extensions.conf so users can fetch their messages. This example sets up extension 500 for fetching voicemail, using the VoiceMailMain application. Users will have to dial 500, then enter their mailbox numbers and passwords:
exten => 500,1,VoiceMailMain(local-vm-users)
Then just follow the prompts.
Recording voicemail greetings
Most folks want their own customized, personal voicemail greeting. No problem, because the VoiceMailMain application handles this as well. Again, just dial in and follow the prompts.
Recording custom prompts
Even though Asterisk comes with hundreds of sound files for every possible occasion (/var/lib/asterisk/sounds/) you'll still want to record your own on occasion. There is a whole subculture of avid telephony sound aficionados who use all manner of sophisticated software and hardware, and know things like every digital music file format in existence, kilohertzes and megahertzes, compression, sampling rates, normalization, and all kinds of stuff. While it's fun and useful to know as much as your average professional sound engineer, it's not necessary when all you want to do is record Asterisk prompts.
All you need is a telephone with decent sound quality, like a good hardphone, a legacy analog phone, a good microphone and sound card, or a good-quality USB headset, and the Asterisk Record application. First configure an extension in under the [local-users] context in extensions.conf for recording new sound files:
;record new voice files
Exten => 501,1,Wait(2)
Exten => 501,n,Record(/tmp/asterisk-recording:gsm)
Exten => 501,n,Wait(2)
Exten => 501,n,Playback(/tmp/asterisk-recording)
Exten => 501,n,wait(2)
Exten => 501,n,Hangup
Pick up a phone and dial 501. After two seconds you'll hear a beep. Record your message, then poke the pound key when you're finished. Asterisk will then play back the new file. You may re-record it as many times as you like, until it has reached a state of suitable shiny perfection, though you'll have to re-dial the extension to re-record. This is very simple and works fine for a lot of folks; next week we'll add refinements and more user options.
Then you need to copy the file into its permanent home. This can be /var/lib/asterisk/sounds/, or a directory of your own choosing like /var/lib/asterisk/sounds/koolkustomsounds/, or wherever you like:
# cp /tmp/asterisk-recording:gsm /var/lib/asterisk/sounds/maingreeting.gsm
In our next couple of installments we'll learn the quick way to play Asterisk sound files, more ways to update custom prompts, and how to create a nice automated attendant to answer and route incoming calls.
ResourcesVoIPowering Your Office with Asterisk: SOHO VoIP; terminology explained
VoIPowering Your Office with Asterisk: SOHO VoIP part 2; connecting legacy PSTN lines to Asterisk, inbound calling
VoIPowering Your Office with Asterisk: SOHO VoIP, Part 3; setting up outbound calls safely
NANPA: North American Numbering Plan Administration