[inbound] ; Insert a gosub before the rest of your script. exten => ._,1,Gosub(spamcheck, CHECK, 1); ; Rest of your script goes here. ;exten => ._,n,RestOfScript [spamcheck] ; Before answering the call, run the phonespamfilter AGI script. exten => CHECK,1,AGI(phonespamfilter.php) ; If the call is SPAM, transfer to the SPAM extension. exten => CHECK,n,GotoIf($["${PHONESPAMFILTER}" = "2"]?SPAM,1:) ; If the callerid is not found, transfer to the NOCID extension. exten => CHECK,n,GosubIf($["${PHONESPAMFILTER}" = "0"]?NOCID,1:) ; Pass the call along to the rest of the script. exten => CHECK,n,Return() ; For SPAM calls, simply answer and then hang up. exten => SPAM,1,Answer() exten => SPAM,n,Hangup() ; For NOCID calls, we can do extra processing or prompts if we want. ; For this simple example, let the call through. exten => NOCID,1,Return()