The following is my shell script to notify the number received, it connects to the Asterisk server via telnet. Using expect program to monitor the AMI and it will notify the Mac Notification Center when there is an incoming call. All you need is to have the script run on your Mac. Although I have not tried the script on other OS, this is a shell script very easy to understand and change accordingly.
hkpopcorn:
The following is my shell script to notify the number received, it connects to the Asterisk server via telnet. Using expect program to monitor the AMI and it will notify the Mac Notification Center when there is an incoming call. All you need is to have the script run on your Mac. Although I have not tried the script on other OS, this is a shell script very easy to understand and change accordingly.
Open Terminal on Mac and start a shell window
Go to any folder to create a shell script. Say ~/Documents
Create a shell script file using vi or other editor. Say the script file name is CallNotify.sh
Copy the following into the script file and modify the settings accordingly.
#!/bin/sh
Asterisk Call Notification and informed the call using Mac OSX Notification Center
rhost=â192.168.1.10â # Asterisk server
uname=âJohnSmithâ # Need to add info into Asterisk file at the
passwd=âpasswordâ # /etc/asterisk/manager.conf
channel=âSIP/OBITRUNKâ # SIP trunk or can be trunks using wildcard
ntitle=âAsterisk Call Notificationâ # Notification title
logfile=â/Users/JohnSmith/Documents/CallNotify.logâ # Log file
Use expect program to monitor and output to result variable. Do not indent right.
while [ TRUE ] ; do
result=$(/usr/bin/expect <<EOD
set timeout -1
log_user 0
spawn telnet $rhost 5038
expect âAsterisk Call Managerâ
send âAction: login\râ
send âusername: $uname\râ
send âsecret: $passwd\r\râ
expect âAppData: 1?Set(CALLERID(name)â
expect "ConnectedLineNum: "
puts $expect_out(buffer)
send âAction: logoff\râ
close
EOD
)
Strip the return and newline using array. Extract CallerID channel, number and name.
IFS=$â\r\nâ # Set delimiter as return and newline
rarry=($result) # Save the expect program output in array
callchann=${rarry[4]/Channel: /} # Extract Caller channel from line 4
callidnum=${rarry[7]/CallerIDNum: /} # Extract CallerID number from line 7
callidname=â${rarry[8]/CallerIDName: /}â # Extract CallerID name from line 8
callidname=${callidname/â'â/â'â} # Replace character ' with â
unset IFS # Unset delimiter
CallerID info logged and sent to Mac OSX Notification Center
if [[ $callchann == $channel* ]] ; then # wildcard comparison of the channel name
dt=date +%Y-%m-%d\ %H:%M:%S
echo â$dt|$rhost|$callidnum|$callidname|$callchannâ
echo â$dt|$rhost|$callidnum|$callidname|$callchannâ >> â$logfileâ
osascript -e âdisplay notification "ââ$dt $callchannââ" with title "ââ$ntitleââ" subtitle "ââ$callidname $callidnumââ" sound name âFrogââ
sleep 5s
fi
done
Make the script file on Mac executable using this command:
chmod +x CallNotify.sh
Open the file /etc/asterisk/manager.conf on the Asterisk server and add the following.
[JohnSmith]
secret=password
read=all,call
write=all,originate,call
Restart Asterisk using the following command
asterisk -r
core restart now
Execute the script file on Mac using this command
./CallNotify.sh
Option to make the script file to run in the background
./CallNotify.sh &
When there is a call, Mac desktop notification center will show the CallerID info.
1 Like