Hack96.Build a Standalone Voicemail Server in Less Than a Half-Hour

Hack 96. Build a Standalone Voicemail Server in Less Than a Half-Hour

If you're a decent typist, it might take you only 15 minutes.

Asterisk comprises many quality applications, and voicemail is one of them. In fact, Asterisk is perhaps best known for the feature set of its voicemail system. In this section, I will demonstrate how you can harness Asterisk's extremely powerful voicemail application in 30 minutes or less. This way, everybody in your house (or your office) can have a customized voicemail greeting and message recorder, even if they don't have a desktop phone. Think of this as a road-warrior voicemail solution.

First, you will need to download my Asterisk distribution, AstLinux. AstLinux is made to run from CompactFlash, but it doesn't have to be that way. (Incidentally, if you'd like to run it from CompactFlash, check out "Build a SoftPBX with No Hard Drive" [Hack #95]. Pay attention to the keydisk portion, as you'll want one for this hack!) But because we want our voicemail server to be as reliable as possible, I am going to assume that you have a fair amount of storage spaceCompactFlash or hard diskavailable for use on this hack.

To build a standalone voicemail server, you'll need the following:

  • A standard PC with AstLinux

  • An IDE-to-CF adapter

  • A CompactFlash card of 32 MB or greater (a 256MB SanDisk is recommended)

Depending on what type of technology you are going to integrate this server with, your hardware needs will vary. If you are looking for an all-VoIP solution (possibly for use with another SIP PBX/proxy, etc.), you won't need any additional hardware, and you can skip ahead to the actual setup.

However, if you will be interfacing with a legacy PBX, you will need to get yourself some PSTN interface hardware. For some options, visit http://www.digium.com/ and http://www.sangoma.com/. The PCI interface cards from Digium and Sangoma allow you to connect to a legacy PBX using POTS lines or T1s. (For a crash course in configuring a Digium TDM card, read "Connect a Legacy Phone Line Using Zaptel" [Hack #44].)

Now for the nitty-gritty. After you have AstLinux running (and have made a keydisk), you need to do away with the default Asterisk configuration. There is just too much there for this simple task. You can blowit away by using this simple command (oh, and if there's anything in this file you want to keep, back it up first):

 # echo > /etc/asterisk/extensions.conf 

You then need to add some basic meat back into extensions.conf. Open extensions.conf in a text editor (vi is included by default) and add the following:

 [general] static=yes writeprotect=yes autofallback=no [globals] VMBASE=8XXX [default] include => vmserv exten => i,1,Hangup exten => t,1,Hangup [vmserv] exten => _${VMBASE},1,Voicemail(u${EXTEN}@vmserv) exten => _${VMBASE},2,Hangup exten => _9${VMBASE},1,VoicemailMain(${EXTEN:1}@vmserv) exten => _9${VMBASE},2,Hangup  

The first two lines under [general] tell Asterisk never to overwrite this file with something you tell it dynamically. This is a good idea. The next line tells Asterisk never to try to guess what to do if no action is assigned. For this simple configuration, it won't make much difference, but it is generally a good idea.

The line under [globals] is what you will want to pay the most attention to. Here, we are setting a variable named VMBASE that will contain the value of our mailboxes. In this configuration, we are creating a range of extensions that will map into a range of voice mailboxes. At this point, that range is 80008999 (8XXX). If this does not match what you have or need, change it now, as we will be using this variable throughout this hack.

Underneath [default], we are telling Asterisk to include the separate section [vmserv]. We are also defining what to do when a call goes to an invalid extension or times out: hang up on them!

The [vmserv] context is where the magic happens. We are using the variable ${VMBASE} to create a range of extensions. We are also telling Asterisk that when we get a call for one of those extensions, we should put that call into the voice mailbox of that extension, which has the same number. We will play back the unavailable greeting from that mailbox and hang up on the caller when he is finished leaving a message.

So how do we retrieve these voicemails? Simple; all you have to do is call into the Asterisk system and add a 9 before your mailbox number. So if your mailbox number is 8000, extension 8000 will allow callers to leave a message in mailbox 8000. To check mailbox 8000, you will call extension 98000. There are many ways to do this, and I suggest that you look into Asterisk substrings and extensions.conf to get a better idea. But for now, save extensions.conf because we are done here.

7.10.1. Create the Voice Mailboxes

Now that we have told Asterisk what to do with incoming calls, we need to tell Asterisk what voice mailboxes we want. The voicemail application is configured with the fileyou guessed itvoicemail.conf. As we did before, open it with vi or the web editor.

In the [general] section, uncomment forcename=no and set it to forcename= yes. This option enables Asterisk to force a new user to record his real name when he first accesses his voicemail. Asterisk determines whether a user is new by his PIN. If his PIN and voice mailbox are identical, Asterisk will guide him through setting up his voice mailbox. Scroll down to the bottom of voicemail.conf, and create a new section that looks like this:

 [vmserv] 8000 => 8000,Lisa Hayes,lisa@rt.com 8001 => 8001,Rick Hunter,rick@rt.com 8002 => 8002,Lynn Minmei,lynn@rt.com 8003 => 8003,Max Sterling,max@rt.com 8004 => 8004,Miriya Sterling,miriya@rt.com 

Here, you are creating five voice mailboxes for a fictional group of five folks. The fields in voicemail.conf map out like so:

 mailbox number => PIN,Real Name,E-mail address 

There are many more options, but you will have to dig deeper into Asterisk on your own time to discover them. You have only 30 minutes to get this done for me to be true to the title of this hack!

Now, all that remains is actually creating the directory structure for the mailboxes. AstLinux includes the addmailbox script from the contrib/scripts directory of the Asterisk source code. It is extremely easy to use and will do all the work for you based on your input. At a shell prompt, simply type addmailbox to get started. It will ask you for the voicemail context. Enter vmserv. It will then ask you for the mailbox number. Enter 8000. Congratulations! You just gave Lisa Hayes a mailbox. To create mailboxes for the rest of the users, simply rerun addmailbox, replacing 8000 with 8001, 8002, and so on.

7.10.2. Final Setup

If you would like to use the voicemail-to-email functionality provided by Asterisk and AstLinux, you will need to edit the /etc/rc.conf file and fill in the variable SMTP_SERVER with the IP address or hostname of an SMTP server that will relay mail for your Asterisk server. If you are delivering email to only one domain name, you can use the SMTP server for that domain name, as it will accept mail for it from any system. After making any other configuration changes, you will want to reboot your server to verify its configuration.

Now, how are you going to get your callers into this system? If you have a SIP platform, you simply need to send the callers into the PBX with a simple SIP URL, such as 8000@<IPAddress of Asterisk server>. This SIP URL will put the caller into Lisa Hayes's mailbox.

If you are using PSTN hardware (POTS/T1/E1/etc.), you are going to need to set up Zaptel and Zapata [Hack #44]. The same principles as before still apply; just make sure that you are sending callers into the default context when they ring in on Asterisk's Zaptel channels. And there you have it: a state-of-the-art voicemail system using all open source components, done in 30 minutes or less.

Kristian Kielhofner

VoIP Hacks
VoIP Hacks: Tips & Tools for Internet Telephony
ISBN: 0596101333
EAN: 2147483647
Year: 2005
Pages: 156

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net