SIP SIMPLE Message between PJSIP Extensions with multiple contacts (AORs)

Hello, I use Distro 14 with Asterisk 16.

All my extensions are PJSIP extensions. Today I can send SIP SIMPLE IM message between extensions but only to one AOR contact of the PJSIP extension. If I have multiple phones connected to one extensions (multiple AOR), I can’t arrived to send a this message to all the phones.

My message_context is correctly set for all the PJSIP extension with astsms

With this custom context, it sends the message to the last registered AOR.

[astsms]
exten => _.,1,NoOp(SMS receiving dialplan invoked)
exten => _.,n,NoOp(To ${MESSAGE(to)})
exten => _.,n,NoOp(From ${MESSAGE(from)})
exten => _.,n,NoOp(Body ${MESSAGE(body)})
exten => _.,n,Set(ACTUALTO=${CUT(MESSAGE(to),@,1)})
exten => _.,n,MessageSend(${ACTUALTO},${MESSAGE(from)})
exten => _.,n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
exten => _.,n,GotoIf($["${MESSAGE_SEND_STATUS}" != “SUCCESS”]?sendfailedmsg)
exten => _.,n,Hangup()
;
; Handle failed messaging
exten => _.,n(sendfailedmsg),Set(MESSAGE(body)="[${STRFTIME(${EPOCH},%d%m%Y-%H:%M:%S)}] Your message to ${EXTEN} has failed. Retry later.")
exten => _.,n,Set(ME_1=${CUT(MESSAGE(from),<,2)})
exten => _.,n,Set(ACTUALFROM=${CUT(ME_1,@,1)})
exten => _.,n,MessageSend(${ACTUALFROM},ServiceCenter)
exten => _.,n,Hangup()
exten => _.,n,Hangup()

I have tried this context too :

[astsms]
exten => s,1,NoOp(Sending message!)
same => n,NoOp(To ${MESSAGE(to)})
same => n,NoOp(From ${MESSAGE(from)})
same => n,NoOp(Body ${MESSAGE(body)})
same => n,Set(from=${CUT(MESSAGE(from),@,1)})
same => n,Set(from_domain=${CUT(MESSAGE(from),@,2)})
same => n,Set(from_domain=${CUT(from_domain,;,1)})
same => n,Set(from_domain=${CUT(from_domain,>,1)})
same => n,Set(from_no=${CUT(from,:,2)})
same => n,Set(to=${CUT(MESSAGE(to),@,1)})
same => n,Set(to_no=${CUT(to,:,2)})
same => n,Set(dial=${DB(DEVICE/${to_no}/dial)})
same => n,Set(tech=${TOLOWER(${CUT(dial,/,1)})})
same => n,GotoIf($["${tech}" != “pjsip”]?sendmsg)
same => n,Set(contacts=${PJSIP_AOR(${to_no},contact)})
same => n,While($["${SET(contact=${SHIFT(contacts,)})}" != “”])
same => n,Set(contacturi=${PJSIP_CONTACT(${contact},uri)})
same => n,Set(sipuri=${CUT(contacturi,;,1)})
same => n,Set(to_no=${CUT(contacturi,@,2)})
same => n(sendmsg),MessageSend(${tech}:${to_no},sip:${from_no}@${from_domain})
same => n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
same => n,GotoIf($[${EXISTS(${contacturi})}]?:end)
same => n,EndWhile
same => n(end),HangUp()

But when I send an IM, I have a SIP/2.0 404 Not Found SIP Response

**2021/02/15 21:54:53.938630 XX.XX.XX.XX:8780 -> YY.YY.YY.YY:1485**
SIP/2.0 **404** Not Found
Via: SIP/2.0/UDP 192.168.0.20:1485;rport=1485;received=XX.XX.XX.XX;branch=z9hG4bKBApZ9FbfI2GwNvjv
Call-ID: **28BF83481A8C3765C865DDAAAC987F3C5DB4E5D8**
From: "Charles" <sip:[email protected]>;tag=EDF6D3BC5254C0266B1DB6E01E33D0C2
To: <sip:[email protected]>;tag=z9hG4bKBApZ9FbfI2GwNvjv
CSeq: 2 MESSAGE
Server: FPBX-14.0.16.4.1(16.15.1)
Content-Length: 0

Do you have any idea ?

Thanks

I tried this too

