Chapter 8. Voicemail

Just leave a message, maybe I’ll call.

Joe Walsh

Before email and instant messaging became ubiquitous, voicemail was a popular method of electronic messaging. Even though most people prefer text-based messaging systems, voicemail remains an essential component of any PBX.

Comedian Mail

One of the most popular (or, arguably, unpopular) features of any modern telephone system is voicemail. Asterisk has a reasonably flexible voicemail system named Comedian Mail.[83] Some of the features of Asterisk’s voicemail system include:

  • Unlimited password-protected voicemail boxes, each containing mailbox folders for organizing voicemail

  • Different greetings for busy and unavailable states

  • Default and custom greetings

  • The ability to associate phones with more than one mailbox and mailboxes with more than one phone

  • Email notification of voicemail, with the voicemail optionally attached as a sound file[84]

  • Voicemail forwarding and broadcasts

  • Message-waiting indicator (flashing light or stuttered dialtone) on many types of phones

  • Company directory of employees, based on voicemail boxes

And that’s just the tip of the iceberg!

The default version of the /etc/asterisk/voicemail.conf file requires a few tweaks in order to provide a configuration that will be suitable to most situations.

We’ll begin by going through the various options you can define in voicemail.conf, and then we’ll provide a sample configuration file with the settings we recommend for most deployments.

The voicemail.conf file contains several sections where parameters can be defined. The following sections detail all the options that are available.

The [general] Section

The first section, [general], allows you to define global settings for your voicemail system. The available options are listed in Table 8-1.

Table 8-1. [general] section options for voicemail.conf

OptionValue/ExampleNotes
format

wav49|gsm|wav

