Different blacklist for different queues

Hey there, this is my first post here!

We have one asterisk with a blacklist activated, but my boss told me “Can we have different blacklists for each queue?”

I’ve been searching but i didnt get anything, I suppose that I have to manually edit my dialplan, but the thruth is that I have inherited the system and we have certain custom configs that don’t help while trying to modify something

Can someone help me out? Is this even possible to do?

Thanks and regards for any information

I think so.

Create different groups in user management or setup the phonebook (depreciated module, but it is still there and easy to use) with the name (group1, group2, etc.)

Create a dynamic route that looks up the calling number and compares to the right group and number and returns a true or false to the dynamic route. Make the true (matches) go to once experience, and false (no match) moves forward.

This can get tricky, but you can ask specific questions here if you have any.

Dynamic Routes Module - PBX GUI - Sangoma Documentation (atlassian.net)

Implementing different blacklists for each queue in a FreePBX environment involves a more nuanced approach, as FreePBX manages Asterisk configurations through its GUI and automatically generates dialplan configurations. Direct modifications to the dialplan files may be overwritten by FreePBX upon reloads or configuration changes. However, you can achieve the desired functionality by using the Custom Contexts module (if available for your version of FreePBX) or by carefully integrating custom dialplan code in a way that minimizes conflict with FreePBX’s automated management.

Approach 1: Using Custom Contexts Module

If your FreePBX installation has the Custom Contexts module installed (or if you can install it), this module can help you create custom dialplan contexts that check your blacklists before routing calls to specific queues. This method allows for a more GUI-oriented approach but still requires an understanding of Asterisk dialplan concepts.

  1. Install Custom Contexts Module: Check if the Custom Contexts module is available and install it via the Module Admin section of FreePBX.

  2. Create Custom Context: Use the Custom Contexts module to create a new context that includes your blacklist logic. You’ll refer to external sources or database queries here to check the incoming number against the specific blacklist for each queue.

  3. Assign Contexts to Inbound Routes: Assign your custom context to the inbound route(s) leading to your queues. This ensures that calls passing through the route are checked against your blacklist before proceeding to the queue.

Approach 2: Custom Dialplan Integration

For a more flexible and powerful solution, you can integrate custom dialplan code. This requires manually editing configuration files, which is not the recommended FreePBX approach but is sometimes necessary for advanced customization.

  1. Identify Custom Configuration Files: FreePBX allows for custom dialplan integrations via files named extensions_custom.conf for dialplan customizations and pjsip_custom.conf or sip_custom.conf for SIP settings, depending on your channel driver.

  2. Add Custom Dialplan Logic:

  • You will write custom dialplan logic similar to this:

This example assumes you’re using the AstDB to store your blacklists, where blacklist is the family, QUEUE_ID is a unique identifier for each queue (you have to set this up based on your queue), and ${CALLERID(num)} is the caller’s number. You’ll need to adjust your_queue_identifier and your_queue_name accordingly.

exten => _X.,1,NoOp(Checking blacklist for the queue)
 same => n,Set(QUEUE_ID=your_queue_identifier) ; Set your queue identifier here
 same => n,GotoIf(${DB_EXISTS(blacklist/${QUEUE_ID}/${CALLERID(num)})}?blacklisted:continue)

 same => n(blacklisted),Playback(number-not-allowed) ; Or handle as needed
 same => n,Hangup()

 same => n(continue),NoOp(Number not blacklisted, continue to queue)
 ; Continue with your queue logic here
 same => n,Queue(your_queue_name,options)

but you’ll place this code in extensions_custom.conf.

  • Use the [from-internal-custom] context for custom dialplan code, or create a new context and include it from the appropriate context used by your queues.
  1. Implement Database or File-based Blacklists:
  • Decide on how to store your blacklists. For database-driven approaches, you may need to use AGI scripts or FuncODBC to query your database.
  • Populate your blacklists accordingly.
  1. Route Calls Through Your Custom Context:
  • This might be the trickiest part, as you’ll need to ensure that calls destined for your queues first pass through your custom context for the blacklist check. This could involve modifying the context of inbound routes or trunks in their configuration files (pjsip_custom.conf or sip_custom.conf).

