Okay, here’s what I did. I warn you up front this DOES NOT WORK, but I can’t figure out where I am going wrong. First I created a file /share/var/lib/asterisk/agi-bin/check-everycall-us.agi which contains this:
BADCALLSCORE="0"
RETRIEVEDSCORE=`/usr/bin/curl -s -m 2 -A Mozilla/4.0 http://www.everycall.us/query\?${1}`
BADCALLSCORE=`echo ${RETRIEVEDSCORE} | grep score | sed -e 's/.*score=//' -e 's/ <br\/>//'`
if [ -z $BADCALLSCORE ]
then
BADCALLSCORE=0
fi
echo "SET VARIABLE badcallscore ${BADCALLSCORE}"
This works fine if I run it from the command line (it gets the score of a number I put in). Of course you do have to remember to change the permissions and ownership so they match the other agi files in that directory (must be executable, and user and group are asterisk, etc). Also be careful not to lose any of the backticks when copying the code.
Now the part that is oh so close, but giving me fits. I added this to /etc/asterisk/extensions_custom.conf (if YOU do this make sure there’s not already a from-pstn-custom context - if there is you’ll have to add this code to it):
[from-pstn-custom]
exten => _.,1,NoOp(Checking Everycall.us for bad caller)
exten => _.,n,AGI(check-everycall-us.agi,${CALLERID(number)})
exten => _.,n,NoOp(Everycall.us returned score of ${badcallscore})
exten => _.,n,GotoIf($["${badcallscore}" < "10"]?notbadcaller:badcaller)
exten => _.,n(badcaller),NoOp(Bad caller score above threshold, blocking call)
exten => _.,n,Congestion(20)
exten => _.,n,Macro(hangupcall,)
exten => _.,n(notbadcaller),NoOp(Bad caller score below threshold - continuing)
exten => h,1,Hangup()
The above may be a bit longer than it needs to be but keep in mind I’m still trying to debug it. The real issue seems to be the AGI call. I’m not doing it correctly, apparently, but I’m not sure what the correct format is. When a call comes in, I get an error like this (phone numbers have been munged for privacy reasons):
-- Executing [8005551212@from-trunk:1] NoOp("SIP/trunk1-08c47fa0", "Checking Everycall.us for bad caller") in new stack
-- Executing [8005551212@from-trunk:2] AGI("SIP/trunk1-08c47fa0", "check-everycall-us.agi|8005552368") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/check-everycall-us.agi
== check-everycall-us.agi|8005552368: Failed to execute ‘/var/lib/asterisk/agi-bin/check-everycall-us.agi’: Exec format error
!!! NOTE THE ABOVE LINE !!!
– Executing [8005551212@from-trunk:3] NoOp(“SIP/trunk1-08c47fa0”, "Everycall.us returned score of ") in new stack
– Executing [8005551212@from-trunk:4] GotoIf(“SIP/trunk1-08c47fa0”, “1?notbadcaller:badcaller”) in new stack
– Goto (from-trunk,2124007595,8)
– Executing [8005551212@from-trunk:8] NoOp(“SIP/trunk-1-08c47fa0”, “Bad caller score below threshold - continuing”) in new stack
So everything is working EXCEPT the actual AGI call. I’m 99% sure it’s just a syntax error but I’ve been looking at other examples and cannot figure out what I am doing wrong. I need to take a break from this so I’ll throw what I’ve done so far out there, in case anyone spots the obvious flaw in my code. By the way, suggestions for making it shorter/more efficient are also appreciated!