IVR Challenge

Has anyone ever used an ivr like this?

call comes in... welcome to our company... blah blah press 2 for customer service
press 1 for so and so..
2 for someone else
if you don't know your rep press 9
the ivr will look at the CID to determine the area code of the caller then send to the correct extension?

I'm not that great with conf files, so I would prefer a gui solution... if conf files is the only way. Need detail instructions....


Give us some more details. How many reps are there? Are you planning on tying every area code to a particular rep? There is not an easy (simple and fast) way to do this in the GUI. But depending on the scale of the project, you might be able to make something like this work using just the GUI. However, you are more than likely going to need to build a custom dial plan that will analyze the phone number and direct it to the proper rep. You could then point 9 in your IVR to this custom dial plan. I’ve never built a custom dial plan so I’m not sure how hard it would be to create what you are asking.

5 reps, yes, each rep has certain States of the US. I have all the area codes in a list, just not sure how to do it… I’ve never done any custom dial plans either… most of my work has been in the gui, or with detailed shell instructions. Thanks for replying, really thought this wouldn’t be that hard… sounded pretty easy in my head… :frowning:

@chasemixon We have looked at building this type of module before for your type of organization, if you open up a sales ticket in the portal or at support.schmoozecom.com I can put together a quote for custom development. Ideally you would want to provide us with a full scope of work… for example you would likely want it pretty easy to manage the area codes assigned to the reps, and to transition those easily when needed. The more specifics you provide the better we can define any potential project.

If you have to have it based off the area code then you should probably let schmooze do it for you. However with only 5 reps, when they press nine take it to another IVR that says if you live in these states press 1, these states press 2, so on and send each number to the correct rep. If you must have it based off the area code, then you could create an IVR for each rep. It would be the same IVR just labeled different and 9 in the first IVR would go to rep 1, 9 in the second IVR would go to rep 2. You will have a total of 5 IVR’s. Then use inbound routes and create a route with CID priority for each area code and direct it to the proper IVR. This would take forever, but will work using just the GUI. Also, depending on how the area codes are laid out for each rep, you may not have to have an inbound route for every single area code, as you might be able to use character matching if a certain rep has a bunch of similar area codes.

reconwireless, thank for the info, at this point it is just a nicety, I was hoping I could do. not a requirement… If it becomes a requirement, I will definetly send you guys a message, we are already using your Fax solution, you guys do really good work. Very impressed!

jermsmingy, interesting, no it doesn’t have to use area code, I would just trying to keep the caller from having to enter anymore info. thought it would be an easy thing to just send the call to an inbound route and let it determine the extension to send the caller.

Yeah, you can definitely do the area code routing in the gui with inbound routes… won’t be fun, or a short process, but can be done. What the last guy looking for this was wanting was a gui to easily manage which area codes were assigned to each destination (or rep) and easily manage them via drag and drop… we can assist if needed with this, but would take some funds to support the custom development.

Just for poops and giggles what is the ballpark of funds? couple hundred, couple thousand? just ballpark, not going to hold you to a number. but in case I need to pitch it to upper management?

Under $1,000,000,000 and over $1…

That was good!

@chasemixon I sent you a PM with some details from the last similar project, I don’t share custom development pricing online.

To put this in perspective, I had to develop a plan to allow calls from specific area codes to go to live ring groups, and all other calls to go to an IVR. There were 9 DID’s and 7 area codes, so a total of 63 inbound routes, plus another 9 to cover the “out-of-area” calls. If you are trying to do the whole country, you can imagine the extent of the job. I don’t know how many DID’s you have but it’s one route for each combination of area code/DID.

For a couple of minutes of my time and to deconstruct your request, maybe 9 goes to :-

