Asterisk cmd LookupBlacklist
Synopsis:
Look up Caller*ID name/number from blacklist databaseDescription:
LookupBlacklistLooks up the Caller*ID number on the active channel in the Asterisk database (family 'blacklist'). If the number is found, and if there exists a priority n + 101, where 'n' is the priority of the current instance, then the channel will be setup to continue at that priority level.
Otherwise, it returns 0. Does nothing if no Caller*ID was received on the channel.
Example:
Sample Section for extensions.conf
[incoming]
exten => s,1,LookupBlacklist
exten => s,2,Dial(SIP/1234,15)
exten => s,3,Answer
exten => s,4,Wait(1)
exten => s,6,Voicemail(u1)
exten => s,7,Hangup
exten => s,102,Goto(blacklisted,s,1)
[blacklisted]
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,Zapateller
exten => s,4,Zapateller
exten => s,5,Playback(ss-noservice)
exten => s,6,Hangup
Note: On asterisk 1.2+ you must add (j) to the end, in order for it to actually make the priority jump. Like such:
exten => s,1,LookupBlacklist(j)
otherwise, it will just continue onto the next priority.
To insert a number into the Black list from the CLI
database put blacklist <name/number> 1
eg. database put blacklist 0123456789 1
Stores 0123456789 as a blackilsted CallerID
To delete a number from the blacklist using the CLI
database del blacklist <name/number>
eg. database del blacklist 0123456789
Deletes 0123456789 from the blacklist database
Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Comments
333${CALLERIDNUM} also deprecated.
exten => s,1,GotoIf(${DB_EXISTS(blacklist/${CALLERID(number)})}?blacklisted,s,1) ; If the number portion of the callerid is matched to blacklist, jump to context blacklisted, ext s, priority 1
exten => s,2,NoOp( Not Blacklisted )
exten => s,3,Dial(SIP/.....)
Since ${CALLERIDNUM} was marked as deprecated in 1.4.0 and has been removed by 1.6.0.
If the caller withholds their number, the above produces an error (unless you make CALLERID(number) equal something on condition that it is empty in the first place). This error does not interrupt the call flow so can be ignored.
I can verify that this works in 1.6.0-beta9.
333${CALLERIDNUM} empty
after first $ in GotoIf( need use [ and second ] after last }.
333${CALLERIDNUM} empty
exten => s,1,LookupBlacklist(j)
or
exten => s,1,GotoIf($${DB(blacklist/${CALLERID(name)})}?blacklisted,s,1)
or
exten => s,1,GotoIf($ ${BLACKLIST()} ?blacklisted,s,1)
or
exten => s,1,GotoIf($ ${DB_EXISTS(blacklist/${CALLERID(name)}) ?blacklist,s,1)
333asterisk 1.4.4 tweaks
333LookupBlacklist Deprecated
Looks like LookupBlacklist has been deprecated and is being replaced by the ${BLACKLIST()} function.
I've begun replacing my dialplan with DB_EXISTS() instead. Note that with DB_EXISTS you can match *any*
database family: blacklist, friendlist, whitelist etc.
exten => s,1,GotoIf(${DB_EXISTS(blacklist/${CALLERIDNUM})}?blacklisted,s,1) ; If callerid is matched to blacklist, jump to context blacklisted, ext 1, priority 1
exten => s,2,NoOp( Not Blacklisted )
exten => s,3,Dial(SIP/.....)