Setting DIVERSION header using Lua

Hi,
I use PJSIP with Asterisk 20 and Lua. I would like to set DIVERSION header in the outgoing call.

When I am setting the DIVERSION header on the outgoing call for the first time it works as expected.

channel[“PJSIP_HEADER(add,Diversion)”]:set(channel[“diversion”]:get())

VERBOSE[3191238] res_pjsip_logger.c: <— Transmitting SIP request (1258 bytes) to UDP:..185.103:60 —>
INVITE sip:+#########35@server7:60 SIP/2.0
Via: SIP/2.0/UDP ..124.63:60;rport;branch=z9hG4bKPj2cb686ba-7fb3-45e9-9241-f34cdb998848
From: “Asterisk BENCH” sip:+#########53@***.***.124.63;tag=e8e6024d-cf83-457a-8946-a6fd7550eaf9
To: sip:+#########35@server7
Contact: sip:+#########41@***.***.124.63:**60
Call-ID: 19f4a147-bae3-4520-8d8d-11da035dd280
CSeq: 26838 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, INFO, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub, histinfo
Session-Expires: 1800
Min-SE: 90
X-Asterisk-CallID: f18bec918f744b4425138a59a99e9ed6@
.
.17.60
P-Asserted-Identity: “+#########53sip:+#########53@***.***.17.60;user=phone;sc=server2;tag=da7296ffb710f1183eaf98869db51467
Diversion: sip:+########38@***.***.124.63;reason=unconditional
Max-Forwards: 70

However when I have an incoming DIVERSION header, even when I try to update the outcome of the INVITE is still showing the original.

I also tried:

channel[“PJSIP_HEADER(update,Diversion)”]:set(diversion_value)

On the logs it is not updating the header.
I am updating the DIVERSION header with the command above. I am using the Referred-By value, but as you see they do not match.

Referred-By: sip:+########35@server7
Diversion: sip:+########38@***.***.124.63;reason=unconditional

You’re trying to manipulate things at the generic header level, and there is built in support for Referred-By/Diversion. You can’t manipulate that at the generic header level as it will be overwritten, unless you disable it on the endpoint by setting the “send_diversion” option to “no”. I haven’t tested that though.

The built in support uses the REDIRECTING dialplan function[1].

[1] Manipulating Party ID Information - Asterisk Documentation

1 Like

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