Maybe this has been done before; if it has, then I have wasted an hour of my time.
If not, then:
Here is a script that gets executed by Asterisk/FreePBX when a voicemail is left. The script makes use of voip.ms's SMS api function. That function is another script below called sendSMS.sh.
I only have one user that needs this, so the script is written for them only. I'm sure this could be enhanced to check all users. I just don't need that functionality. Therefore, replace ???? with the extension of the VM box.
#!/bin/bash vVmDirectory="/var/spool/asterisk/voicemail/default/????/INBOX" vMaxVmNumber=`ls $vVmDirectory/*.wav | tail -1 | cut -c 53-56` vMailBox=`cat $vVmDirectory/msg$vMaxVmNumber.txt | grep origmailbox | cut -d "=" -f2-`vCallerID=`cat $vVmDirectory/msg$vMaxVmNumber.txt | grep callerid`vDate=`cat $vVmDirectory/msg$vMaxVmNumber.txt | grep origdate | cut -d "=" -f2-`vDuration=`cat $vVmDirectory/msg$vMaxVmNumber.txt | grep duration | cut -d "=" -f2-` vCallerID=`echo "$vCallerID" | tr -d '"' | cut -d "=" -f2-`vDate=`date -d "$vDate"` if [ "${#vDuration}" -le 3 ]; then vTime="seconds"else vTime="minutes"fi /var/lib/asterisk/utils/sendSMS.sh "You have a new VM message in mailbox $vMailBox from:" " " " $vCallerID" " " " $vDate" " " " $vDuration $vTime long"
It's ugly, but it works. If I had more time, I would have written a shorter, cleaner script.
Here is the sendSMS.sh script:
#!/bin/bash vURL=https://voip.ms/api/v1/rest.phpvUSER=YOUR_USER_NAME_FOR_APIvKEY=YOUR_API_KEYvMETHOD=sendSMS urlencode() { # urlencode <string> local length="${#1}" for (( i = 0; i < length; i++ )); do local c="${1:i:1}" case $c in [a-zA-Z0-9.~_-]) printf "$c" ;; *) printf '%s' "$c" | xxd -p -c1 | while read c; do printf '%%%s' "$c"; done ;; esac done} ### echo $(urlencode "$1") wget -O /dev/null -o /dev/null $vURL?method=$vMETHOD\&api_username=$vUSER\&api_password=$vKEY\&did=PHONENUMBER\&dst=PHONENUMBER\&message=$(urlencode "$1")%0D%0A$(urlencode "$2")%0D%0A$(urlencode "$3")%0D%0A$(urlencode "$4")%0D%0A$(urlencode "$5")%0D%0A$(urlencode "$6")%0D%0A$(urlencode "$7")%0D%0A$(urlencode "$8")%0D%0A$(urlencode "$9") >/dev/null
This script takes 9 command line arguments and delivers them as 1 line each in a SMS message. There is no error control for long messages and no feedback for other errors.
↧