PJSIP_HEADER add diversion

We are testing with a new sip trunk provider and decided to test with asterisk 13. Everything seems to be working as should be except for call forwarding. I’m trying out PJSIP which has been challenging to say the least but the provider requires us to add a diversion header as they only allow their DID’s. I’ve been trying (and trying) to get PJSIP_HEADER to work doing the following:

exten => s,n,Dial(PJSIP/${ARG1}@provider,30,tb(header-modify^modheader^1))

exten => modheader,1,Set(PJSIP_HEADER(add,Diversion)=sip:9252020203@masergy;privacy=off;screen=no;reason=unconditional)

When I look at the SIP messages I see a diversion header but it’s not this above that I’m trying to change. It’s the original 4 digit extension and SIP endpoint the call comes in on but seems to continue to be passed during the call forward.

Any ideas?

Your Diversion header is malformed, as the URI part is mandatory. In fact having screening and privacy status on missing URI makes no sense.

However your real problem is that you are trying to override a system provided header. What you probably really want is described in https://wiki.asterisk.org/wiki/display/AST/Manipulating+Party+ID+Information#ManipulatingPartyIDInformation-REDIRECTINGdialplanfunction

I must have copied the wrong example. Here’s a couple different examples I tried. I’ve changed the number to protect the innocent.

exten => modheader,1,Set(PJSIP_HEADER(add,Diversion)=sip:1234567890\;tgrp=1234567890\;trunkcontext=masergy\;privacy=off\;reason=unconditional)

exten => modheader,1,Set(PJSIP_HEADER(add,Diversion)=sip:1234567890@masergy;privacy=off;screen=no;reason=unconditional)

Is there a reason not to use a diversion header? Prior versions of asterisk used sipaddheader so I’m assuming the same for PJSIP is to use the PJSIP_HEADER?

I’ll take a look at the link you provided.

Hmmm looks like what I’m posting is changed once I submit it. I’m assuming the website doesn’t like something with the formatting.

The reason not to add a diversion header is that one will be added automatically. Add header functions are basically there for non-standard or unsupported headers. Diversion headers weren’t supported in early versions of Asterisk.

You will probably need to use preformat </> mode to get the angle bracketted text through the forum software.

exten => modheader,1,Set(PJSIP_HEADER(update,Contact)=<sip:1234567890\;tgrp=1234567890\;trunkcontext=isp\;privacy=off\;reason=unconditional>)

exten => modheader,1,Set(PJSIP_HEADER(add,Diversion)=<sip:1234567890\;tgrp=1234567890\;trunkcontext=isp\;privacy=off\;reason=unconditional>)

exten => modheader,1,Set(PJSIP_HEADER(add,Diversion)=<sip:1234567890@isp>\;privacy=off\;screen=no\;reason=unconditional)