Route incoming call based on specific Caller ID name

My SIP provider has implemented a new feature (possibly related to STIR/SHAKEN) that changes the caller ID text to “Potential Spam” whenever they detect an incoming call that appears to be spam. So far they have been 100% correct.

Is there a way to route a called based on this specific caller ID text so I can send these calls to a no service message? I’ve seen similar posts on the forum, but they all seem much more complicated that this request, with possible online lookups to various spam services, or multiple text lookups with variables. I’m hoping for something to match a single text string every time.


Something like GotoIf($["${CALLERID(name)}"="Potential Spam"]?spamcontext,spamextension,1) as custom dialplan. This may need some tweaking depending on how the quotes are handled.

You could rename the initial context and follow the above with a Goto, to the standard context, or could invert the test, and put the spam handling in-line

Dynamic Routes can do this, see this thread for background: CID can get to IVR but have to enter PIN or being in whitelist to an certain option on IVR

Use David’s expression as the Asterisk Variable in this form:

$["${CALLERID(name)}"="Potential Spam"]

Which will return a 0 or a 1. Set dynroutes destinations as appropriate.

1 Like

I put a quote in the wrong place. Now corrected.

1 Like

Thank you very much, david55 and Igaetz!

I’m not very familiar with asterisk expressions. In the expression above, is a 0 for not matching the caller ID, whereas a 1 will match the caller ID text?

I installed the dynamic route module and setup call routing based on a 1 being a match. I’ll try a few test calls to make sure I didn’t break normal calling, and then wait and watch the logs to see if spam is being routed to null. It looks like the main inbound route needs to the dynamic route, so that is what I did. Here goes nothing…

Yes. 1 is true and 0 is false. The logging output is done after the expression is completely evaluated and all variables and functions have been substitute.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.