Setting up voicemail in Asterisk

In order to make a better product, we need to add a little "expected" functionality to Banana Phone; namely, voicemail.

Voicemail in Asterisk is fairly straightforward to setup. It comes with the standard features one might expect: password logins, save/delete, etc. Plus, we can add our own functionality to it, because Asterisk is good for it like that.

Add in some more sound files

We'll start by downloading the set of sound files that Asterisk needs to make it's voicemail system work. Start by ssh'ing into our Banana Phone server as the 'banana' user and navigate to the 'asterisk_resources/sounds' directory we created.

cd ~/banana_phone/asterisk_resources/sounds

Now run this wget command to download the standard set of Asterisk sound files from the Asterisk web site. They will be tarred up, so we'll uncompress them too.

wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-core-sounds-en-gsm-current.tar.gz
tar -xvf asterisk-core-sounds-en-gsm-current.tar.gz

Now Asterisk has the sound files it needs for us to use the VoiceMail app in our dialplan.


voicemail.conf

Move into the /etc/asterisk directory and change the name of the current voicemail.conf to voicemail.conf.bk.

cd /etc/asterisk
sudo mv voicemail.conf voicemail.conf.bk

Now create a new voicemail.conf

sudo nano voicemail.conf

Paste to following into voicemail.conf:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
[general]
; Formats for writing Voicemail
format=wav49|gsm|wav
;
; Who the e-mail notification should appear to come from
serveremail=asterisk
;serveremail=asterisk@linux-support.net
; Should the email contain the voicemail as an attachment
attach=no
; Maximum number of messages per folder.  If not specified, a default value
; (100) is used.  Maximum value for this option is 9999.  If set to 0, a
; mailbox will be greetings-only.
maxmsg=100
; Maximum length of a voicemail message in seconds
maxsecs=180
; Minimum length of a voicemail message in seconds for the message to be kept
; The default is no minimum.
minsecs=3
; Maximum length of greetings in seconds
;maxgreet=60
; How many milliseconds to skip forward/back when rew/ff in message playback
skipms=3000
; How many seconds of silence before we end the recording
maxsilence=7
; Silence threshold (what we consider silence: the lower, the more sensitive)
silencethreshold=128
; Max number of failed login attempts
maxlogins=8
;
; Move heard messages to the 'Old' folder automagically.  Defaults to on.
moveheard=yes
; Set the date format on outgoing mails. Valid arguments can be found on the
; strftime(3) man page
;
; Default
emaildateformat=%A, %B %d, %Y at %r
; 24h date format
;emaildateformat=%A, %d %B %Y at %H:%M:%S
;
; Default for pager use
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
pacific=America/LosAngeles|'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
;
;
[banana-vm]
PhoneHandset => 3333,Montel Williams,,tz=pacific|maxmsg=30
;
;

This is minimal configuration for voicemail in Asterisk. You can look at the settings individually if you so desire and see what each one does. The lines we want to look at are lines 54 and 55.

On line 54, we are naming a voicemail box called "banana-vm", similar to how we name contexts in extensions.conf.

On line 55, we associate this voicemail box with our 'PhoneHandset' endpoint. We then set a voicemail password, a name for the person using the mailbox, and some extra options for timezone and how many messages the box can hold.

You can check to see that your voicemail is setup properly by jumping into the Asterisk debug console and reloading the voicemail configuration.

asterisk -rvvvvv
voicemail reload

Edit extensions.conf

Now we will adjust extensions.conf to allow for two things:

  • Let us dial into our voicemail menu from the phone to hear/delete/save voicemails
  • Have calls go to voicemail if the phone doesn't get answered

Have a look at the following snippet from this new extensions.conf. Notice the changes we've made on just a few lines of our dialplan:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[PhoneHandset]
exten => 222,1,Answer()
    same => n,VoiceMailMain(@banana-vm)

exten => _X.,1,Answer()
    same => n,NoOp("in PhoneHandset extension")
    same => n,NoOp("dialed number: ${EXTEN}")
    same => n,Dial(SIP/${EXTEN}@PhoneLine)

[PhoneLine]
exten => 5555555555,1,NoOp("call registered")
    same => n,Answer()
    same => n,Set(CallTimestamp=${STRFTIME(${EPOCH},,%s)})
    same => n,Background(initial_greet)
    same => n,System(python ${SCRIPTS_DIR}add_log.py ${CALLERID(num)} '${CALLERID(name)}' ${CallTimestamp})
    same => n,Set(result=${SHELL(python ${SCRIPTS_DIR}check_whitelist.py ${CALLERID(num)})})
    same => n,Set(inWL=${REGEX("([YES])" ${result})})    
    same => n,NoOp(CID in DB: ${inWL})
    same => n,GotoIf($["${inWL}" = "1"]?liveline:banana)
    same => n(liveline),NoOp("passing to live line")
    same => n,Dial(SIP/PhoneHandset)
    same => n,VoiceMail(PhoneHandset@banana-vm,u)
    same => n(banana),Goto(BananaPhone,start,1)
    same => n,HangUp()

On line 2, we've added a new extension to the PhoneHandset context, 222. Then on line 3, we add in the VoiceMailMain app and reference "@banana-vm", the voicemail box we setup in voicemail.conf.

This lets us dial "222" from our phone and will drop us into the voicemail menu. To record a voicemail greeting, dial 222, wait for the prompt to enter the password, and

Check out line 24. After the Dial command, if the phone isn't picked up, it will then push the call to the voicemail box defined for PhoneHandset, which points to "banana-vm"

Conclusion

So now Banana Phone has voicemail.

My grandma did say it'd be nice if she had a way of seeing if any new messages were waiting for her. I thought that might be a good chance for me to test out this idea I had for text message notifications of waiting voicemails at home, but that's another tutorial all together.

I was also interested in speech recognition . . .