For each format listed, Asterisk will create a separate recording in that format whenever a message is left. The benefit of this is that some transcoding steps may be saved if the stored format is the same as the codec used on the channel. We like wav because it is the highest quality, and wav49 because it is nicely compressed and easy to email. We don’t like gsm due to it’s scratchy sound, but it enjoys some popularity.[a]
serveremailuser@domainWhen an email is sent from Asterisk, this is the email address that it will appear to come from.[b]
attachyes,noIf an email address is specified for a mailbox, this determines whether the messages is attached to the email (if not, a simple message notification is sent).
maxmsg9999By default Asterisk will only allow a maximum of 100 messages to be stored per user. For users who delete messages, this is no problem. For people who like to save their messages, this space can get eaten up quickly. With the size of hard drives these days, you could easily store thousands of messages for each user, so our current thinking is to set this to the maximum and let the users manage things from there.
maxsecs0This type of setting was useful back in the days when a large voicemail system might have only 40 MB[c] of storage: it was necessary to limit the system because it was easy to fill up the hard drive. This setting can be annoying to callers (although it does force them to get to the point, so some people like it). Nowadays, with terabyte drives becoming common, there is no reason not to set this to a high value. Two considerations are: 1) if a channel gets hung in a mailbox, it’s good to set some sort of value so it doesn’t stay there for days, but 2) if a user wants to use her mailbox to record notes to herself, she won’t appreciate it if you cut her off after three minutes. A setting somewhere between 600 seconds (10 minutes) and 3600 seconds (1 hour) will probably be about right.
minsecs4Many folks will hang up instead of leaving a message when they call somebody and get voicemail. Sometimes this hangup happens after recording has started, so the mailbox owner gets an annoying two-second message of somebody hanging up. This setting ensures that Asterisk will ignore messages that are shorter than the configured minimum length. You should take care not to set this to a value that is too high, though, because then a message like “Hey it’s me give me a call” (which can be said in less than one second) will get lost, and you’ll get complaints of messages disappearing. Three seconds seems to be about right. To discourage people from leaving ultra-short messages that might be discarded, you can request callers to identify themselves and leave some information about why they called.
maxgreet1800You can define the maximum greeting length if you want. Again, since storage is not a problem and setting this too low will annoy your more verbose users, we suggest setting this to a high value and letting your users figure it out an appropriate length for themselves.
skipms3000When listening to messages, users can skip ahead or backwards by pressing (by default) * and #. This setting indicates the length of the jump (in milliseconds).
maxsilence5This setting defines the maximum time for which the caller can remain silent before the recording is stopped. We like to set this setting to one second longer than minsecs (if you set it equal to or greater than minsecs, you will get a warning).
silencethreshold128You can fine-tune the silence sensitivity of Asterisk to better define what qualifies as silence. In practice, this is seldom a good idea, since you cannot control the volumes of all the calls you’ll be getting from different places. It’s best to leave this at the default.
maxlogins3This little security feature is intended to make brute-force attacks on your mailbox passwords more time-consuming. If a bad password is received this many times, voicemail will hang up and you’ll have to call back in to try again. Note that this will not lock up the mailbox. Patient snoopers can continue to try to log into your mailbox as many times as they like, they’ll just have to call back every third attempt. If you have a lot of ham-fingered users, you can set this to something like 5.
moveheardyesThis setting will move listened-to messages to the Old folder. We recommend leaving this at the default.
forward_urgent_autonoSetting this to yes will preserve the original urgency setting of any messages the user receives and then forwards on. If you leave it at no, users can set the urgency level themselves on messages that they forward.
userscontextdefaultIf you use the users.conf file (we don’t), you can define here the context where entries are registered.
externnotify/path/to/scriptIf you wish to run an external app whenever a message is left, you can define it here.
smdienablenoIf you are using Asterisk as a voicemail server on a PBX that supports SMDI, you can enable it here.
smdiport/dev/ttyS0Here is where you would define the SMDI port that messages between Asterisk and the external PBX would pass across.
externpass/path/to/scriptAny time the password on a mailbox is changed, the script you define here will be notified of the context, mailbox, and new password. The script will then be responsible for updating voicemail.conf (the Asterisk voicemail app will not update the password if this parameter is defined).
externpassnotify/path/to/scriptAny time the password on a mailbox is changed, the script you define here will be notified of the context, mailbox, and new password. Asterisk will handle updating the password in voicemail.conf. If you have defined externpass, this option will be ignored.
externpasscheck/usr/local/bin/voicemailpwcheck.pySee the sidebar following this table for a description of this option.
directoryintrodir-introThe Directory() dialplan application uses the voicemail.conf file to search by name from an auto attendant. There is a default prompt that plays, called dir-intro. If you want, you can specify a different file to play instead.
charsetISO-8859-1If you need a character set other than ISO-8859-1 (a.k.a Latin 1) to be supported, you can specify it here.
adsifdn0000000FUse this option to configure the Feature Descriptor Number.[d]
adsisec9BDBF7ACUse this option to configure the security lock code.
adsiver1This specifies the ADSI voicemail application version number.
pbxskipyesIf you do not want emails from your voicemail to have the string [PBX] added to the subject, you can set this to yes.
fromstringThe Asterisk PBXYou can use this setting to configure the From: name that will appear in emails from your PBX.
usedirectoryyesThis option allows users composing messages from their mailboxes to take advantage of the Directory.
odbcstorage<item from res_odbc.conf>If you want to store voice messages in a database, you can do that using the Asterisk res_odbc connector. Here, you would set the name of the item in the res_odbc file. For details, see Chapter 22.
odbctable<table name>This setting specifies the table name in the database that the odbcstorage setting refers to. For details, see Chapter 22.
emailsubject[PBX]: New message ${VM_MSGNUM} in mailbox ${VM_MAILBOX}When Asterisk sends an email, you can use this setting to define what the Subject: line of the email will look like. See the voicemail.conf.sample file for more details.
emailbodyDear ${VM_NAME}: just wanted to let you know you were just left a ${VM_DUR} long message (number ${VM_MSGNUM}) in mailbox ${VM_MAILBOX u might want to check it when you get a chance. Thanks! --Asterisk When Asterisk sends an email, you can use this setting to define what the body of the email will look like. See the voicemail.conf.sample file for more details.
pagerfromstringThe Asterisk PBXWe don’t actually know anybody who uses pagers anymore (nor can we recall having seen one in many years), but if you have one of these historical oddities and you want to customize what Asterisk sends with its pager notification, presumably you can do that with this. A very practical usage of this feature for short message voicemail notifications is to send a message to an email to SMS gateway.
pagersubjectNew VMAs above.
pagerbodyNew ${VM_DUR} long msg in box ${VM_MAILBOX} from ${VM_CALLERID}, on ${VM_DATE}The formatting for this uses the same rules as emailbody.
emaildateformat%A, %d %B %Y at %H:%M:%SThis option allows you to specify the date format in emails. Uses the same rules as the C function STRFTIME.
pagerdateformat%A, %d %B %Y at %H:%M:%SThis option allows you to specify the date format in pager. Uses the same rules as the C function STRFTIME.
mailcmd/usr/sbin/sendmail -tIf you want to override the default operating system application for sending mail, you can specify it here.
pollmailboxesno, yesIf the contents of mailboxes are changed by anything other than app_voicemail (such as external applications or another Asterisk system), setting this to yes will cause app_voicemail to poll all the mailboxes for changes, which will trigger proper message waiting indication (MWI) updates.
pollfreq30Used in concert with pollmailboxes, this option specifies the number of seconds to wait between mailbox polls.
imapgreetingsno, yesThis enables/disables remote storage of greetings in the IMAP folder. For more details, see Chapter 18.
greetingsfolderINBOXIf you’ve enabled imapgreetings, this parameter allows you to define the folder your greetings will be stored in (defaults to INBOX).
imapparentfolderINBOXIMAP servers can handle parent folders in different ways. This field allows you to specify the parent folder for your mailboxes. For more details, see Chapter 7.

[a] The separator that is used for each format option must be the pipe (|) character.

[b] Sending email from Asterisk can require some careful configuration, because many spam filters will find Asterisk messages suspicious and will simply ignore them. We talk more about how to set email for Asterisk in Chapter 18.

[c] Yes, you read that correctly: megabytes.

[d] The Analog Display Services Interface is a standard that allows for more complex feature interactions through the use of the phone display and menus. With the advent of VoIP telephones, ADSI’s popularity has decreased in recent years.

Part of the [general] section is an area that is referred to as advanced options. These options (listed in Table 8-2) are defined in the same way as the other options in the [general] section, but they can also be defined on a per-mailbox basis, overriding whatever is defined under [general] for that particular setting.

Table 8-2. Advanced options for voicemail.conf

OptionValue/ExampleNotes
tzeastern, european, etc.Specifies the zonemessages name, as defined in the [zonemessages] section, discussed in the next section.
localede_DE.utf8, es_US.utf8, etc.Used to define how Asterisk generates date/time strings in different locales. To determine the locales that are valid on your Linux system, type locale -a at the shell.
attachyes, noIf an email address is specified for a mailbox, this determines whether the messages are attached to the email notifications (otherwise, a simple message notification is sent).
attachfmtwav49, wav, etc.If attach is enabled and messages are stored in different formats, this defines which format is sent with the email notifications. Often wav49 is a good choice, as it uses a better compression algorithm and thus will use less bandwidth.
saycidyes, noThis command will state the caller ID of the person who left the message.
cidinternalcontexts<context>, <another context>Any dialplan contexts listed here will be searched in an attempt to locate the mailbox context, so that the name associated with the mailbox number can be spoken. The voicemail box number needs to match the extension number that the call came from, and the voicemail context needs to match the dialplan context.[a]
saydurationyes, noThis command will state the length of the message.
saydurationm2Use this to specify the minimum duration of a message to qualify for its length being played back. For example, if you set this to 2, any message less than 2 minutes in length will not have its length stated.
dialout<context>If allowed, users can dial out from their mailboxes. This is considered a very dangerous feature in a phone system (mainly because many voicemail users like to use 1234 as their password), and is therefore not recommended. If you insist on allowing this, make sure you have a second level of password in the dialplan where another password is specified. Even so, this is not a safe practice.
sendvoicemailyes, noThis allows users to compose messages to other users from within their mailboxes.
searchcontextsyes, noThis allows voicemail applications in the dialplan to not have to specify the voicemail context, since all contexts will be searched. This is not recommended.
callback<context>This specifies which dialplan context to use to call back to the sender of a message. The specified context will need to be able to handle dialing of numbers in the format in which they are received (for example, the country code may not be received with the caller ID, but might be required for the outgoing call).
exitcontext<context>There are options that allow the callers to exit the voicemail system when they are in the process of leaving a message (for example, pressing 0 to get an operator). By default, the context the caller came from will be used as the exit context. If desired, this setting will define a different context for callers exiting the voicemail system.
reviewyes, noThis should almost always be set to yes (even though it defaults to no). People get upset if your voicemail system does not allow them to review their messages prior to delivering them.
operatoryes, noBest practice dictates that you should allow your callers to “zero out” from a mailbox, should they not wish to leave a message. Note that an o extension (not “zero,” “oh”) is required in the exitcontext in order to handle these calls.
envelopeno, yesYou can have voicemail play back the details of the message before it plays the actual message. Since this information can also be accessed by pressing 5, we generally set this to no.
deleteno, yesAfter an email message notification is sent (which could include the message itself), the message will be deleted. This option is risky, because even though a message was emailed, it is no guarantee that it was received (spam filters seem to love to delete Asterisk voicemail messages). Point being: on a new system, leave this at no until you are certain that no messages are being lost due to spam filters.
volgain0.0This setting allows you to increase the volume of received messages. Volume used to be a problem in older releases of Asterisk, but has not been an issue for many years. We recommend leaving this at the default. The sox utility is required for this to work.
nextaftercmdyes, noThis handy little setting will save you some time, as it takes you directly to the next message once you’ve finished dealing with the current message.
forcenameyes, noThis strange little setting will check if the mailbox password is the same as the mailbox number. If it is, it will force the user to change his voicemail password and record his name.
forcegreetingsyes, noAs above, but for greetings.
hidefromdirno, yesIf you wish, you can hide specific mailboxes from the Directory() application using this setting.
tempgreetwarnyes, noSetting this to yes will warn the mailbox owner that she has a temporary greeting set. This can be a useful reminder when people return from trips or vacations.
passwordlocationspooldirIf you want, you can have mailbox passwords stored in the spool folder for each mailbox.[b]
messagewrapno, yesIf this is set to yes, when the user has listened to the last message, pressing next (6) will take him to the first message. Also, pressing previous (4) when at the first message will take the user to the last message.
minpassword6This option enforces a minimum password length. Note that this does not prevent the users from setting their passwords to something that’s easy to guess (such as 123456).
vm-passwordcustom_soundIf you want, you can specify a custom sound here to use for the password prompt in voicemail.
vm-newpasswordcustom_soundIf you want, you can specify a custom sound here to use for the “Please enter your new password followed by the pound key” prompt in voicemail.
vm-passchangedcustom_soundIf you want, you can specify a custom sound here to use for the “Your password has been changed” prompt in voicemail.
vm-reenterpasswordcustom_soundIf you want, you can specify a custom sound here to use for the “Please reenter your password followed by the pound key” prompt in voicemail.
vm-mismatchcustom_soundIf you want, you can specify a custom sound here to use for the “The passwords you entered and reentered did not match” prompt in voicemail.
vm-invalid-passwordcustom_soundIf you want, you can specify a custom sound here to use for the “That is not a valid password. Please try again” prompt in voicemail.
vm-pls-try-againcustom_soundIf you want, you can specify a custom sound here to use for the “Please try again” prompt in voicemail.
listen-control-forward-key#You can use this setting to customize the fast forward key.
listen-control-reverse-key*You can use this setting to customize the rewind key.
listen-control-pause-key0You can use this setting to customize the pause/unpause key.
listen-control-restart-key2You can use this setting to customize the replay key.
listen-control-stop-key13456789You can use this setting to customize the interrupt playback key.
backupdeleted0This setting will allow you to specify how many deleted messages are automatically stored by the system. This is similar to a recycle bin. Setting this to 0 disables this feature. Up to 9999 messages can be stored, after which the oldest message will be erased each time another message is deleted.

[a] Yes, we found this a bit confusing too.

[b] Typically the spool folder is /var/spool/asterisk/, and it can be defined in /etc/asterisk/asterisk.conf.

The [zonemessages] Section

The next section of the voicemail.conf file is the [zonemessages] section. The purpose of this section is to allow time zone–specific handling of messages, so you can play back to the user messages with the correct timestamps. You can set the name of the zone to whatever you need. Following the zone name, you can define which time zone you want the name to refer to, as well as some options that define how timestamps are played back. You can look at the ~/src/asterisk-complete/asterisk/1.8/configs/voicemail.conf.sample file for syntax details. Asterisk includes the examples shown in Table 8-3.

Table 8-3. [zonemessages] section options for voicemail.conf

Zone nameValue/ExampleNotes
easternAmerica/New_York|'vm-received' Q 'digits/at' IMpThis value would be suitable for the eastern time zone (EST/EDT).
centralAmerica/Chicago|'vm-received' Q 'digits/at' IMpThis value would be suitable for the central time zone (CST/CDT).
central24America/Chicago|'vm-received' q 'digits/at' H N 'hours'This value would also be suitable for CST/CDT, but would play back the time in 24-hour format.
militaryZulu|'vm-received' q 'digits/at' H N 'hours' 'phonetic/z_p'This value would be suitable for Universal Time Coordinated (Zulu time, formerly GMT).
europeanEurope/Copenhagen|'vm-received' a d b 'digits/at' HMThis value would be suitable for Central European time (CEST).

The Contexts Section

All the remaining sections in the voicemail.conf file will be the voicemail contexts, which allow you to segregate groups of mailboxes.

In many cases, you will only need one voicemail context, commonly named [default]. This is worth noting, as it will make things simpler in the dialplan: all the voicemail-related applications assume the context default if no context is specified. In other words, if you don’t require separation of your voicemail users, use default as your one and only voicemail context.

The format for the mailboxes is as follows:

mailbox => password[,FirstName LastName[,email addr[,pager addr[,options[|options]]]]]

Note

The pipe character (|) used to be more popular in Asterisk. For the first few years, it was used as the standard delimiter. More recently, it has almost completely been replaced by the comma; however, there are still a few places where the pipe is used. One of them is in voicemail.conf: for example, as a separator for any mailbox-specific options, and also as the separator character in the format= declarative. You’ll see this in our upcoming example, as well as in the voicemail.conf.sample file.

The parts of the mailbox definition are:

mailbox

This is the mailbox number. It usually corresponds with the extension number of the associated set.

password

This is the numeric password that the mailbox owner will use to access her voicemail. If the user changes her password, the system will update this field in the voicemail.conf file.

FirstName LastName

This is the name of the mailbox owner. The company directory uses the text in this field to allow callers to spell usernames.

email address

This is the email address of the mailbox owner. Asterisk can send voicemail notifications (including the voicemail message itself, as an attachment) to the specified email box.

pager address

This is the email address of the mailbox owner’s pager or cell phone. Asterisk can send a short voicemail notification message to the specified email address.

options

This field is a list of options for setting the mailbox owner’s time zone and overriding the global voicemail settings. There are nine valid options: attach, serveremail, tz, saycid, review, operator, callback, dialout, and exitcontext. These options should be in option = value pairs, separated by the pipe character (|). The tz option sets the user’s time zone to a time zone previously defined in the [zonemessages] section of voicemail.conf, and the other eight options override the global voicemail settings with the same names.

The mailboxes you define in your voicemail.conf file might look like the following examples:

[default]
100 => 5542,Mike Loukides,[email protected]
101 => 67674,Tim OReilly,[email protected]
102 => 36217,Mary JonesSmith,[email protected]

; *** This needs to all be on the same line
103 => 5426,Some Guy,,,dialout=fromvm|callback=fromvm
|review=yes|operator=yes|envelope=yes

[shifteight]
100 => 0107,Leif Madsen,[email protected]
101 => 0523,Jim VanMeggelen,[email protected],,attach=no|maxmsg=100
102 => 11042,Tilghman Lesher,,,attach=no|tz=central

Warning

The Asterisk directory cannot handle the concept of a family name that is anything other than a simple word. This means that family names such as O’Reilly, Jones-Smith, and yes, even Van Meggelen must have any punctuation characters and spaces removed before being added to voicemail.conf.

The contexts in voicemail.conf are an excellent and powerful concept, but you will likely find that the default context will be all that you need in normal use.

An Initial voicemail.conf File

We recommend the following sample as a starting point. You can refer to ~/asterisk-complete/asterisk/1.8/configs/voicemail.conf.sample for details on the various settings:

; Voicemail Configuration

[general]
format=wav49|wav
[email protected]
attach=yes
skipms=3000
maxsilence=10
silencethreshold=128
maxlogins=3
emaildateformat=%A, %B %d, %Y at %r
pagerdateformat=%A, %B %d, %Y at %r
sendvoicemail=yes ; Allow the user to compose and send a voicemail while inside

[zonemessages]
eastern=America/New_York|'vm-received' Q 'digits/at' IMp
central=America/Chicago|'vm-received' Q 'digits/at' IMp
central24=America/Chicago|'vm-received' q 'digits/at' H N 'hours'
military=Zulu|'vm-received' q 'digits/at' H N 'hours' 'phonetic/z_p'
european=Europe/Copenhagen|'vm-received' a d b 'digits/at' HM

[shifteight.org]
100 => 1234,Leif Madsen,[email protected]
101 => 1234,Jim Van Meggelen,[email protected]
102 => 1234,Russell Bryant,[email protected]
103 => 1234,Jared Smith,[email protected]

Note

Setting up a Linux server to handle the sending of email is a Linux administration task that is beyond the scope of this book. You will need to test your voicemail to email service to ensure that the email is being handled appropriately by the Mail Transfer Agent (MTA),[85] and that downstream spam filters are not rejecting the messages (one reason this might happen is if your Asterisk server is using a hostname in the email body that does not in fact resolve to it).

Dialplan Integration

There are two primary dialplan applications that are provided by the app_voicemail.so module in Asterisk. The first, simply named VoiceMail(), does exactly what you would expect it to, which is to record a message in a mailbox. The second one, VoiceMailMain(), allows a caller to log into a mailbox to retrieve messages.

The VoiceMail() Dialplan Application

When you want to pass a call to voicemail, you need to provide two arguments: the mailbox (or mailboxes) in which the message should be left, and any options relating to this, such as which greeting to play or whether to mark the message as urgent. The structure of the VoiceMail() command is this:

VoiceMail(mailbox[@context][&mailbox[@context][&...]][,options])

The options you can pass to VoiceMail() to provide a higher level of control are detailed in Table 8-4.

Table 8-4. VoiceMail() optional arguments

ArgumentPurpose
bInstructs Asterisk to play the busy greeting for the mailbox (if no busy greeting is found, the unavailable greeting will be played).
d([c])Accepts digits to be processed by context c. If the context is not specified, it will default to the current context.
g(#)Applies the specified amount of gain (in decibels) to the recording. Only works on DAHDI channels.
sSuppresses playback of instructions to the callers after playing the greeting.
uInstructs Asterisk to play the unavailable greeting for the mailbox (this is the default behavior).
UIndicates that this message is to be marked as urgent. The most notable effect this has is when voicemail is stored on an IMAP server. In that case, the email will be marked as urgent. When the mailbox owner calls in to the Asterisk voicemail system, he should also be informed that the message is urgent.
PIndicates that this message is to be marked as priority.

The VoiceMail() application sends the caller to the specified mailbox, so that he can leave a message. The mailbox should be specified as mailbox@context, where context is the name of the voicemail context. The option letters b or u can be added to request the type of greeting. If the letter b is used, the caller will hear the mailbox owner’s busy message. If the letter u is used, the caller will hear the mailbox owner’s unavailable message (if one exists).

Consider this simple example extension 101, which allows people to call John:

exten => 101,1,Dial(${JOHN})

Let’s add an unavailable message that the caller will be played if John doesn’t answer the phone. Remember, the second argument to the Dial() application is a timeout. If the call is not answered before the timeout expires, the call is sent to the next priority. Let’s add a 10-second timeout, and a priority to send the caller to voicemail if John doesn’t answer in time:

exten => 101,1,Dial(${JOHN},10)
exten => 101,n,VoiceMail(101@default,u)      

Now, let’s change it so that if John is busy (on another call), the caller will be sent to his voicemail, where he will hear John’s busy message. To do this, we will make use of the ${DIALSTATUS} variable, which contains one of several status values (type core show application dial at the Asterisk console for a listing of all the possible values):

exten => 101,1,Dial(${JOHN},10)
   same => n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)
   same => n(unavail),VoiceMail(101@default,u)
   same => n,Hangup()
   same => n(busy),VoiceMail(101@default,b)
   same => n,Hangup()

Now callers will get John’s voicemail (with the appropriate greeting) if John is either busy or unavailable. A slight problem remains, however, in that John has no way of retrieving his messages. We will remedy that in the next section.

The VoiceMailMain() Dialplan Application

Users can retrieve their voicemail messages, change their voicemail options, and record their voicemail greetings using the VoiceMailMain() application. VoiceMailMain() accepts two arguments: the mailbox number (and optionally the context) to be accessed, and some options. Both arguments are optional.

The structure of the VoiceMailMain() application looks like this:

VoiceMailMain([mailbox][@context][,options])

If you do not pass any arguments to VoiceMailMain(), it will play a prompt asking the caller to provide her mailbox number. The options that can be supplied are listed in Table 8-5.

Table 8-5. VoiceMailMain() optional arguments

ArgumentPurpose
pAllows you to treat the <mailbox> parameter as a prefix to the mailbox number.
g(#)Increases the gain by # decibels when playing back messages.
sSkips the password check.
a(folder)Starts the session in one of the following voicemail folders (defaults to 0): 0 - INBOX, 1 - Old, 2 - Work, 3 - Family, 4 - Friends, 5 - Cust1, 6 - Cust2, 7 - Cust3, 8 - Cust4, 9 - Cust5

To allow users to dial an extension to check their voicemail, you could add an extension to the dialplan like this:

[Services]

exten => *98,1,VoiceMailMain()

Creating a Dial-by-Name Directory

One last feature of the Asterisk voicemail system that we should cover is the dial-by-name directory. This is created with the Directory() application. This application uses the names defined in the mailboxes in voicemail.conf to present the caller with a dial-by-name directory of the users.

Directory() takes up to three arguments: the voicemail context from which to read the names, the optional dialplan context in which to dial the user, and an option string (which is also optional). By default, Directory() searches for the user by last name, but passing the f option forces it to search by first name instead. Let’s add two dial-by-name directories to the incoming context of our sample dialplan, so that callers can search by either first or last name:

exten => 8,1,Directory(default,incoming,f)
exten => 9,1,Directory(default,incoming)

If callers press 8, they’ll get a directory by first name. If they dial 9, they’ll get the directory by last name.

Using a Jitterbuffer

When using Asterisk as a voicemail server,[86] you may want to add a jitterbuffer in between voicemail and the caller. The purpose of a jitterbuffer is to help deal with the fact that when a call traverses an IP network, the traffic may not arrive with perfect timing and in perfect order. If packets occasionally arrive with a bit of delay (jitter) or if they arrive out of order, a jitterbuffer can fix it so that the voicemail system receives the voice stream on time and in order. If the jitterbuffer detects that a packet was lost (or may arrive so late that it will no longer matter), it can perform packet loss concealment. That is, it will attempt to make up a frame of audio to put in place of the lost audio to make it harder to hear that audio was lost.

In Asterisk, jitterbuffer support can only be enabled on a bridge between two channels. In the case of voicemail, there is generally only a single channel connected to one of the voicemail applications. To enable the use of a jitterbuffer in front of voicemail, we create a bridge between two channels by using a Local channel and specifying the j option. Specifying the n option for the Local channel additionally ensures that the Local channel is not optimized out of the call path in Asterisk:

[Services]

exten => *98,1,Dial(Local/vmm@Services/nj)

exten => vmm,1,VoiceMailMain()

Storage Backends

The storage of messages on a traditional voicemail system has always tended to be overly complicated.[87] Asterisk, on the other hand, not only provides you with a simple, logical, filesystem-based storage mechanism, but also offers a few extra message storage options.

Linux Filesystem

By default, Asterisk will store voice messages in the spool folder, at /var/spool/asterisk/voicemail/<context>/<mailbox>. The messages can be stored in multiple formats (such as WAV and GSM), depending on what you specified as the format in the [general] section of your voicemail.conf file. Your greetings will also be stored in this folder.

Note

Asterisk will not create a folder for any mailboxes that do not have any recordings yet (as would be the case with a new mailbox), so this folder cannot be used as a reliable method of determining which mailboxes exist on the system.

Here’s an example of what might be in a mailbox folder. This mailbox has no new messages in the INBOX, has two saved messages in the Old folder, and has busy and unavailable greetings recorded:

/var/spool/asterisk/voicemail/default
./INBOX
./Old
./Old/msg0000.WAV
./Old/msg0000.txt
./Old/msg0001.WAV
./Old/msg0001.txt
./Urgent
./busy.WAV
./unavail
./unavail.WAV

Note

For each message, there is a matching msg####.txt file, which contains the envelope information for the message. The msg####.txt file is also critically important for message waiting indication (MWI), as this is the file that Asterisk looks for in the INBOX to determine whether the message light for a user should be on or off.

ODBC

In a centralized or distributed system, you may find it desirable to store messages as binary objects in a database, instead of as files on the filesystem. We’ll discuss this in detail in ODBC Voicemail.

IMAP

Many people would prefer to manage their voicemail as part of their email. This has been called unified messaging by the telecom industry, and its implementation has traditionally been expensive and complex. Asterisk allows for a fairly simple integration between voicemail and email, either through its built-in voicemail to email handler, or through a relationship with an IMAP server. We’ll discuss IMAP integration in detail in VoiceMail IMAP Integration.

Using Asterisk As a Standalone Voicemail Server

In a traditional telecom environment, the voicemail server was typically a standalone unit (provided either as a separate server altogether, or as an add-in card to the system). Very few PBXs had fully integrated voicemail (in the sense that voicemail was an integral part of the PBX rather than a peripheral device).

Asterisk is quite capable of serving as a standalone voicemail system. The two most common reasons one might want to do this are:

  1. If you are building a large, centralized system and have several servers each providing a specific function (proxy server, media gateway, voicemail, conferencing, etc.)

  2. If you wish to replace the voicemail system on a traditional PBX with an Asterisk voicemail

Asterisk can serve in either of these roles.

Integrating Asterisk into a SIP Environment As a Standalone Voicemail Server

If you want to have Asterisk act as a dedicated voicemail server (i.e., with no sets registered to it and no other types of calls passing through it), the process from the dialplan perspective is quite simple. Getting message waiting to work can be a bit more difficult, though.

Let’s start with a quick diagram. Figure 8-1 shows an overly simplified example of a typical SIP enterprise environment. We don’t even have an Asterisk server in there (other than for the voicemail), in order to give you a generic representation of how Asterisk could serve as a standalone voicemail server in an otherwise non-Asterisk environment.

Unfortunately, Asterisk cannot send message notification to an endpoint if it doesn’t know where that endpoint is. In a typical Asterisk system, where set registration and voicemail are handled on the same machine, this is never a problem, since Asterisk knows where the sets are. But in an environment where the sets are not registered to Asterisk, this can become a complex problem.

There are several solutions on the Internet that recommend using the externnotify option in voicemail.conf, triggering an external script whenever a message is left in a mailbox (or deleted). While we can’t say that’s a bad approach, we find it a bit kludgy, and it requires the administrator to understand how to write an external script or program to handle the actual passing of the message.

Simplified SIP enterprise environment

Figure 8-1. Simplified SIP enterprise environment

Instead you can statically define an entry for each mailbox in the voicemail server’s sip.conf file, indicating where the message notifications are to be sent. Rather than defining the address of each endpoint, however, you can have the voicemail server send all messages to the proxy, which will handle the relay of the message notifications to the appropriate endpoints.

The voicemail server still needs to know about the SIP endpoints, even though the devices are not registered directly to it. This can be done either through a sip.conf file that identifies each SIP endpoint, or through a static real-time database that does the same thing. Whether you use sip.conf or the Asterisk Realtime Architecture (ARA), each endpoint will require an entry similar to this:

[messagewaiting](!)            ; a template to handle the settings common 
                               ; to all mailboxes
type=peer
subscribecontext=voicemailbox  ; the dialplan context on the voicemail server
context=voicemailbox           ; the dialplan context on the voicemail server
host=192.168.1.1               ; ip address of presence server

[0000FFFF0001](messagewaiting) ; this will need to match the subscriber 
                               ; name on the proxy
mailbox=0000FFFF0001@DIR1      ; this has to be in the form mailbox@mailboxcontext
defaultuser=0000FFFF0001       ; this will need to match the subscriber 
                               ; name on the proxy

Note

Note that Asterisk’s dynamic realtime will not work with this configuration, as a peer’s information is only loaded into memory when there is an actual call involving that peer. Since message notification is not a call as far as Asterisk is concerned, using dynamic realtime will not allow message waiting to happen for any peers not registered to Asterisk.

You will not want to implement this unless you have prototyped the basic operation of the solution. Although we all agree that SIP is a protocol, not everyone agrees as to the correct way to implement the protocol. As a result, there are many interoperability challenges that need to be addressed in a solution like this. We have provided a basic introduction to this concept in this book, but the implementation details will depend on other factors external to Asterisk, such as the capabilities of the proxy.

The fact that no device has to register with Asterisk will significantly reduce the load on the Asterisk server, and as a result this design should allow for a voicemail server that can support several thousand subscribers.

Dialplan requirements

The dialplan of the voicemail server can be fairly simple. Two needs must be satisfied:

  1. Receive incoming calls and direct them to the appropriate mailbox

  2. Handle incoming calls from users wishing to check their messages

The system that is passing calls to the voicemail server should set some SIP headers in order to pass additional information to the voicemail server. Typically, this information would include the mailbox/username that is relevant to the call. In our example, we are going to set the headers X-Voicemail-Mailbox and X-Voicemail-Context, which will contain information we wish to pass to the voicemail server.[88]

Note

If the source system is also an Asterisk system, you might set the headers using the SIPAddHeader() voicemail application, in a manner similar to this:

exten => sendtovoicemail,1,Verbose(2,Set SIP headers for voicemail)
    same => n,SipAddHeader(X-Voicemail-Mailbox: <mailbox number>)
    same => n,SipAddHeader(X-Voicemail-Context: voicemailbox)

Note that this dialplan does not go on the voicemail server. It would only be useful if one of the other servers in your environment was also an Asterisk server. If you were using a different kind of server, you would need to find out how to set custom headers in that platform, or find out if it already uses specific headers for this sort of thing, and possibly modify the dialplan on the voicemail server to handle those headers.

The voicemail server will need an extensions.conf file containing the following:

[voicemailbox]
; direct incoming calls to a mailbox
exten =>  Deliver,1,NoOp()
    same =>  n,Set(Mailbox=${SIP_HEADER(X-Voicemail-Mailbox)})
    same =>  n,Set(MailboxContext=${SIP_HEADER(X-Voicemail-Context)})
    same =>  n,VoiceMail(${Mailbox}@${MailboxContext})
    same =>  n,Hangup()

; connect users to their mailbox so that they can retrieve messages exten =>  
Retrieve,1,NoOp()
    same =>  n,Set(Mailbox=${SIP_HEADER(X-Voicemail-Mailbox)})
    same =>  n,Set(MailboxContext=${SIP_HEADER(X-Voicemail-Context)})
    same =>  n,VoiceMailMain(${Mailbox}@${MailboxContext})
    same =>  n,Hangup()

sip.conf requirements

In the sip.conf file on the voicemail server, not only are entries required for all the mailboxes for message waiting notification, but some sort of entry is required to define the connection between the voicemail server and the rest of the SIP environment:

[VOICEMAILTRUNK]
type=peer
defaultuser=voicemail
fromuser=voicemail
secret=s0m3th1ngs3cur3
canreinvite=no
host=<address of proxy/registrar server>
disallow=all
allow=ulaw
dtmfmode=rfc2833
context=voicemailbox

The other end of the connection (probably your proxy server) must be configured to pass voicemail connections to the voicemail server.

Running Asterisk as a standalone voicemail server requires some knowledge of clustering and integration, but you can’t beat the price.

SMDI (Simplified Message Desk Interface)

The Simplified Message Desk Interface (SMDI) protocol is intended to allow communication of basic message information between telephone systems and voicemail systems.

Asterisk supports SMDI, but given that this is an old protocol that runs across a serial connection, there are likely to be integration challenges. Support in various PBXs and other devices may be spotty. Still, it’s a fairly simple protocol, so for sure it’s worth testing out if you are considering using Asterisk as a voicemail replacement.

The following is not a detailed explanation of how to configure SMDI for Asterisk, but rather an introduction to the concepts, with some basic examples. If you are planning on implementing SMDI, you will need to write some complex dialplan logic and have a good understanding of how to interconnect systems via serial connections.

SMDI is enabled in Asterisk by the use of two options in the [general] section of the voicemail.conf file:

smdienable=yes
smdiport=/dev/ttyS0; or whatever serial port you are connecting your SMDI service to

Additionally, you will need an smdi.conf file in your /etc/asterisk folder to define the details of your SMDI configuration. It should look something like this (see the smdi.conf.sample file for more information on the available options):

[interfaces]
charsize=7
paritybit=even
baudrate=1200           ; hopefully a higher bitrate is supported
smdiport=/dev/ttyS0     ; or whatever serial port you'll be using to handle 
                        ; SMDI messages on asterisk

[mailboxes]             ; map incoming digit strings (typically DID numbers) 
                        ; to a valid mailbox@context in voicemail.conf
smdiport=/dev/ttyS0     ; first declare which SMDI port the following mailboxes 
                        ; will use
4169671111=1234@default
4165551212=9999@default

In the dialplan there are two functions that will be wanted in an SMDI configuration. The SMDI_MSG_RETRIEVE() function pulls the relevant message from the SMDI message queue. You need to pass the function a search key (typically the DID that is referred to in the message), and it will pass back an ID number that can be referenced by the SMDI_MSG() function:

SMDI_MSG_RETRIEVE(<smdi port>,<search key>[,timeout[,options]])

Once you have the SMDI message ID, you can use the SMDI_MSG() function to access various details about the message, such as the station, callerID, and type (the SMDI message type):

SMDI_MSG(<message_id>,<component>)

In your dialplan, you will need to handle the lookup of the SMDI messages that come in, in order to ensure that calls are handled correctly. For example, if an incoming call is intended for delivery to a mailbox, the message type might be one of B (for busy) or N (for unanswered calls). If, on the other hand, the call is intended to go to VoiceMailMain() because the caller wants to retrieve his messages, the SMDI message type would be D, and that would have to be handled.

Conclusion

While the Asterisk voicemail system is quite old in terms of Asterisk code, it is nevertheless a powerful application that can (and does) compete quite successfully with expensive, proprietary voicemail systems.



[83] This name was a play on words, inspired in part by Nortel’s voicemail system Meridian Mail.

[84] No, you really don’t have to pay for this—and yes, it really does work.

[85] Also sometimes called a Message Transfer Agent.

[86] This advice applies to any situation where Asterisk is the endpoint of a call. Another example would be when using the MeetMe() or ConfBridge() applications for conferencing.

[87] Nortel used to store its messages in a sort of special partition, in a proprietary format, which made it pretty much impossible to extract messages from the system, or email them, or archive them, or really do anything with them.

[88] As far as we know, there aren’t any specific SIP headers that are standardized for this sort of thing, so you should be able to name the headers whatever you want. We chose these header names simply because they make some sort of sense. You may find that other headers would suit your needs better.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset