Account codes via trunks

Ok this is going to be long winded, but I solved it. Someone gave me a hint when they said to insert into the sip header as a custom header. I already insert P-Asserted Identity so I had a little experience in this.

First you have to add a pre-dial hook in extensions_custom, here is mine:

[macro-dialout-trunk-predial-hook]

exten => s,1,GotoIf($["${custom}" = “SIP/ssi2”]?A2)
exten => s,n,MacroExit()
exten => s,n(A2),Noop(A2 Account Code Added)
exten => s,n,SIPAddHeader(X-Accountcode:${CDR(accountcode)})
exten => s,n,MacroExit()

In this example my trunk name to the A2 box is “ssi2”. So the macro idientifies the trunk and then inserts the account code into a custom sip header: X-Accountcode.

On the A2 machine the call is received under the context from-internal. To make things fir into freepbx, I picked a macro that would normally be called, in this case [macro-user-caller-id]. I copied it into freepbx_extensions_overides, with the first two lines modified to insert my account code info:

[macro-user-callerid]
include => macro-user-callerid-custom
exten => s,1,Set(CDR(accountcode)=${SIP_HEADER(X-Accountcode)})
exten => s,n,Noop(********* Account code: ${CDR(accountcode))
exten => s,n,Set(AMPUSER=${IF($[“foo${AMPUSER}” = “foo”]?${CALLERID(number)}:${AMPUSER})})
exten => s,n,GotoIf($["${CHANNEL:0:5}" = “Local”]?report)
exten => s,n,ExecIf($["${REALCALLERIDNUM:1:2}" = “”]?Set(REALCALLERIDNUM=${CALLERID(number)}))
exten => s,n,Set(AMPUSER=${DB(DEVICE/${REALCALLERIDNUM}/user)})
exten => s,n,Set(AMPUSERCIDNAME=${DB(AMPUSER/${AMPUSER}/cidname)})
exten => s,n,GotoIf($[“x${AMPUSERCIDNAME:1:2}” = “x”]?report)
exten => s,n,Set(AMPUSERCID=${IF($["${DB_EXISTS(AMPUSER/${AMPUSER}/cidnum)}" = “1”]?${DB_RESULT}:${AMPUSER})})
exten => s,n,Set(CALLERID(all)="${AMPUSERCIDNAME}" <${AMPUSERCID}>)
exten => s,n,ExecIf($["${DB(AMPUSER/${AMPUSER}/language)}" != “”]?Set(CHANNEL(language)=${DB(AMPUSER/${AMPUSER}/language)}))
exten => s,n(report),GotoIf($[ “${ARG1}” = “SKIPTTL” ]?continue)
exten => s,n(report2),Set(__TTL=${IF($[“foo${TTL}” = “foo”]?64:$[ ${TTL} - 1 ])})
exten => s,n,GotoIf($[ ${TTL} > 0 ]?continue)
exten => s,n,Wait(${RINGTIMER})
exten => s,n,Answer
exten => s,n,Wait(2)
exten => s,n,Playback(im-sorry&an-error-has-occured&with&call-forwarding)
exten => s,n,Macro(hangupcall,)
exten => s,n,Congestion(20)
exten => s,n(continue),Set(CALLERID(number)=${CALLERID(number):0:40})
exten => s,n,Set(CALLERID(name)=${CALLERID(name):0:40})
exten => s,n,Noop(Using CallerID ${CALLERID(all)})
exten => h,1,Macro(hangupcall,)

; end of [macro-user-callerid]

Viola! the accountcode variable is now set from the extension that call ed from the remote machine. A2 billing now automatically knows what to do with it, rates, and routes it accordingly.

results:

xecuting [s@macro-user-callerid:1] Set(“SIP/SSI2-00000014”, “CDR(accountcode)=1046910106”) in new stack
– Executing [s@macro-user-callerid:2] NoOp(“SIP/SSI2-00000014”, “********* Account code: 1046910106”) in new stack

I hope that might help someone else out. You could essentially send any variable you wanted, not just the account code.

2 Likes