Routing inbound calls based on CID Lookup Source

Ok, I found it.

I need to create a custom destination. Here’s what I did:

Edit the file /etc/asterisk/extensions_custom.conf

Add the following:

[custom-split-sales-support]

exten => s,1,GotoIf($["${CALLERID(name):0:3}" = “Sup”]?ext-queues,700,1)
exten => s,n,GotoIf($["${CALLERID(name):0:10}" = “Sales:Cust”]?ext-queues,700,1)
exten => s,n,Goto(ext-group,600,1)

Now in the web admin go to admin -> custom destination.

Add a destination called custom-split-sales-support,s,1 and give it a name.

Go to your upstream module, might be the inbound route or in my case it is a time condition. Set the destination to custom destination and pick the destination name you just created.

A bit of explanation.

On my system there are two inbound routes for my two telephone numbers. They both have a custom cid lookup which is an https call to our crm system. The prepends either Cust: or New: to the caller id. Then the inbound route prepends Sales: or Sup: to the caller id. So calls end out looking like:

Sup:New:12345444 (a call to the support number from a number that’s not in crm)
Sales:Cust:13344343 (a call to the sales line from a customer)

I want to route calls from unknown numbers to the sales team to a specific call group (ring everyone, there’s money on the phone!) and calls to the support line or from customers to the sales line to the queue (they can wait).

In my setup the ring group is extension 600 and my queue is extension 700. So going back to the magic in the file. This is a dial plan, which is essential what freepbx creates for asterisk and having looked at it a bit I really love freepbx.

Line by line:

[custom-split-sales-support]

This is the context which is how asterisk and freepbx label this set of rules.

exten => s,1,GotoIf($["${CALLERID(name):0:3}" = “Sup”]?ext-queues,700,1)

exten => is just a standard part of the asterisk syntax
I’m not sure what the s is. I think it just means this isn’t a feature code or an extension you can dial.
The 1 means this is the first rule.
GotoIf says the if the part before the ? is true, then goto the part after the ?
$["${CALLERID(name):0:3}" = “Sup” means look at the name part of the caller id (I had it as num before which didn’t work), from the 0th character to the 3rd character (or it might be 3 characters) and see if it matches Sup, which mean that it is a call that came in on the support line. If it matches send it to the context ext-queues, extension 700, step number 1.

exten => s,n,GotoIf($["${CALLERID(name):0:10}" = “Sales:Cust”]?ext-queues,700,1)

Same as above mostly. The n says this is the next step, could have put in 2 as well. The gotoif now says look at 10 characters, if they match Sales:Cust (ie a customer who has called the sales line), send them to the queue.

exten => s,n,Goto(ext-group,600,1)

This last line says send everyone who got this far without being matched should be send to the ring group, extension 600, step 1.

Hope that helps someone out there.

2 Likes