Macro-dialout-trunk-predial-hook and PJSIP

Hi guys,

I need a specific Contact Header to be sent with every INVITE using PJsip. The problem I have is that the “Contact User” field pjsip has, only gets used for the registration and not INVITEs.

The Contact header I need is:

<sip:71234567;tgrp=71234567;[email protected]:5060;transport=udp>

Here’s what I added to extensions_override_freepbx.conf:

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(Updating Contact Header)
exten => s,n,Set(PJSIP_HEADER(update,Contact)=<sip:71234567\;tgrp=71234567\;[email protected]:5060\;transport=udp>)
exten => s,n(done),MacroExit()

I’m using the PJSIP_HEADER function documented here: https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Function_PJSIP_HEADER
The backslashes are to deal with the asterisk config parser to include the semi-colons.

The result is the following:

    -- Executing [s@macro-dialout-trunk-predial-hook:1] NoOp("Local/023456789@from-internal-00000022;2", "Updating Contact Header") in new stack
    -- Executing [s@macro-dialout-trunk-predial-hook:2] Set("Local/023456789@from-internal-00000022;2", "PJSIP_HEADER(update,Contact)=<sip:71234567;tgrp=71234567;[email protected]:5060;transport=udp>") in new stack
[2015-10-14 12:48:56] ERROR[13169][C-00000013]: res_pjsip_header_funcs.c:515 func_write_header: This function requires a PJSIP channel.

So, it looks like it’s trying, but it’s not finding a PJSIP channel. Is there something else I need to reference? I figured it would create the channel before it gets to this point in the FPBX dial-plan?

Thanks again for any help.

I just noticed this Note on the Asterisk Wiki:

To operate on the callee’s (outgoing) channel call PJSIP_HEADER in a pre-dial handler.
Example:

Note: I’ve edited this to reflect what it means in the FPBX dial-plan.

;
[macro-dialout-trunk-predial-hook]
exten => addheader,1,Set(PJSIP_HEADER(add,X-MyHeader)=myvalue)
exten => addheader,2,Set(PJSIP_HEADER(add,X-MyHeader2)=myvalue2)
;
[somecontext]
exten => 1,1,Dial(PJSIP/${EXTEN},,b(macro-dialout-trunk-predial-hook^addheader^1))
;

The standard FPBX dialplan calls the Dial in step 23 of [macro-dialout-trunk] and looks like:

exten => s,n,Dial(${OUT_${DIAL_TRUNK}}/${OUTNUM}${OUT_${DIAL_TRUNK}_SUFFIX},${TRUNK_RING_TIMER},${DIAL_TRUNK_OPTIONS})

So, to hook b(macro-dialout-trunk-predial-hook^addheader^1) into that Dial call, would I have to play within the ${DIAL_TRUNK_OPTIONS} variable? Or would it be safe to just add it at the end separated with a comma? Obviously within extension_custom.conf.

Sorry if this is becoming long in the tooth, but I feel it’s worthwhile documenting my pjsip journey. Hopefully it’ll help people as they start migrating to pjsip.

Quick update on this:

To call PJSIP_HEADER properly, you should add it in its own context, then call it within the Asterisk Trunk Dial Options field in FPBX.

I added the following in extensions_custom.conf

[lets-modify-contact]
exten => modheader,1,Set(PJSIP_HEADER(update,Contact)=<sip:73333333\;tgrp=73333333\;[email protected]:5065\;transport=udp>)
same => n,Return()

Then the following in Asterisk Trunk Dial Options within FPBX:

Ttb(lets-modify-contact^modheader^1)

This is how you would add and modify custom headers… It works, just not in my case, since Asterisk as a whole relies on the Contact Header too much, even with pjsip.

Can anyone recommend a good SBC I can use that works well with Asterisk to play as an interworking function here?