Modify Asterisk Variable to Check Both Phonebook and Allow List

Hi everyone,

I’m trying to modify the following Asterisk variable, which currently checks if the caller ID exists in the Asterisk Phonebook:

${DB_EXISTS(cidname/${CALLERID(number)})}

I’d like to adjust this so that it also checks if the caller ID exists in an “Allowlist” module database entry. Essentially, I want the logic to work as:

If the caller ID is in the Asterisk Phonebook OR in the Allowlist, the check should pass, with a 1. If not, it should result in a 0.

Any help or guidance would be greatly appreciated!

Thanks in advance.
Richie

You write an OR statement checking both. If it exists in one or the other return a 1

Blacklist Module module doing exactly this checks, have you checked that. @RichieH

It’s a function call.

Where you are using it probably allows Asterisk expressions.

Hi Tom,

I think I’m missing something here. If I set the Asterisk Variable to:

${DB_EXISTS(allowlist/${CALLERID(number)})}

And I add my mobile number to the Allowlist and I call the external number, the call will reach the ring group (expected). If I remove my mobile number from the Allowlist and call the external number again, the call will ring once then hang-up and not go to the IVR for Unknown Calls if match “0”.

If I try to combine both as an OR, with either my mobile number in the Allowlist or not, calling the external number from my mobile just causes the call to ring out. It doesn’t seem to match either a “0” or a “1”?

$[${DB_EXISTS(cidname/${CALLERID(number)})} | 
 {DB_EXISTS(allowlist/${CALLERID(number)})}]

I’m probably doing something wrong here, I think the problem is the way I am doing this as the allowlist isn’t returning 0 if the caller ID isn’t in the allowlist.

Would greatly appreciate any help/advice :grinning:

Cheers,
Richie

Your missing the leading $ char for the allowlist check

$[${DB_EXISTS(cidname/${CALLERID(number)})} | ${DB_EXISTS(allowlist/${CALLERID(number)})}]

Didn’t check the brackets/paren you’re on your own there.

1 Like

Thank you for spotting that out. The leading $ must have came off when I backspaced when pasting that into my response as the value looked like it had created a new line at that point. The one you modified is the one I tested and it doesn’t seem to return a “0” or “1”.

Show us the full line starting from exten =

Are you using this expression with the Dynamic Routes module? If you’re using an expression with square brackets, you must disable substitutions in the dynroute.

1 Like

Thank you! :+1: Yes, I was using this expression with a Dynamic Route and I had substitutions enabled. Just disabled that and now it’s working as I want it, thank you so much! This has been driving me insane for ages now, life saver!