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:

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

I’m using the PJSIP_HEADER function documented here:
The backslashes are to deal with the asterisk config parser to include the semi-colons.

The result is the following:

    -- Executing [[email protected]:1] NoOp("Local/[email protected];2", "Updating Contact Header") in new stack
    -- Executing [[email protected]:2] Set("Local/[email protected];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.

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

exten => addheader,1,Set(PJSIP_HEADER(add,X-MyHeader)=myvalue)
exten => addheader,2,Set(PJSIP_HEADER(add,X-MyHeader2)=myvalue2)
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:


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

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:


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?