Messinet Secure Services
wiki:Asterisk/Message
Last modified 7 months ago Last modified on 10/11/12 12:29:38

Asterisk Basic SIP MESSAGE Routing

Basic SIP MESSAGE routing.

sip.conf

[general]
...
accept_outofcall_message=yes
outofcall_message_context=messages-sip
auth_message_requests=yes
regcontext=sipregistrations
...

[17735550001]
...
regexten=2201&17735550001
...

[17735550002]
...
regexten=2202&17735550002
...

extensions.conf

[messages]
include => sipregistrations

; Country Code +1 extensions which match sip peer names only at the moment
exten => _1NXXNXXXXXX,2,MessageSend(sip:${EXTEN},${MESSAGE(from)})
same => n,NoOp(Message Send Status: ${MESSAGE_SEND_STATUS})
same => n,Hangup()

; Unavailable extensions
exten => i,1,Set(MESSAGE(body)=Temporarily unavailable)
same => n,Set(FROM=${CUT(MESSAGE(from),<,2)})
same => n,MessageSend(${CUT(FROM,@,1)},"Asterisk" <${INVALID_EXTEN}>)

Asterisk Advanced SIP MESSAGE Distribution to Multiple Devices

As many of use are using more devices, and since Asterisk doesn't yet support multiple AORs, there is a way to distribute incoming messages to any and all of our devices. To do this, we simply create a sort of user alias via the dialplan that maps to a list of devices for a real person. We match this list of devices with the regexten parameter in the device definitions of the multiple devices that must be created.

sip.conf

[general]
...
realm=asterisk
accept_outofcall_message=yes
outofcall_message_context=messages-sip
auth_message_requests=no
...

;
; Multi-device user alias template
[user](!)
type=friend
host=dynamic
context=default
callerid="SIP User" <2201>
regexten=user&user-1&user-2&user-ws&1775550001
;secret converted to md5secrets below
;secret=YuvdZ97a93sirhzUZlswS058EnlRJsASaGbud2yBQ2uIJGJpP8BfJ5K7UnOlMe1
videosupport=yes
contactpermit=0.0.0.0/0.0.0.0
contactpermit=::/0
permit=0.0.0.0/0.0.0.0
permit=::/0
disallow=all
allow=gsm
allow=g722
allow=h264

[user-1](user)
description=user - (host1)
md5secret=56f5221c26d009250cf48c1bb4e79d43

[user-2](user)
description=user - Telepathy-KDE (host2)
md5secret=56ca94ba21363e8c8085ffec42622ef3

[user-ws](user)
; WebSocket: https://wiki.asterisk.org/wiki/display/AST/Asterisk+WebRTC+Support
description=user (WebSocket/sipML5)
avpf=yes
encryption=yes
directmedia=no
md5secret=636c0c3217e4b4c990d08425f67c8db0
videosupport=no

[17735550001](user)
description=user - CSipSimple (773-555-0001)
encryption=yes
md5secret=ab6f279759b83b480a5c5040cb47ce7b

extensions.conf

[global]
user=SIP/user-1&SIP/user-2&SIP/user-ws&&SIP/17735550001


[messages-sip]
; Invalid handler
exten => _[is],1,NoOp(Invalid extension: inbound SIP MESSAGE to ${MESSAGE(to)} from ${MESSAGE(from)})

; Require at least 4 character extensions
exten => _[a-z1-9][a-z0-9][a-z0-9][a-z0-9].,1,Goto(asterisk_message_distribution,1)

exten => asterisk_message_distribution,1,NoOp(Start SIP MESSAGE to ${MESSAGE(to)} from ${MESSAGE(from)})
same => n,Set(TO=${CUT(MESSAGE(to),:,2)})
same => n,Set(TO=${CUT(TO,@,1)})
same => n,Set(FROM=${CUT(MESSAGE(from),:,2)})
same => n,Set(FROM=${CUT(FROM,@,1)})

; Get/set peer group memberships
same => n,Set(TO_PEERS=${IF($["${GLOBAL(${TO})}" = ""]?SIP/${TO}:${GLOBAL(${TO})})})
same => n,Set(TO_PEERS=${LISTFILTER(TO_PEERS,&,SIP/${FROM})})
same => n,Set(FROM_PEERS=${IF($["${SIPPEER(${FROM},regexten)}" = ""]?SIP/${FROM}:${SIPPEER(${FROM},regexten)})})

; Replace from address with the first regexten in the group
same => n,Set(FROM_PEER=${SHIFT(FROM_PEERS,&)})
same => n,Set(FROM_PEER=${STRREPLACE(MESSAGE(from),${FROM},${FROM_PEER})})

; Distribute to each peers in recipient's group
same => n,While($["${SET(TO_PEER=${SHIFT(TO_PEERS,&):4})}" != ""])
same => n,Set(TO_PEER_NAME=${SIPPEER(${TO_PEER},callerid_name)})
same => n,GotoIf($["${DEVICE_STATE(SIP/${TO_PEER})}" != "NOT_INUSE"]?skip)
same => n,MessageSend(sip:${TO_PEER},${FROM_PEER})
same => n,Set(GROUP_MESSAGE_SEND_STATUS=${IF($["${MESSAGE_SEND_STATUS}" = "SUCCESS"]?SUCCESS)})
same => n(skip),ContinueWhile()
same => n,EndWhile()

; Determine ability to send to at least one peer, otherwise send offline message
same => n,GotoIf($["${GROUP_MESSAGE_SEND_STATUS}" = "SUCCESS"]?end)
same => n,Set(MESSAGE(body)=I'm offline)
same => n,MessageSend(sip:${FROM},"${TO_PEER_NAME}" <${MESSAGE(to)}>)
same => n(end),NoOp(Finish SIP MESSAGE to ${MESSAGE(to)} from ${MESSAGE(from)}))