I recently had to add diversion header to our sip packets and we are using PJSIP. It took a while to know how to do that since PJSIP is different than SIP and I will post it here in case someone else wants to do this.
We have several trunks and we wanted to add Diversion header for some of our outbound routes ( based on the region ). If you need it at trunk level, dont need to use Execif part , just set the header:
exten =>s,n,Set(PJSIP_HEADER(add,Diversion)=sip:[email protected])
This is how I did it :
vi /etc/asterisk/extensions_override_freepbx.conf
[func-apply-sipheaders]
include => func-apply-sipheaders-custom
exten => s,1,Noop(Applying custom SIP Headers to channel, Outbound Route= ${ROUTENAME})
;Check if call is going out over XX routes, XX_Local_LD_INT is trunk name
exten => s,n,ExecIf($[“${ROUTENAME}” = “XX_Local_LD_INT”]?Set(PJSIP_HEADER(add,Diversion)=sip:[email protected]))
;Check if it call is going out over YY routes, YY_Local_LD_INT is trunk name
exten => s,n,ExecIf($[“${ROUTENAME}” = “YY_Local_LD_INT”]?Set(PJSIP_HEADER(add,Diversion)=sip:[email protected]))
Change the caller id and sip provider ip address as you need.
And on webgui, change your trunk setting as below :
Asterisk Trunk Dial Options = TWtb(func-apply-sipheaders^s^1)
There are cleaner ways of manipulating SIP headers on outgoing trunk calls, and using the override file is to be avoided whenever possible. I recommend you use the native header gosub functions with macro-dialout-trunk-predial-hook
Looks like forum was launched 18 years ago, so there are many that predate me by a year or two. A quick glance in the admin portal shows a quite a few still active.
So you are saying call func-set-sipheader from predial-? And do not change system asterisk trunk dialout option? I will test it thanks. And Happy Cake day…