Instead of going ODBC/AGI, you might do it in the dialplan by calling an external web app - that is maybe easier to manage. This is feasible, see e.g. the dialplan here VIP Callers | QueueMetrics Blog (ATM QueueMetrics does not support blacklisting per queue, so it’s just an example, though I hgues you could use the “affinity” field for checking).

If you’re going to regurgitate so-called “AI” content here, you can at least label it as such.

I’ve set up a fresh new install of FreePBX for trying different ways for achieving this. The 1st thing that I want to test is if Custom Context module works well for my case, but I don’t see anywhere how to download it or how to install it.

Googlin it I’ve found this:

1.GitHub repository but I don’t know how to take that to the server GitHub - FreePBX-ContributedModules/customcontexts

  1. Many blogs refer to this URL http://mirror.freepbx.org/modules/release/contributed_modules/customcontexts-2.8.0rc1.1.tgz but it doesn’t take me anywhere

Anyone else know how to can I install this module?

Are you running the distro version of FreePBX.

  • If so go to Admin>Module Admin
  • Check unsupported and press check online
  • Scroll down to the Connectivity section
  • Custom Context should be the top item

FYI, my two cents, I would just make a custom destination and edit the config files if you were going this route.

So I made this a while back which basically posts all channel variables to a url…

You can put something like this inline on the dialplan. Remove the post bit and add logic to blacklist. If the caller is good continue in dialplan. Otherwise something like…

      const playback = ari.Playback();
      channel.play({ media: 'sound:tt-monkeys' }, playback)
        .then(() => channel.hangup())
        .catch(error => console.error('Error playing sound or hanging up:', error));

First of all, thanks all for your answers. Here is how I achieved to do this, in case someone need this:


vacio="`ls -lrt  /var/lib/asterisk/blacklist/ | wc -l`"

if [ "$vacio" != "1" ]; then

    if [ "$1" == "" ]; then

        echo "Sin argumento de entrada" >> /var/log/asterisk/log_blacklist_SERVICE1

		IsBlackListed="`grep $1 /var/lib/asterisk/blacklist/SERVICE1`"

		if [ "$IsBlackListed" != "" ]; then

			echo "LLAMADA BLOQUEADA: " $1 >> /var/log/asterisk/log_blacklist_SERVICE1


    echo "FICHERO VACIO" >> /var/log/asterisk/log_blacklist_SERVICE1

echo -e "SET VARIABLE answer $VALUE"
export answer=$VALUE

I stored this script here /var/lib/asterisk/agi-bin/blacklist_SERVICE.sh

You have to put a list of numbers to block in files like this one



Give script permissions to execute:

chmod +x /var/lib/asterisk/agi-bin/blacklist_SERVICE.sh

If you have generated the script in Windows, you will need to reformat it with this command:

dos2unix /var/lib/asterisk/agi-bin/blacklist_SERVICE.sh

In order to execute the script each time that a call hits a queue, I overrided Freepbx dialplan config using /etc/asterisk/extensions_override_freepbx.conf

This is the default config for a queue in /etc/asterisk/extensions_additional.conf


include => ext-queues-custom

exten => 100,1,Macro(user-callerid,)

exten => 100,n,Answer

exten => 100,n,Macro(blkvm-set,reset)

So in /etc/asterisk/extensions_override_freepbx.conf you need to put this in order to execute the script and if the answer of it is equal to 0, go to “gotodest” which is the last command for a queue in the context:

exten => 100,3,agi(/var/lib/asterisk/agi-bin/blacklist_SERVICE1.sh,${CALLERID(num)})
exten => 100,4,Gotoif($[“${answer}”=“0”]?gotodest)

Then, enter to asterisk cli

asterisk -rvvv

And make a reload of the dialplan

dialplan reload

Hope that this can help someone


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