Complex CID prefix

I’ve been tasked with doing CID prefixes based on US area codes.

Thankfully, it’s a subset of the NANP, but it’s still enough that I’m seeking alternatives to plugging them in the web interface, maybe something at the dial plan level in extensions_custom.conf or similar.

An example of what I need to do:

Prefix the CID with STL: for the area codes: 314, 636, 573, 618 and 217
Prefix the CID with KC: for the area codes: 816, 660, 975, 417, 913, 785, 620 and 316

There are more (30 area codes total,) but I’ll just leave it at that for now.

Now, I know I can just go in and create an inbound route to tag these, but there are 30 at the start, and I’m sure more will be added. I really don’t want to have to do this in the GUI, especially considering that I have to do it for three DIDs, so right off the bat I’ll be doing 90 inbound routes. Not a pleasant prospect.

Any ideas?

I’ve sort of figured this out. I created one, then copied the code it created from and copied it into extensions_custom.conf:

exten => 6689/_314XXXXXXX,1,Set(__FROM_DID=${EXTEN})
exten => 6689/_314XXXXXXX,n,Gosub(app-blacklist-check,s,1)
exten => 6689/_314XXXXXXX,n,GotoIf($[ “${CALLERID(name)}” != “” ] ?cidok)
exten => 6689/_314XXXXXXX,n,Set(CALLERID(name)=${CALLERID(num)})
exten => 6689/_314XXXXXXX,n(cidok),Noop(CallerID is ${CALLERID(all)})
exten => 6689/_314XXXXXXX,n,Set(_RGPREFIX=STL:)
exten => 6689/_314XXXXXXX,n,Set(CALLERID(name)=${RGPREFIX}${CALLERID(name)})
exten => 6689/_314XXXXXXX,n,Goto(timeconditions,1,1)

However, if a generic DID for 6689 exists in extensions_additional.conf, it matches that first. I’m not holding out much hope, but is there a way to override that behavior?

Ok, you can’t override, all you can really do is copy all of the inbound routes to the _custom config file.

Here’s what I did, maybe it’ll help someone in the future. I wrote a perl script to make these en masse, it just writes to standard output. Capture the stdout and shove it in a file, then put it in extension_custom.con in the ext-did-custom context.

Here’s the script:

# used for mass creation of inbound routes, meant for inclusion in the
# [ext-did-custom] context in extensions_custom.conf
# Written by Jason "KodaK" Balicki, April 10th, 2008
# [email protected]

use strict;
use warnings;
use Text::CSV;
use Switch;

# csv file format is:
# did,prefix,areacode,routedest
my $file = 'routelist.csv';
# create the csv instance
my $csv = Text::CSV->new();

open (CSV, "<", $file) or die $!;

while (<CSV>) {
        if ($csv->parse($_)) {
                # columns should be obvious
                my @columns = $csv->fields();
                my $did = $columns[0];
                my $prefix = $columns[1];
                my $areacode = $columns[2];
                my $routedest = $columns[3];
                # $confdest is the destination in the format required
                # by the config files
                my $confdest='timeconditions,1,1';
                # These are my local time condition names, you may have to change
                # up this section to suit your requirements
                # ORDER MATTERS HERE.  Since I'm just doing pattern matching,
                # perl will match the WeekdayCalls in KCWeekdayCalls, so my
                # quick and dirty solution is to match KCWeekdayCalls first.
                # You may want to put some more thought into this.

                switch ($routedest) {
                        case /KCWeekdayCalls/ { $confdest='timeconditions,3,1' }
                        case /WeekdayCalls/ { $confdest='timeconditions,1,1' }
                # yeah, yeah, I know I can use EOF, but I started it this way, shut up
                print "exten => " . $did . "\/_" . $areacode . "XXXXXXX,1,Set(__FROM_DID=\${EXTEN})\n";
                print "exten => " . $did . "\/_" . $areacode . "XXXXXXX,n,Gosub(app-blacklist-check,s,1)\n";
                print "exten => " . $did . "\/_" . $areacode . "XXXXXXX,n,GotoIf(\$[ \"\${CALLERID(name)}\" != \"\" ] ?cidok)\n";
                print "exten => " . $did . "\/_" . $areacode . "XXXXXXX,n,Set(CALLERID(name)=\${CALLERID(num)})\n";
                print "exten => " . $did . "\/_" . $areacode . "XXXXXXX,n(cidok),Noop(CallerID is \${CALLERID(all)})\n";
                print "exten => " . $did . "\/_" . $areacode . "XXXXXXX,n,Set(_RGPREFIX=" . $prefix . ":)\n";
                print "exten => " . $did . "\/_" . $areacode . "XXXXXXX,n,Set(CALLERID(name)=\${RGPREFIX}\${CALLERID(name)})\n";
                print "exten => " . $did . "\/_" . $areacode . "XXXXXXX,n,Goto(" . $confdest . ")\n";

Yes, it’s quick and dirty.

CSV format is:


So, example:


Things I could do better: put in some logic to make just DID routes or just CID routes easier.

Hope this helps someone.