Wednesday, August 23, 2017

Monitor missed calls (Asterisk)

There is a way to monitor, if your employees are missing some calls by having this pretty simply script

/usr/local/sbin/vm-mailer.sh
#!/bin/bash

EXTEN=$1
CID=$2
TEST=0
EMAILTO="boss@compamy.com"
[ "$TEST" -gt 0 ] && EMAILTO='developer@freelancer.br'
mfile='/tmp/mail-ab'
if [ -z "$2" ] || [ -z "$1" ]
then
    exit 1
fi

echo "Hello!" > $mfile
echo "" >> $mfile
echo "There is missed call from $CID to extension $EXTEN" >> $mfile
echo "" >> $mfile
echo "If there is any voicemail has been left by the caller, it will be mailed you soon" >> $mfile
echo "" >> $mfile
echo "-----------" >> $mfile
echo "Best regards" >> $mfile

then just simply add to your dialplan of the local extensions

exten => _XXX,1,Dial(SIP/${EXTEN},15)
exten => _XXX,n,NoOp(Voicemail for ${EXTEN})
exten => _XXX,n,System(/usr/local/sbin/vm-mailer.sh ${EXTEN} ${CALLERID(num)}) <--ADD THIS
exten => _XXX,n,Voicemail(${EXTEN},u)
exten => _XXX,n,Hangup

it has to be added before Voicemail, otherwise a caller may hangup during before voicemail is complete.

Now you'll be receiving email once a call to any of your local extensions got missed. To switch it into developer mode set TEST=1