PJSIP - how to send a specific PAI field

Hi.

I’m using a fresh install of Fpbx 17 (PJSIP only).

This newly FPBX will be used to facing different SIP Trunk Providers.
Kind of a proxy node between many others PBXs and our different Providers.

In order to place some outbound calls to one of the providers using multiples FROM caller numbers id, that provider is requesting us to send a specific PAI field.

Now, I tried this good old configuration into extension_custom.conf like this:

[macro-dialout-trunk-predial-hook]
exten => s,1,Noop(Entering user defined context macro-dialout-trunk-predial-hook in extensions_custom.conf)
exten => s,n,ExecIF($["${OUT_${DIAL_TRUNK}_SUFFIX}"!=""]?Set(trunk_name=${OUT_${DIAL_TRUNK}_SUFFIX}):Set(trunk_name=${OUT_${DIAL_TRUNK}}))
exten => s,n,Noop(Trunk Name: ${trunk_name})
exten => s,n,ExecIf($["${trunk_name}"="PJSIP/TO-PROVIDER"]?func-set-sipheader,s,1(P-Asserted-Identity, <sip:[email protected]>))
exten => s,n,Return()

Seems to work only for good old Chan_SIP channels ?
FBPX 17 do nothing with that configuration.

Anyways, I saw that with PJSIP we should used PJSIP_HEADED instead…
So, again into extension custom:

[add-pai-header]
exten => s,1,NoOp(Adding P-Asserted-Identity)
exten => s,n,Set(PJSIP_HEADER(add,P-Asserted-Identity)=<sip:[email protected]>)
exten => s,n,Return()

As per my reading, we should be able to call that macro into the FPBX gui with the Asterisk Trunk Dial Options , with something like this: Ttb(add-pai-header^s^1).

When placing an outbound call, in the asterisk logs I can see the following

Executing [5558889999@trunk-dial-with-exten:1] Dial(“PJSIP/699-000000e6”, “PJSIP/5558889999@provider,300,Ttb(add-pai-header^s^1)b(func-apply-sipheaders^s^1,(1))U(sub-send-obroute-email^5558889999^^1^1732547749^^5558889999,^)”) in new stack

but no PAI field is added to the outbound SIP packets…
I guess that I missed a something somewhere, but I can’t figured out where.

Thanks.

I think that is because you have two b options. There is code in FreePBX, whose name I forget, but should be obvious from looking at the logs, which sets up variables, for use by func-apply-sipheaders. func-apply-sipheaders, tries both the chan_sip and the chan_pjsip0 way.

Make sure you do not enable Asterisk to send PAI automatically, as there could be a conflict.

Your first example is the correct way and also works with PJSIP.
We are using a similar dialplan to add the PIA for two different outgoing SIP trunks. But I am not quiet sure if the ExecIf application on line 5 is the correct way. I am using the GoSubIf appliction instead. Maybe try that.

Hi @joni1802 and @david55

Found it.

As @joni1802 mention, my good old configuration is working with PJSIP and still working into FPBX 17 - asterisk 21.

My issue:

I forget that this macro is placing the trunk name into a variable named trunk_name, and within that variable , the trunk name is using the @trunkname format. I was trying to match trunk_name with “PJSIP/Trunkname” which never match the @trunkname located into the variable trunk_name (too much trunk name here) :slight_smile:

So, here’s my final code:

[macro-dialout-trunk-predial-hook]
exten => s,1,Noop(Entering user defined context macro-dialout-trunk-predial-hook in extensions_custom.conf)
exten => s,n,ExecIF($[“${OUT_${DIAL_TRUNK}SUFFIX}“!=”"]?Set(trunk_name=${OUT${DIAL_TRUNK}SUFFIX}):Set(trunk_name=${OUT${DIAL_TRUNK}}))
exten => s,n,Noop(Trunk Name: ${trunk_name})
exten => s,n,GoSubIf($[”${trunk_name}“=”@provider"]?func-set-sipheader,s,1(P-Asserted-Identity, sip:[email protected]))
exten => s,n,Return()

Where ${trunk_name}“=”@provider" must match what is been output by line #3 showed into asterisk logs (full), while trying to place a call (Trunk name : @provier).

Executing [s@macro-dialout-trunk-predial-hook:3] NoOp(“PJSIP/5001-0000013a”, “Trunk Name: @provider”) in new stack

On a match, func-set-sipheader is been called and working just fine.

Don’t forget that in Asterisk 21, MacroExit hase been deprecated, use Return() instead.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.