exten => s,1,set (AC=${CALLERID(number):0:3)
exten => s,n,goto(${AC},1)
exten => 212,1,dial(local/1234,m)
exten => 213,1,dial(local/1235,m)

Not so easy to manage , right? so

exten => s,1,set (AC=${CALLERID(number):0:3)
exten => s,n,goto(${AC},1)
exten => 212,1,goto(newyork,1)
exten => 213,1,goto(california,1)
exten => newyork,1,dial(local/1234,m)
exten => california,1,dial(local/1235,m)

But that will be not easily managed either, so

exten => s,1,set (AC=${CALLERID(number):0:3)
exten => s,n,goto(${AC},1)
exten => 212,1,goto(newyork,1)
exten => 213,1,goto(california,1)
exten => newyork,1,goto(nyrep,1)
exten => california,1,goto(carep,1)
exten => nyrep,1,dial(local/1234,m)
exten => carep,1,dial(local/1235,m)

Still not really pretty, so how about you seed the astdb appropriately with lots of

rasterisk -x 'database put AC 212 1234’
rasterisk -x ‘database put AC 213 1235’

(or use sqlite3 appropriately)

and then you just need for every call with a valid 10 digit CALLERID(number).

exten => s,1,set(AC=${CALLERID(number):0:3)
exten => s,n,Set(REP=${DB(AC/${AC})})
exten => s,n,dial(local/${REP},m)

A couple of caveates, That would generally work in NANP land for toll free calls from landlines, but if the callerid(number) arrives with possiby “UNKNOWN”, “NOT KNOWN”, “ANONYMOUS” or “WITHHELD” etc. or the call is from an out of state cellphone physically in your areacode of concern you will need to cover that , I almost certainly have typos in there, perhaps even gross errors, but I hope you follow the logic.

Wow, thanks for the replies! RChalk, that’s kind of where I ended up… to massive for this first timer with asterisk.

Dicko, that last one looks very interesting, but as I stated, I’m a first timer on asterisk… and though I follow the logic, I’m no where close to being in the same ballpark as you! if you don’t mind mentoring me a little. ok a lot! I would really like to pick your brain about the solution… if you can get me started, I’m sure I could get it working. when I say get me started, I mean explain how to get one state’s area codes into the the file you are referencing… and help me get the IVR to that file… like I said… I downloaded asteriskNow and entered enough info in to get it working… not a lot of nano skills!

I would recommend some time with a bash tutorial or two, there is a lot more than nano, but it all fits together very well. As to AreaCodes for NANP the base source of info is at


and with a LOT of digging you will find a list buried in there somewhere, I would however recommend the list that a guy at


scrapes a living by publishing the latest of at very reasonable prices (info that which was once considered public information but officially on sale for a few hundred dollars or free if you can track it down, go figure). You can download from him in several formats so you can massage it with the software of your choice.

This guy doesn’t provide a license on the repo so not sure if it is “ok” to use this

There is also:


this will give back some useful data

        status: "success",
        error_message: "",
        area_codes: [
                        area_code: "601",
                        state: "MS",
                        timezone: "Central",
                        current_time: "11:38am"

Then you could route by time zone. This takes 50 states to 9 zones.

Another data source:


hmmm, I need to stick with states, since that’s how our reps are broken up, timezones wouldn’t be very helpful… although it is cool… can someone get me started though like how you would implement this?
remember I need specifics like in the extensions_custom.conf put
{context bucket} for each state…

explain the exten lines…

exten => s,1,set(AC=${CALLERID(number):0:3)
to me this looks like AC will be equal to the Area Code in the phone number…

exten => s,n,Set(REP=${DB(AC/${AC})})
this looks like REP will to something the area code does…???

exten => s,n,dial(local/${REP},m)
this is dialing the correct REP…???

Well, I will defer you as many here would to:-


It is as the Title page states"Asterisk™: The Definitive Guide" you will find things like substring manipulation the first of your demands, the asterisk database usage , the second of your demands and basic dialing syntax , the third of your demands are all covered. As to specifics, respectfully this is a forum where many folks (some friendly :slight_smile: ) can and will point you in the right direction, however many of those who will answer also make a living out of what you specifically demand for free.

You obviously have a money making venture , I suggest you either spend some of your time productively RTFM or spend some of that money getting processional consultancy, there are links to that in the "support " tab at the top of this page where you will no doubt re-meet reconwireless and jfinstrom, this time with checkbook in hand :slight_smile: .

As I have suggested in another post EVERYTHING DOESN’T NEED TO BE IN THE DIAL PLAN

I would recommend looking at the use of AGI.

The one block above was in JSON which is a standard data format supported in most languages. This type of task can easily be done with a flat file rather than a database.

Let the AGI do all the magic. You can write it any way you want in whatever language you are comfortable with

OK, I will offer this as a solid starting point, no AGI or JSON needed just human readable flat files and the native sqlite3 database included in every asterisk, it’s faster and more streamlined but very easy to modify ( I don’t know whether SHMZOS has an sqlite3 client or what it is called so maybe the yum bit is wrong :slight_smile: however . . .

mkdir -p  /usr/src/nanp
cd /usr/src/nanp
if [ ! -f  allutlzd.zip ];then wget http://www.nanpa.com/nanp1/allutlzd.zip;unzip allutlzd.zip;fi
if !  which sqlite3 > /dev/null ;then apt-get install sqlite3||yum install sqlite3;fi
SQLITE3=$(which sqlite3)
cat allutlzd.txt | awk 'BEGIN { FS = "\t" } ; { print "/NPA/"substr($2,1,3)"|"$1 }'|tail -n +2| sort -u > import.txt
#this next line could be usefully used for for calls with no useful CALLERID(name)
cat allutlzd.txt | awk 'BEGIN { FS = "\t" } ; { print "/NPANXX/"substr($2,1,3)substr($2,5,3)"|"$5$1 }'|tail -n +2| sort -u >> import.txt
#Traditional Regions mapped later to REP but feel free to edit these to suit 
#currently bash doesn't support arrays of arrays so
for REP in ${CENTRALNORTH[@]};do echo "/STATEREP/$REP|1234"; done >> import.txt 
for REP in ${CENTRALSOUTH[@]};do echo "/STATEREP/$REP|1235"; done >> import.txt
for REP in ${EASTERNNORTH[@]};do echo "/STATEREP/$REP|1236"; done >> import.txt
for REP in ${EASTERNSOUTH[@]};do echo "/STATEREP/$REP|1237"; done >> import.txt
for REP in ${WESTERNNORTH[@]};do echo "/STATEREP/$REP|1238"; done >> import.txt
for REP in ${WESTERNSOUTH[@]};do echo "/STATEREP/$REP|1239"; done >> import.txt
for REP in ${ATLANTIC[@]};do echo "/STATEREP/$REP|1240"; done >> import.txt
for REP in ${PACIFIC[@]};do echo "/STATEREP/$REP|1240"; done >> import.txt
rasterisk -x 'core stop when convenient'
${SQLITE3} /var/lib/asterisk/astdb.sqlite3 "delete from astdb where key like '/STATEREP%'"
${SQLITE3} /var/lib/asterisk/astdb.sqlite3 "delete from astdb where key like '/NPA%'"
${SQLITE3} /var/lib/asterisk/astdb.sqlite3 '.import import.txt astdb'
service asterisk start > /dev/null

echo -e "\acheck your work by typing . . .\n\n\nrasterisk -x 'database show'\n\a"
exit 0