How to keep the TO header in MessageSend()?

Hi all,
I’m using MessageSend() to send SIP MESSAGE requests between my registered PJSIP endpoints but I noticed that Asterisk always rewrites the TO header with real IP addresses as they appear in AOR.
This is causing the destination endpoint to create a new chat for the incoming SIP MESSAGE as it targets the IP address instead of domain name.
What I mean is in Asterisk logs I see:

<— Received SIP request (683 bytes) from WSS:37.XXX.XXX.XXX:52035 —>
MESSAGE sip:892@even.mytel.it SIP/2.0
Via: SIP/2.0/WSS 7dkgibevdo8e.invalid;branch=z9hG4bK7334263
Max-Forwards: 69
To: sip:892@even.mytel.it
From: sip:624@even.mytel.it;tag=5ducb6hl9c
Call-ID: m4saplbp7sftikghd164
CSeq: 5402 MESSAGE
Authorization: Digest algorithm=MD5, username=“624”, realm=“asterisk”, nonce=“1551707044/73bbe61471fb0d459195bbd0363dd270”, uri=“sip:892@even.mytel.it”, response=“4d4fd38f5588a890322de841045a2185”, opaque=“341e26da53a49a04”, qop=auth, cnonce=“pm0gtmu8p66h”, nc=00000001
Content-Type: text/plain
Allow: INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO
Supported: outbound
User-Agent: JsSIP 3.3.4
Content-Length: 10

riproviamo
<— Transmitting SIP response (315 bytes) to WSS:37.XXX.XXX.XXX:52035 —>
SIP/2.0 202 Accepted
Via: SIP/2.0/WSS 7dkgibevdo8e.invalid;rport=52035;received=37.XXX.XXX.XXX;branch=z9hG4bK7334263
Call-ID: m4saplbp7sftikghd164
From: sip:624@even.mytel.it;tag=5ducb6hl9c
To: sip:892@even.mytel.it;tag=z9hG4bK7334263
CSeq: 5402 MESSAGE
Server: Asterisk PBX 16.0.0
Content-Length: 0

-- Executing [892@smsdial:1] NoOp("Message/ast_msg_queue", "SMS receiving dialplan invoked") in new stack
-- Executing [892@smsdial:2] NoOp("Message/ast_msg_queue", "To pjsip:892@even.mytel.it") in new stack
-- Executing [892@smsdial:3] NoOp("Message/ast_msg_queue", "From <sip:624@even.myel.it>") in new stack
-- Executing [892@smsdial:4] NoOp("Message/ast_msg_queue", "Body riproviamo") in new stack
-- Executing [892@smsdial:5] Set("Message/ast_msg_queue", "PJSIPACTUALTO=pjsip:892") in new stack
-- Executing [892@smsdial:6] Set("Message/ast_msg_queue", "ACTUALTO=892") in new stack
-- Executing [892@smsdial:7] Set("Message/ast_msg_queue", "MESSAGE_DATA(X-Even)=") in new stack
-- Executing [892@smsdial:8] Set("Message/ast_msg_queue", "MESSAGE_DATA(X-EvenType)=") in new stack
-- Executing [892@smsdial:9] Set("Message/ast_msg_queue", "MESSAGE_DATA(X-Caller)=") in new stack
-- Executing [892@smsdial:10] Set("Message/ast_msg_queue", "MESSAGE_DATA(X-Callee)=") in new stack
-- Executing [892@smsdial:11] MessageSend("Message/ast_msg_queue", "pjsip:892,<sip:624@even.i-tel.it>") in new stack
-- Executing [892@smsdial:12] NoOp("Message/ast_msg_queue", "Send status is SUCCESS") in new stack
-- Executing [892@smsdial:13] GotoIf("Message/ast_msg_queue", "0?sendfailedmsg") in new stack
-- Executing [892@smsdial:14] Hangup("Message/ast_msg_queue", "") in new stack

== Spawn extension (smsdial, 892, 14) exited non-zero on ‘Message/ast_msg_queue’
<— Transmitting SIP request (493 bytes) to TLS:37.XXX.XXX.XXX:48039 —>
MESSAGE sip:892@37.XXX.XXX.XXX:48039;transport=TLS SIP/2.0
Via: SIP/2.0/TLS 51.XX.XX.XX:5061;rport;branch=z9hG4bKPjf699b368-1db2-46ff-a41e-d917d266740d;alias
From: sip:624@even.mytel.it;tag=5bded5c5-2e1f-441a-babd-1a6bbf325d84
To: sip:892@37.XXX.XXX.XXX
Contact: sip:892@51.XX.XX.XX:5061;transport=TLS
Call-ID: 25fd3058-2379-4391-8bf0-8b3e0c31da19
CSeq: 17596 MESSAGE
Max-Forwards: 70
User-Agent: Asterisk PBX 16.0.0
Content-Type: text/plain
Content-Length: 10

riproviamo
<— Received SIP request (1035 bytes) from TLS:37.XXX.XXX.XXX:48039 —>
MESSAGE sip:624@even.mytel.it SIP/2.0
Via: SIP/2.0/TLS 192.168.5.187:48039;branch=z9hG4bK.NgvJpydrT;rport
From: sip:892@37.XXX.XXX.XXX;tag=0FH~BuhV6
To: sip:624@even.mytel.it
CSeq: 20 MESSAGE
Call-ID: YxdZV9Fvzh
Max-Forwards: 70
Supported: replaces, outbound, gruu
Date: Mon, 04 Mar 2019 13:44:05 GMT
Content-Encoding: deflate
Content-Type: message/imdn+xml
Content-Length: 282
Priority: non-urgent
User-Agent: ITELphoneAndroid/4.0.1 (belle-sip/1.6.3)
Proxy-Authorization: Digest realm=“asterisk”, nonce=“1551706951/b5eaf6fca0a39a3a407d0352a495dafe”, algorithm=md5, opaque=“4b178aae6f3c8a1c”, username=“892”, uri=“sip:624@even.mytel.it”, response=“15800c414e3d636be555bbdb9d821259”, cnonce=“sMUzj1JdnXUQKiT8”, nc=00000002, qop=auth

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>25fd3058-2379-4391-8bf0-8b3e0c31da192019-03-04T13:44:05Z

<— Received SIP response (319 bytes) from TLS:37.XXX.XXX.XXX:48039 —>
SIP/2.0 200 Ok
Via: SIP/2.0/TLS 51.XX.XX.XX:5061;rport;branch=z9hG4bKPjf699b368-1db2-46ff-a41e-d917d266740d;alias
From: sip:624@even.mytel.it;tag=5bded5c5-2e1f-441a-babd-1a6bbf325d84
To: sip:892@37.XXX.XXX.XXX;tag=ZR4Q2bL
Call-ID: 25fd3058-2379-4391-8bf0-8b3e0c31da19
CSeq: 17596 MESSAGE
Content-Length: 0

So the messages are delivered but with unwanted TO header containing the registered IP address.
Is there a way to maintain the domain name “even.mytel.it” in the TO header?

Thanks

Same problem here. Any solution?

Hi
I have no any problem with sip messaging
Please share your full Dialplan and Agi Script for pjsip , I will be happy to help you.

Hello Franco,

I had same issues but I fixed it.
The problem comes from dialplan and AGI or both.
Please show me all your dialplan and AGI and any other PJSIP Messaging settings, then I can help you to fix it.

Regards,
Majid

You might be interested in ASTERISK-28513.