NSLU2-Linux
view · edit · print · history

Here is a variation of the missing call email notification script done by Matt Schmandt (http://www.theschmandts.org/blog/2007/05/05/email-notifications-for-missed-calls-in-asterisk/(approve sites)). This will give the expected result also for the case when the called phone is not registered or is busy.

The missing call email notification script needs to be called on the hangup extension "h". You can add the h extension in any regular context you want email notifications for missed calls:

exten => h,1,System(asterisk-ic "my@email.net" "${CALLERID(num)}" "${CALLERID(name)}" "${DIALSTATUS}" "${VMSTATUS}" "${EXTEN}")

Here is the script:


#!/bin/sh
#Used for email alerting of incoming calls
#$1  email address
#$2  callerid num
#$3  callerid name
#$4  dial status
#$5  vm status
#$6  extension

if [ $# != 6 ]
then exit 1
fi

#Store command line args in nice variables
EMAIL=$1
CALLERIDNUM=$2
CALLERIDNAME=$3
DIALSTATUS=$4
VMSTATUS=$5
EXTEN=$6

DEBUG=0         #Set to 0 for standard operation.  1 will log inputs and mail commands for debugging.
LOGFILE="/var/log/asterisk/IncomingCalls.log"

SENDMAIL=1      #Set to 1 if you want it to email the alert.  0 is useful for debugging.
EMAILCMD="/usr/sbin/sendmail -t"
FROMEMAIL="your_sending@email.net"
SUBJECT="[PBX] Incoming call for extension ${EXTEN}"

#log mail command
if [ ${DEBUG} -eq 1 ]; then
        echo $1 $2 \"$3\" $4 $5 $6 >> ${LOGFILE}
fi

#Check we have an email address if not quit
if [ "${EMAIL}" = "" ]; then
        exit 0
fi

if [ ${DIALSTATUS} = "CANCEL" ]; then
        BODY="${CALLERIDNAME} (${CALLERIDNUM}) hung up."
elif [ ${DIALSTATUS} = "ANSWER" ]; then
        BODY="${CALLERIDNAME} (${CALLERIDNUM}) was answered by ${EXTEN}."
else
        BODY="[ ${DIALSTATUS} ] ${CALLERIDNAME} (${CALLERIDNUM}) hung up."
        #check for hangup in vm menu.  ex call went to vm and user hung up
        if [ ${VMSTATUS} = "USEREXIT" ]; then
                BODY="[ ${DIALSTATUS} ] ${CALLERIDNAME} (${CALLERIDNUM}) hung up on vm."
        fi
        #check for hangup in vm menu.  ex call went to vm and user hung up
        if [ ${VMSTATUS} = "FAILED" ]; then
                BODY="[ ${DIALSTATUS} ] ${CALLERIDNAME} (${CALLERIDNUM}) hung up on vm."
        fi
        #if they left a vm we already would get an email.  Don't need a 2nd
        if [ ${VMSTATUS} = "SUCCESS" ]; then
                exit 0
        fi
fi

#log mail command
if [ ${DEBUG} -eq 1 ]; then
echo "To: ${EMAIL} Subject: ${SUBJECT} ${BODY}" >> ${LOGFILE}
fi

#send email
if [ ${SENDMAIL} -eq 1 ]; then
${EMAILCMD} <<INLINE
To: ${EMAIL}
From: ${FROMEMAIL}
Subject: ${SUBJECT}

${BODY}

Asterisk PBX

INLINE
fi

exit 0

view · edit · print · history · Last edited by cdoban.
Originally by cdoban.
Page last modified on April 23, 2009, at 04:22 PM