[Asterisk-Users] Remote MWI via IAX?

Karl A. Krueger kkrueger at whoi.edu
Mon Feb 7 10:09:20 MST 2005


On Mon, Feb 07, 2005 at 02:22:07AM -0800, George Pajari wrote:
> We have a couple of Asterisk boxes with one being the main system with 
> everyone's voicemail and the other a slave used merely to link a couple 
> of remote phones to the main system using IAX.
> 
> How can one propagate message waiting indication from the main system to 
> the remote phones?

This is not quite the same set-up, but we have phones registered against
an SER proxy with voice mail on Asterisk.  We send MWI NOTIFYs using the
Asterisk externnotify feature and a shellscript that composes the NOTIFY
message and sends it using sipsak.

Here's the script we are using with externnotify, and the template it
uses.  Please note that you have to set the configuration settings to
your SIP environment ...

++++ CUT HERE ++++ check_voicemail.sh ++++
#!/bin/bash
#
# check_voicemail.sh -- Asterisk voice mail externnotify script
#
# This script traverses the voice mail for a user and sends a SIP NOTIFY
# indicating how many voice mail messages they have.
#
# It can be triggered directly (e.g. from Asterisk dial plan) whenever it
# is appropriate to think that the number of messages has changed.
# 
# It can also be triggered periodically (e.g. from periodic_vm_check.sh)
# just in case a user has missed a NOTIFY.
#
# Command-line parameters:
#	$1 -- $VM_CONTEXT -- the called context (ignored)
#	$2 -- $EXTEN -- the user account to check (user at context)
# 	$3 -- $NUM_MSG -- ignored
# 
# Configuration:
#
# THIS_HOST -- the name of the host we are running on
THIS_HOST=some.host.example.com
#
# THIS_IP -- the IP address of the host we are running on
THIS_IP=127.0.0.1
#
# SIP_HOST -- the IP address of our SIP Proxy where the users are
SIP_HOST=127.0.0.2
#
# SIP_DOMAIN -- the domain into which the users are registered
SIP_DOMAIN=example.com
#
# SIP_SENDER -- the identity to send the message as
SIP_SENDER=1234		# users can call back to check voice mail
#
# LOG_FILE -- where to store our debugging log
LOG_FILE=/tmp/voicemail-log
#
# VM_ROOT -- the root of the Asterisk voice mail spool
VM_ROOT=/var/spool/asterisk/voicemail
#
# TEMPLATE -- the message template for a SIP NOTIFY message
TEMPLATE=/etc/asterisk/notify.msg


echo "RUN AT" `date` >> $LOG_FILE
echo "$1 $2 $3" >> $LOG_FILE

VM_CONTEXT=$1
E_AT_C=$2
NUM_MSG=$3

EXTEN=`expr substr $E_AT_C 1 \( \( index $E_AT_C @ \) - 1 \)`
CONTEXT=`expr substr $E_AT_C \( \( index $E_AT_C @ \) + 1 \) 64`

USER_DIR=$VM_ROOT/$CONTEXT/$EXTEN

# Did we get OK syntax?
if [ "$EXTENfoo" == "foo" ]
then
	echo Error, no user specified > /dev/stderr
	exit 1
fi

# Is there actually any such user?
if ! [ -d $USER_DIR ]
then
	echo No VM user $EXTEN in $CONTEXT > /dev/stderr
	exit 1
fi

# Count the number of VM messages for the user.
pushd $USER_DIR > /dev/null
TOTAL_MESSAGES=`find . -name "*.txt" | wc -l | sed 's/^ *\(.*\) *$/\1/'`
NEW_MESSAGES=`find INBOX -name "*.txt" | wc -l | sed 's/^ *\(.*\) *$/\1/'`
popd > /dev/null

OLD_MESSAGES=$(($TOTAL_MESSAGES - $NEW_MESSAGES))

if [ "$NEW_MESSAGES" == "0" ]
then
	HAS_NEW="no"
else
	HAS_NEW="yes"
fi

CONTENT_LENGTH=$((34 + `expr length $HAS_NEW` +
                       `expr length $NEW_MESSAGES` +
		       `expr length $OLD_MESSAGES`))

CMD="s/!SUBSCRIBER!/$EXTEN/g;s/!IP!/$THIS_IP/;s/!SENDER!/$SIP_SENDER/g;s/!DOMAIN!/$SIP_DOMAIN/g;s/!MAILBOX!/$EXTEN/g;s/!CONTENT_LENGTH!/$CONTENT_LENGTH/g;s/!HAS_MESSAGE!/$HAS_NEW/g;s/!NEW_COUNT!/$NEW_MESSAGES/g;s/!OLD_COUNT!/$OLD_MESSAGES/g" 

cat $TEMPLATE | sed $CMD | flip -m - - > /tmp/mwi-$$

sipsak -H $THIS_HOST -f /tmp/mwi-$$ -p $SIP_HOST -s sip:$EXTEN@$SIP_DOMAIN

rm /tmp/mwi-$$

++++ CUT HERE ++++ end of check_voicemail.sh ++++
++++ CUT HERE ++++ notify.msg ++++
NOTIFY sip:!SUBSCRIBER!@!DOMAIN! SIP/2.0
Via: SIP/2.0/UDP !IP!:5060
From: <sip:!SENDER!@!DOMAIN!>
To: <sip:!SUBSCRIBER!>
Contact: <sip:!MAILBOX!@!DOMAIN!>
Call-ID: 1234567890@!IP!
CSeq: 1 NOTIFY
User-Agent: VoiceMail
Event: message-summary
Content-Type: application/simple-message-summary
Content-Length: !CONTENT_LENGTH!

Messages-Waiting: !HAS_MESSAGE!
Voicemail: !NEW_COUNT!/!OLD_COUNT!
++++ CUT HERE ++++ end of notify.msg ++++

-- 
Karl A. Krueger <kkrueger at whoi.edu>
Network Security -- Linux/Unix Systems Support -- Etc.
Woods Hole Oceanographic Institution




More information about the asterisk-users mailing list