;================================ SUB_TEXT_USER ==
; Instant messaging subroutine for PJSIP
; Send message to all pjsip contacts of an endpoint
; Usage: Gosub(sub_text_user,${EXTEN},1(${HINT}))
; ${EXTEN} - Extension, eg 0735698294
; ${ARG1} - pjsip tech/endpoint: ${HINT}, eg PJSIP/myuser
;
; Implementation details
; PJSIP_DIAL_CONTACTS() return all contact URLs separated by an "&", eg: 
; PJSIP/myuser/sip:[email protected]:61863;option=value&PJSIP/myuser/sip:[email protected]:35678;option=value
; Within a While() loop, we cut this string at the "&" using ${SHIFT(contacts,&):6}. 
; The ":6" strips off the initial "PJSIP/".
; MessageSend() needs the URL to be slightly reformatted, eg
; pjsip:myuser/sip:[email protected]:61863;option=value
; so we simply prepend with "pjsip:"
; MessageSend() accepts but ignores any provided options
;
[astsms]
exten = _X.,1,Verbose(2, "Sending message, To ${MESSAGE(to)}, Hint ${ARG1}, From ${MESSAGE(from)}, CID ${CALLERID}, Body ${MESSAGE(body)}")
 same = n,Set(LOCAL(endpoint)=${CUT(ARG1,/,2)})
 same = n,Set(LOCAL(contacts)=${PJSIP_DIAL_CONTACTS(${endpoint})})
 same = n,While($["${SET(contact=${SHIFT(contacts,&):6})}" != ""])
 same = n,MessageSend(pjsip:${contact},${MESSAGE(from)})
 same = n,Verbose(2, "Send status is ${MESSAGE_SEND_STATUS}")
 same = n,EndWhile
 same = n,HangUp()

But I have this log answer

    [2021-02-15 22:17:42] VERBOSE[4444][C-0000008b] pbx.c: Executing [199@astsms:1] Verbose("Message/ast_msg_queue", "2, "Sending message, To pjsip:[email protected], Hint , From "Charles" <sip:[email protected]>, CID , Body Hhh"") in new stack
    [2021-02-15 22:17:42] VERBOSE[4444][C-0000008b] app_verbose.c: "Sending message, To pjsip:[email protected], Hint , From "Charles" <sip:[email protected]>, CID , Body Hhh"
    [2021-02-15 22:17:42] VERBOSE[4444][C-0000008b] pbx.c: Executing [199@astsms:2] Set("Message/ast_msg_queue", "LOCAL(endpoint)=") in new stack
    [2021-02-15 22:17:42] ERROR[4444][C-0000008b] app_stack.c: Tried to set LOCAL(endpoint), but we aren't within a Gosub routine
    [2021-02-15 22:17:42] WARNING[4444][C-0000008b] pjsip/dialplan_functions.c: An endpoint name must be specified when using the 'PJSIP_DIAL_CONTACTS' dialplan function
    [2021-02-15 22:17:42] VERBOSE[4444][C-0000008b] pbx.c: Executing [199@astsms:3] Set("Message/ast_msg_queue", "LOCAL(contacts)=") in new stack
    [2021-02-15 22:17:42] ERROR[4444][C-0000008b] app_stack.c: Tried to set LOCAL(contacts), but we aren't within a Gosub routine
    [2021-02-15 22:17:42] VERBOSE[4444][C-0000008b] pbx.c: Executing [199@astsms:4] While("Message/ast_msg_queue", "0") in new stack
    [2021-02-15 22:17:42] VERBOSE[4444][C-0000008b] app_while.c: Jumping to priority 7
    [2021-02-15 22:17:42] VERBOSE[4444][C-0000008b] pbx.c: Executing [199@astsms:8] Hangup("Message/ast_msg_queue", "") in new stack
    [2021-02-15 22:17:42] VERBOSE[4444][C-0000008b] pbx.c: Spawn extension (astsms, 199, 8) exited non-zero on 'Message/ast_msg_queue'

I have not looked at SIP SIMPLE messages. but when sending a SIP notify to a specific AOR, I need to include the full AOR in my testing.

[jbusch@pbx ~]$ rasterisk -x 'pjsip show aor 103'
<snip>
# this
 contact              : sip:[email protected]:1029
 contact              : sip:[email protected]:12065;transport=TLS;x-ast-orig-host=10.254.103.215:12065
 contact              : sip:[email protected]:21538;transport=TCP;rinstance=787AD507;x-ast-orig-host=10.65.9.1:21538
rasterisk -x 'pjsip send notify restart-yealink uri sip:[email protected]:12065;transport=TLS;x-ast-orig-host=10.254.103.215:12065'
# or
rasterisk -x 'pjsip send notify restart-yealink uri sip:[email protected]:1029'

Thank you Jared, I will try it

Also take a look at this. It has a few suggestions on looping through the contacts.

Dear, thank you ! it works :wink:

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