FreePBX | Register | Issues | Wiki | Portal | Support

Send accountcode via PJSIP Trunk


(Elimin) #1

Hello,

My FreePBX configuration looks something like this:

I would like to send an account code from INT1 / INT2 to GW1 and collect the CDR on GW1.

I found a similar solution, but it does not work for me.
https://community.freepbx.org/t/account-codes-via-trunks/13878/8

I tested something like this on INT1:

[macro-dialout-trunk-predial-hook]
exten => s,1,GotoIf($["${custom}" = “PJSIP/TRUNK-GW1”]?A2)
exten => s,n,MacroExit()
exten => s,1,Noop(A2 Account Code Added)
exten => s,n,Set(PJSIP_HEADER(add,X-Accountcode)=${CDR(accountcode)})
exten => s,n,MacroExit()

But I do not see this header when running “pjsip set logger on”.

I think I’m doing something wrong.
How do I do the test:

[macro-dialout-trunk-predial-hook]
exten => s,1,Noop(A2 Account Code Added)
exten => s,n,Set(PJSIP_HEADER(add,X-Accountcode)=${CDR(accountcode)})
exten => s,n,MacroExit()

I have in the logs:

[2019-07-09 14:43:51] VERBOSE[14765][C-000000d5] pbx.c: Executing [s@macro-dialout-trunk-predial-hook:1] NoOp(“PJSIP/211493205-000001b1”, “A2 Account Code Added”) in new stack
[2019-07-09 14:43:51] VERBOSE[14765][C-000000d5] pbx.c: Executing [s@macro-dialout-trunk-predial-hook:2] Set(“PJSIP/211493205-000001b1”, “PJSIP_HEADER(add,X-Accountcode)=211493205”) in new stack
[2019-07-09 14:43:51] VERBOSE[14765][C-000000d5] pbx.c: Executing [s@macro-dialout-trunk-predial-hook:3] MacroExit(“PJSIP/211493205-000001b1”, “”) in new stack

But I still do not see the header either in “pjsip set logger on” or in tcpdump

Any tips what should I do?


#2

Try replacing
exten => s,n,Set(PJSIP_HEADER(add,X-Accountcode)=${CDR(accountcode)})
with
exten => s,n,Set(HASH(__SIPHEADERS,X-Accountcode)=${CDR(accountcode)})


(Tom Ray) #3

You use the existing function that does this for you.

GoSub(func-set-sipheader,s,1(X-ACCOUNTCODE,${ACCOUNTCODE}))

This is PJSIP which means you have you set the headers for the called channel on that channel. The only way to do that is with the b() option in the Dial() string. FreePBX already uses that b() option to run a GoSub that will apply all the headers set by “func-set-sipheaders” on the called channel for you.


(Lorne Gaetz) #4

Even better is to use the native subroutine for setting the header:

exten => s,n,GoSub(func-set-sipheader,s,1(X-Accountcode,${CDR(accountcode)}))

edit - Tom beat me to it
edit - typo fixed, not tested


(Itzik) #6

Off topic:

Curious why you have a setup like this?
Seems like you only need two servers (if my assumptions are correct). Why do you have 3?


(Elimin) #7

Nothing special.
Each FreePBX is in a different location and is also connected to the Analog PBX via E1.

Thank you for your help @Stewart1 @BlazeStudios @lgaetz