Saturday, July 24, 2010

trixbox as voicemail system on cisco call manager

Recently I had a customer asked how to connect a trixbox to cisco call manager for use as a voicemail system.  It's actually not too hard to achieve, although it does require some manual customizations.  Here only the trixbox side will be covered, as far as I am aware, all the you need to do on the cisco side is to add a voicemail "pilot" number and the IP address of our trixbox, in our case we will be using 6199.   This setup does have some security concerns as there are no logins.  With that said as long as you don't have any outbound routes setup then they can't make any calls, but they could potentially access the voicemail.
Ok lets get down to the setup.  Login to the admin area of your trixbox webpanel.
What we need to do is create a custom context for the handling of the calls.  to do this we goto pbx->config file editor.   Then select extensions_custom.conf on the left hand side in that file we are going to create our custom context for handling calls.
[cisco-voicemail]
exten => _6199,1,Set(DEST=${CALLERID(number)})
exten => _6199,n,Macro(exten-vm,${DEST},${DEST})

the _6199 means 6199 is the number dialed. Then in the first line I get the callerid number and create a variable called DEST.  Then I use a predefined macro to call the voicemail in line 2

Ok... So that seems straight forward enough, but you need to create all the extensions in such a way so that they go into this context and goto the voicemail.

To do that you create a basic sip extension by putting the extension number in and then just put the voicemail information in.  Save it.  You will probably get an error about not having a sip password, just accept that.  Then you need to click on the extension you have just created to edit it.  The parts you need to change are this:

context = cisco-voicemail
qualify = no

From there you should be able to use the voicemail :)

that's great, but what about MWI ( Message Waiting Indicator ).  So in order to get that going we need to do a little more configuration.  That configuration is a custom notification command to the phone using the SIP notify.  below is the script I have used, it has some very basic parts and doesn't give a total of the old messages, as the cisco handsets didn't have the ability to display that information, so I removed a whole bunch of code from the original script and modified it slightly to make it fast and simple.  Below is the script, but in order to make that script work you need to tell asterisk to use it.  in voicemail.conf

externnotify = /var/lib/asterisk/script/notify-sip.sh

Here is the actual script used, if you are to use it all that will be require to change are the SIP_SERVER and the DOMAIN
#!/bin/bash
 
# This script send the SIP NOTIFY message to UA. The NOTIFY message
# can either enable or disable the UA message indicator. The script
# looks for any file in $VM_HOME and creates the NOTIFY message
#
# The actual NOTIFY message is sent to the SIP proxy by the sipsak
# utilty.  This script can be called from Asterisk when a voice mail
# is left to notify immediately, and it can also be called from a cron
# job to send out message notifications to all users with voicemail
#
# Adapted from the script found on [Serusers] mailing list:
# http://lists.iptel.org/pipermail/serusers/2005-May/019684.html
# 
# Adaptations by Josh Mahonin (jmahonin@cbnco.com), with credit to the 
# original creator.

# If Asterisk called us, save its parameters
VM_CONTEXT=$1
EXTENSION=$2
VM_COUNT=$3


# Voice mail file type
VM_TYPE=wav

# SIP settings
SIP_SERVER=ASTERISK_IP
SIP_PORT=5060
SIP_FROM=voicemail
user=${EXTENSION}
DOMAIN=DESTINATION_IP


SEQUENCE=$( printf "%06d" $RANDOM )
if [ $VM_COUNT -gt 0 ]
then
 HAS_NEW="yes"
else
 HAS_NEW="no"
fi

NEW_MESSAGES=$VM_COUNT
OLD_MESSAGES=0
CONTENT_LENGTH=$(( 34 + ${#HAS_NEW} + ${#NEW_MESSAGES} + ${#OLD_MESSAGES} ))

(
        cat <<-EOM
NOTIFY sip:${user}@${DOMAIN} SIP/2.0
From: 
To: 
Contact: 
Call-ID: ${SEQUENCE}@${SIP_SERVER}
CSeq: ${SEQUENCE} NOTIFY
Event: message-summary
Content-Type: application/simple-message-summary
Content-Length: ${CONTENT_LENGTH}

Messages-Waiting: ${HAS_NEW}
Voicemail: ${NEW_MESSAGES}/${OLD_MESSAGES}
 
EOM
) > out.msg
cat out.msg | /usr/bin/sipsak -s sip:${user}@${DOMAIN} -f -

        if [ $? -ne 0 ] ; then
            logger -t notify-script "Error: sipsak was not successful sending to $user"
        fi
 
exit 0