Sydney Staff SRE or something.

Asterisk – Using CallerID to make decisions

· by Robert Mibus · Read in about 2 min · (340 Words)
asterisk sysadmin voip

CallerID information is carried along quite readily within the SIP protocol; most SIP providers pass that along to their customers for free. Other than just showing it as “This is the number the call is coming from”, can we do something more useful?


As an example, imagine the contexts incoming (where calls go to when they come in to Asterisk from a SIP provider) and outgoing (which allows outbound calls from internal phones). There’s also an internal context to allow calls between internal phones.

exten => s,1,WaitForExten

;Internal extensions
exten => 1000,1,Dial(SIP/alice)
exten => 1001,1,Dial(SIP/bob)
exten => 1002,1,Dial(SIP/charlie)
exten => 1003,1,Dial(SIP/jack)

include => internal
;External calls
exten => _XX.,1,Dial(SIP/${EXTEN}@voipprovider)

; Incoming calls go to Alice, our receptionist
exten => s,1,Dial(SIP/alice)

Let’s add in an override for when an employee rings in from their mobile phone - instead of having to talk to Alice, they get put back into the internal context, so they get to directly dial an extension.

Within the incoming context, add:

exten => s/0491570156,1,Playback(please-enter-the)
exten => s/0491570156,n,Playback(number)
exten => s/0491570156,n,Goto(internal)

We can make it a bit better yet. Let’s allow another employee’s mobile phone in, and let’s share the config by moving them to a different context. We can also reuse parts of the dialplan in the new context by only using the CallerID information to override the first part of the sequence.

exten => s/0491570156,1,Goto(employeemobiles)
exten => s/0491570157,1,Goto(employeemobiles)
exten => s/0491570158,1,Goto(employeemobiles)
exten => s/0491570156,1,Set(CDR(accountcode)=alice)
exten => s/0491570157,1,Set(CDR(accountcode)=bob)
exten => s/0491570158,1,Set(CDR(accountcode)=charlie)
exten => s,2,Background(please-enter-the)
exten => s,3,Background(number)
exten => s,4,WaitForExten
include => internal

Note the accountcode being set - this way, you can readily choose to allow outgoing calls from your PABX for remote employees - and it all gets tracked separately (per employee) in your call data records.

You can also just as easily use include => outgoing so that calls in from the mobiles can make calls back out to any other number (eg. if you have great international rates from your PABX, or free calls to certain numbers).