I’ve always been disappointed with off-the-shelf digital answering machines that are available from your favorite retailer. The quality is never up to par, the features are never quite right and generally there a few features that I’m not interested in. And since every answering machine works differently, you must always keep the manual around in case you need to work simple features such as changing the message or setting up multiple mailboxes.
After years of frustration and living with sub-par answering machines, I’ve finally decided to create my own. Sure, it sounds like a daunting task, but thanks to Mark Spencer of Digium, Inc. we now have a fantastic piece of software to work with called Asterisk. Asterisk is a complete PBX system and well known in the VoIP world. While it is admittedly overkill for the task of a simple answering machine, it met my goals (Table 1) perfectly and offers nearly unlimited expansion as my needs grow.
|Short Term||Long Term|
|Table 1: Project Objectives|
Note: While I take the approach of editing configuration files to bend Asterisk to my purposes, you could also use the more user-friendly [email protected] (AAH) to build your answering machine. See our previous article on AAH for more info.
The first part of the process was determining the operating system and hardware to use for the job. Being that Asterisk is licensed under the GPL, I decided to stick as much as possible to using open source software and that meant using Linux. While I’m no expert, I am most familiar with the Debian distribution so I decided to go that route. For those of you that aren’t Linux users, an important point to remember is that everything in Linux is case sensitive.
We first need to create a bootable installation CD and since I wanted a minimal amount of software, I started by downloading the official netinst ISO image for Debian stable which is currently named sarge. I chose the i386 distro, as most of the hardware I have around here is Intel compatible. At only 108 Mb, it didn’t take long to finish the download and burn the image to CD.
After much research, I determined that the hardware needs were minimal and almost any standard PC would do the job. The only specific hardware I needed was an FXO (Foreign Exchange Office) interface to provide connection to my PSTN line. There are many devices available, but I specifically wanted to keep everything as inexpensive as possible! I discovered that Digium used to sell a single port X100P PCI card that can be obtained on Ebay for $10.00-$20.00 (USD) delivered.
For the PC, I pieced together a system that consisted of an Athlon 850 MHz CPU on a Gigabyte motherboard with 384 MB of RAM, 10 GB hard drive and a CD-ROM drive I had laying around. I used an ATI PCI video card and since this particular motherboard didn’t have Ethernet built in, I added a 10/100 PCI NIC.
Installing Debian Sarge
I connected the power, video, keyboard, network and phone cables and inserted the Debian “sarge” CD I had burned eariler. Once the Debian boot screen came up I entered:
at the prompt as I wanted to use the 2.6 kernel over the default 2.4 kernel. The new sarge installer is quite slick and it doesn’t take a lot of Linux knowledge to get Debian running. I accepted all of the default options the installer presented. Although an IP address was picked up automatically from my router through DHCP, if you’re not using a DHCP server or need to configure a static address, the installer will prompt you for a few extra steps. You can always type:
after the installation for documentation on configuring your network.
When it came to drive partitioning, I chose to erase the entire disk and install all files onto one partition and instaled the Grub boot loader to the master boot record. After the install finishes, the CD will be ejected and the system will then reboot from the hard drive.
Once the reboot finishes, you will arrive at the base system configuration menu, where you’ll need to complete the following steps:
- Select your time zone
- Assign the root password
- Cancel creating a normal user
- Configure apt which is debian’s package management tool. I chose HTTP for the method and accepted the default mirror.
If you’d like to receive email notifications for new voicemails, you can choose: Configure the Mail Transfer Agent. Configuring Debian as a mail server is beyond the scope of this article, however, if you accept all defaults and choose Internet site, there is a good chance it might work. Note that you can always skip this step and come back to it later by typing:
Finally, choose Finish configuring the base system and congratulations, Debian is installed.
Since I didn’t create any users, I logged in as root to determine the IP address that DHCP had given out. At the command line type:
ifconfig eth0 | grep 'inet addr'
I made note that my IP address was 10.1.0.103, as I find it easier to use remote management through SSH (secure shell) from my workstation where I can have my web browser and multiple SSH sessions open at the same time. Of course, remote management is optional and you can continue to work directly on the Asterisk PC if you prefer.
To prepare the PC for remote management, you’ll need to download and install SSH, which you can do via apt:
aptitude install ssh
Once again, I accepted all suggested defaults and the install went without a hitch.
Installing the FXO and Asterisk
At this point, I turned off the monitor and moved to my Windows workstation to continue building my answering machine. The most popular SSH client for Windows that I’m aware of is PuTTY , and that’s what I used to remotely access the Debian machine. After downloading the executable, simply double click it, enter your Asterisk PC IP address, and hit open. You should then be prompted with a Security Alert asking you to accept a key. Choose Yes and enter “root” (without the quotes) when the “login as:” prompt appears. Once logged in, you’ll have full control as if you were sitting at the actual PC. You can start multiple SSH sessions into your Asterisk PC which will probably come in handy as you go.
Now we need to get and install the drivers (aka kernel modules) for the X100P card by issuing the following commands:
aptitude install module-assistant aptitude install kernel-headers-`uname -r` m-a prepare apt-get build-dep zaptel-source m-a a-i zaptel depmod -a modprobe zaptel modprobe wcfxo
If everything worked properly up to this point, you should be able to type:
lsmod | grep zaptel
and see something similar to:
zaptel 182020 1 wcfxo
Which indicates that the X100P drivers are installed. The final step is to install Asterisk itself, which is done by entering:
aptitude install asterisk asterisk-config asterisk-sounds-main
We’re almost there! Asterisk is now installed, as are the drivers for the X100P FXO Card. Now we just need to configure everything. By the way, a great resource for hardware configuration is available on Digium’s site here.
Tip: For the remainder of this article, I will be using the nano text editor to edit various configuration files. A few useful hotkey combinations to know are: Control-W to search the text of the file; Control-O to save the edited file; Control-X to exit; and Control-W followed by Control-V to jump to the end of the file.
We first need to make a few changes to the X100P card config file.
Will open the card’s configuration file with nano. Now add a new line at the end of the file:
After you save and exit, type:
and you should see that one channel is configured. Now change to the /etc/asterisk directory and open the zapata.conf file:
cd /etc/asterisk nano zapata.conf
and you should see a line similar to:
which you will modify to be:
At the end of the file add two lines:
context=incoming channel => 1
Finally, let’s make another modification so that Asterisk will start at boot in case we ever turn off or reboot this PC:
Now simply type:
to start it up in the background.
At this point you have configured Asterisk and have a working system. But whenever you change any config file, you need to reload the Asterisk configuration. There are several ways to do this, but one way is:
Finally, check that everything works by making sure you have a working phone line connected to your FXO card, and dialing in from a second line or cell phone. If everything is ok, you will hear the Asterisk demo.
Configuring Asterisk as an Answering Machine
Now that we have a working system we’d like to create our own message and use it as the main greeting. The quickest way to do this is to let Asterisk record your message. The configuration for the menu system is stored in /etc/asterisk/extensions.conf. This file has many examples of different configurations you might want to use. For the time being we just want to add a temporary extension as a way to record our welcome message.
By the way, I recommend making a copy of this file before you started changing it so that you can refer to the original at a later time. You can do this via:
cp extensions.conf extensions.conf.bak
Now you can open the file for editing
At the end of the file, create an extension by adding these three lines:
exten => 1205,1,Wait(2) exten => 1205,2,Record(/tmp/asterisk-recording:gsm) exten => 1205,3,Hangup
Now reload Asterisk (since you changed a configuration file, remember?) and dial back in from your outside line. Once the demo starts to explain the available extensions, dial 1205 to trigger your new extension. You should hear a beep and you can then record your greeting, which we will use instead of the demo greeting in a moment. Now that you’ve recorded your greeting, let’s move it where Asterisk can use it:
mv /tmp/asterisk-recording.gsm /usr/share/asterisk/sounds/
The extensions.conf file is very powerful and many articles could be written describing all of the functionality and flexibility it offers. But to keep things simple, we’re going to just modify the demo. Once again, open the file with nano:
And search for:
We’ll first a few more seconds to give you time to answer the phone. Replace:
exten => s,1,Wait,1
exten => s,1,Wait,7
Next, comment out the default demo greetings by adding a semi-colon to the start of the lines:
;exten => s,5,BackGround(demo-congrats) ;exten => s,6,BackGround(demo-instruct)
and add two new replacement instructions to play your greeting and send the caller to voicemail:
exten => s,5,BackGround(asterisk-recording) exten => s,6,Voicemail(u1234)
To stay consistent with other prompts, let’s add a method to hang up using the # key:
exten => #,1,Hangup
There is a lot of demo functionality in the file that we don’t really need, such as doing test VOIP calls and echo tests. So I added a semi-colon in front of every line down to:
; Give voicemail at extension 8500
Optionally, you may also want to remove or comment out the 1205 extension we added earlier at the end of the file.
Once you’ve made and checked your changes, save them and exit nano and then reload the Asterisk configuration:
If you’d like to trim the extensions.conf file to a minimum here is how it would look:
[general] static=yes writeprotect=no [demo] exten => s,1,Wait,7 exten => s,2,Answer exten => s,3,DigitTimeout,5 exten => s,4,ResponseTimeout,10 exten => s,5,BackGround(asterisk-recording) exten => s,6,Voicemail(u1234) exten => #,1,Hangup exten => 8500,1,VoicemailMain exten => 8500,2,Goto(s,6) [default] include => demo
At this point your new answering machine is set up to receive calls and record voicemail. You can call in and check your messages by entering extension 8500 during the initial greeting. The default Asterisk voice will ask you for a mailbox number, which in our case is 1234. It will then ask you for a password, which is currently 4242.
Let’s change the default password for security reasons and let Asterisk know our email address so that it can send us email notifications of new voicemails:
Search for 1234 and change the 4242 to a new four digit numeric password. Also change the example email address to your own:
1234 => 3421,Example Mailbox,[email protected]
Reload asterisk to pick up these new changes:
A few other handy things to know are that:
will bring up the Asterisk console, while:
set verbose 1000
will increase logging detail. Now call in again and you will see all of the steps execute that you created in /etc/asterisk/extensions.conf. To exit the console type:
You can also see the raw log file which contains CallerID information by typing:
cd /var/log/asterisk/cdr-csv tail -100 Master.csv
Now that you have a working Asterisk PC acting as an answering machine, you can start experimenting with adding additional capabilities. For example, you could set up multiple mailboxes or issue different greetings based on the incoming CallerID. And, of course, you can always add VoIP PBX functions.
For further info, be sure to check out the Asterisk on Debian Wiki page as well as the Asterisk User Documentation Project.