SIP Diversion Headers

Hi,

I’ve done SIP trunking with a few different LECs that seem to agree on how and when they’d like to see diversion headers from me. It is important to avoid using the header if it isn’t needed. Maybe. If you ever look at your phone bills to see who’s calling the most or do any useful investigation on abuse you will not want to user the diversion header unless absolutely necessary.

To keep the example as honest and clean as possible yet not publish our real info, only the NXX’s have been updated. Here is my current dialplan context as found in extensions_custom.conf:

[macro-dialout-trunk-predial-hook]
; is sip trunk? yes , goto checkcid
exten => s,1,Set(CDR(accountcode)=${CALLERID(num):-4:4})
exten => s,n,NoOp(DIAL_TRUNK = ${DIAL_TRUNK} and EXTEN = ${EXTEN})
exten => s,n,Set(TRACKTR=${OUT_${DIAL_TRUNK}:4})
exten => s,n,NoOp(TRACKTR = ${TRACKTR})
exten => s,n,SIPAddHeader(X-Unique-ID: ${UNIQUEID})
exten => s,n,GotoIf($["${TRACKTR}" = “6120009673”]?checkcid) ; LEC, trunk id 1
; trunk isn’t a SIP trunk, nothing more to do here
exten => s,n,Goto(s,done)
; We are on a SIP trunk, so let’s look closer
; is callerid local?
exten => s,n(checkcid),Set(TRCID=${CALLERID(num)})
; the next block are legit after everyone’s numbers are moved to SIP
exten => s,n,GotoIf($[$[${TRCID} >= 6121111400] & $[${TRCID} <= 6121111499]]?done) ; Company block 1 (100)
exten => s,n,GotoIf($[$[${TRCID} >= 6121112600] & $[${TRCID} <= 6121112799]]?done) ; Company block 2 (200)
exten => s,n,GotoIf($[$[${TRCID} >= 6121113798] & $[${TRCID} <= 6121113997]]?done) ; Company block 3 (100)
exten => s,n,GotoIf($[$[${TRCID} >= 6120004301] & $[${TRCID} <= 6120004387]]?done) ; Company block 4 (87)
exten => s,n,GotoIf($[$[${TRCID} >= 5131118700] & $[${TRCID} <= 5131118739]]?done) ; Acquisition block 1 (40)
exten => s,n,GotoIf($[$[${TRCID} >= 5131118820] & $[${TRCID} <= 5131118899]]?done) ; Acquisition block 2 (80)
; end of block
; singlets
exten => s,n,GotoIf($[${TRCID} = 6519993300]?done) ; old company number (1)
exten => s,n,GotoIf($[${TRCID} = 6518883700]?done) ; old company FAX (1)
exten => s,n,GotoIf($[${TRCID} = 5137778888]?done) ; Acquisition Main Number
; add sip header goto done
; Enventis
exten => s,n(addheader),SIPAddHeader(Diversion: sip:[email protected];reason=unconditional;screen=no;privacy=off)
; McLeod // Paetec // Windstream
;exten => s,n(addheader),SIPAddHeader(Diversion: sip:${TRACKTR}@bwas4.global.voip.mcleodusa.net;reason=unconditional;screen=no;privacy=off)
exten => s,n,NoOp(Call from ${TRCID} on trunk ${TRACKTR})
exten => s,n(done),MacroExit()

Calls that need a diversion header will be billed to 6519993300 in my example above.

  • – I give bonus points to whomever can rewrite this to actually update the billing call number as the extension that’s forwarding or follow-me’ing the call.