I simply forgot MWI wasn’t working since I get an email and just delete the message via email after listening! My daughter asked me why she never knows if she has a voicemail (she doesnt have usable email) and it prompted me to fix it. I’ll post what I did and how I did it shortly. Since call manager doesn’t inherently support authenticated sip trunks of course, no google voice integration, i’ve used my Asterisk server (running since 2002) as my Gateway for sometime. When I got my hands on a few 88xx, 8945s, and a dx650, I decided to setup call manager. To keep everything smooth, I just send everything to Asterisk and let it route to the cloud. Asterisk also provides my voicemail capability for the asterisk phones (my parents, a few military friends, and a few friends who would like to call locally within the US) and the Cisco phones. Calling into voicemail and diverting calls to voicemail is extremely basic so I won’t discuss this at all, but MWI stumped me. Asterisk handles MWI pretty differently from Unity Connection and I struggled with it for a bit. After an hour of internal server errors I decided to try scripting.
Prior to the scripting, I went ahead and created my MWI off and on DNs, 191# and 192# respectively. Dialing this from my Cisco phones would turn on or off the MWI successfully. So my thinking was, alright, a call comes in to asterisk, routes to cisco whereupon the timeout is hit or i decline the call. this sends a sip message back to asterisk which i use to send the call to the busy or unavailable voicemail recording. I needed to launch a script any time I dialed into voicemail or someone left me a voicemail. After some digging through my asterisk book and the subsequent verification that the options still exist in Asterisk 13, i stumbled upon externnotify for voicemail.conf. This let’s you specify a script to launch anytime voicemail is accessed.
From voip-info I read the following
Want to run an external program whenever a caller leaves a voice mail message for a user? This is where the externnotify command comes in handy. Externnotify takes a string value which is the command line you want to execute when the caller finishes leaving a message.
Note: see an example of an external notification script here.
Note: This command will also run after a person who has logged into a mailbox exits the VoiceMailMain() application. (Remark: This seems not to be the case for Asterisk 1.2.x)
The way it works is basically any time that somebody leaves a voicemail on the system (regardless of mailbox number), the command specified for externnotify is run with the arguments (in this order): context, extension, new voicemails, old voicemails and urgent voicemails. These arguments are passed to the program that you set in the externnotify variable.
This sounds pretty perfect, so I simply needed a bash script that would dial a number, with an RDNIS of the called number.
I came up with something like this
!/bin/bash off="Channel: SIP/cucm/191#\Callerid: $2\nMaxRetries: 0\nRetryTime: 0\nWaitTime: 2\nContext: $1\nExtension: $2" on="Channel: SIP/cucm/192#\Callerid: $2\nMaxRetries: 0\nRetryTime: 0\nWaitTime: 2\nContext: $1\nExtension: $2" if [[ $3 !ge 1 ]]; then echo -e $off >> /var/spool/asterisk/outgoing/$date.call else echo -e $on >> /var/spool/asterisk/outgoing/$date.call fi
this actually didn’t work and after some searching I found someone else with a very similar script that did work (damn quotes) and looked a bit more elegant. Sorry bud, honestly I think i found your snippet on a forum and I just can’t remember where, but thanks for saving me!
!/bin/bash CONTEXT=$1 EXTEN=$2 NUMVMS=$3 Turnoff="Channel: SIP/cucm/191#\nCallerid: $EXTEN\nMaxRetries: 0\nRetryTime: 5\nWaitTime: 5\nContext: $CONTEXT\nExtension: $EXTEN" Turnon="Channel: SIP/cucm/192#\nCallerid: $EXTEN\nMaxRetries: 0\nRetryTime: 5\nWaitTime: 5\nContext: $CONTEXT\nExtension: $EXTEN" if [[ $NUMVMS = "0" ]]; then echo -e $Turnoff >> /var/spool/asterisk/outgoing/$date.call else echo -e $Turnon >> /var/spool/asterisk/outgoing/$date.call fi
After setting permissions and ownership on the file, i called and left a voicemail and saw errors on my asterisk! Obviously, this crushed my heart as it should’ve worked perfectly, as I turned my head to the phone to clear out the voicemails from that test, i see a red MWI light. Even though asterisk received an error from Cisco, it actually worked perfectly. I did a few more tests and everything was perfect. As you would want, from the externnofity tip above, $3 is “new” voicemails, meaning once you listen to it, this script will turn off your MWI because you don’t have “new” voicemails. I suppose you could use $4 to keep it lit until you delete voicemails, or perhaps monitor $5 and $3 for new and urgent so you don’t forget to take action or something. Personally, if I were to deal with urgent voicemails, I would probably have the script just send an email and/or text message to me.
Either way, my asterisk+cisco integration is working perfectly now!