SIP Messaging with FreePBX


(Avayax) #1

Is it possible to send text messages (SIP message) from one phone to the other using FreePBX 13 /Asterisk 13, pjsip?
My Yealink phones support it but I get errors on the Asterisk side.

<--- Received SIP request (626 bytes) from UDP:10.124.195.10:5060 --->
MESSAGE sip:5314@10.20.32.4:5060 SIP/2.0
Via: SIP/2.0/UDP 10.124.195.10:5060;branch=z9hG4bK2016407173
From: "5315" <sip:5315@10.20.32.4:5060>;tag=2437577201
To: <sip:5314@10.20.32.4:5060>
Call-ID: 0_1556125936@10.124.195.10
CSeq: 2 MESSAGE
Authorization: Digest username="5315", realm="asterisk", nonce="1602498181/8147a8741daf0d8d7dbcdb6ba4871700", uri="sip:5314@10.20.32.4:5060", response="b41e33ba8d02d9af99a60d10ea88b39a", algorithm=MD5, cnonce="0a4f113b", opaque="1cbcb34f3002253d", qop=auth, nc=00000001
Content-Type: text/plain
Max-Forwards: 70
User-Agent: Yealink SIP-T23G 44.84.0.125
Content-Length: 2

hi
<--- Transmitting SIP response (328 bytes) to UDP:10.124.195.10:5060 --->
SIP/2.0 202 Accepted
Via: SIP/2.0/UDP 10.124.195.10:5060;rport=5060;received=10.124.195.10;branch=z9hG4bK2016407173
Call-ID: 0_1556125936@10.124.195.10
From: "5315" <sip:5315@10.20.32.4>;tag=2437577201
To: <sip:5314@10.20.32.4>;tag=z9hG4bK2016407173
CSeq: 2 MESSAGE
Server: FPBX-13.0.195.4(13.18.3)
Content-Length:  0


[2020-10-12 06:23:02] ERROR[6991][C-00024e0a]: translate.c:1320 ast_translator_best_choice: Cannot determine best translation path since one capability supports no formats
[2020-10-12 06:23:02] WARNING[6991][C-00024e0a]: channel.c:6203 ast_request: No translator path exists for channel type PJSIP (native (g723|ulaw|alaw|gsm|g726|g726aal2|adpcm|slin|slin|slin|slin|slin|slin|slin|slin|slin|lpc10|g729|speex|speex|speex|ilbc|g722|siren7|siren14|testlaw|g719|opus|silk|silk|silk|silk)) to (none)
[2020-10-12 06:23:02] WARNING[6991][C-00024e0a]: app_dial.c:2525 dial_exec_full: Unable to create channel of type 'PJSIP' (cause 58 - Bearer capability not available)
[2020-10-12 06:23:02] ERROR[6991][C-00024e0a]: channel.c:5640 set_format: Unable to set format because channel Message/ast_msg_queue supports no formats
[2020-10-12 06:23:02] WARNING[6991][C-00024e0a]: file.c:1247 ast_streamfile: Unable to open /var/spool/asterisk/voicemail/default/5314/unavail (format (none)): Function not implemented
[2020-10-12 06:23:02] ERROR[6991][C-00024e0a]: channel.c:5640 set_format: Unable to set format because channel Message/ast_msg_queue supports no formats
[2020-10-12 06:23:02] WARNING[6991][C-00024e0a]: file.c:1247 ast_streamfile: Unable to open beep (format (none)): Function not implemented
[2020-10-12 06:23:02] ERROR[6991][C-00024e0a]: channel.c:5640 set_format: Unable to set format because channel Message/ast_msg_queue supports no formats
[2020-10-12 06:23:02] WARNING[6991][C-00024e0a]: app.c:1615 __ast_play_and_record: Unable to set to linear mode, giving up

#2

FreePBX’s dialplan only handles calls and not messages.

For each endpoint that will send messages you would set the message_context to a custom context name (such as “messages”). In FreePBX 15 this is a field in the Extension settings. In FreePBX 13 you would have to do it in the pjsip.endpoint_custom_post.conf file, e.g.

[1000](+)
message_context=messages

then in /etc/asterisk/extensions_custom.conf, make a [messages] context:

[messages]
; Deliver to local 4-digit extension
exten => _XXXX,1,Set(FROMUSER=${CUT(MESSAGE(from),<,2)})
same => n,Set(FROMUSER=${CUT(FROMUSER,@,1)})
same => n,Set(FROMUSER=${CUT(FROMUSER,:,2)})
same => n,Set(TODEVICE=${DB(DEVICE/${EXTEN}/dial)})
same => n,Set(TODEVICE=${TOLOWER(${STRREPLACE(TODEVICE,"/",":")})})
same => n,MessageSend(${TODEVICE},${FROMUSER})

The database lookup allows for sending to different technologies (pjsip:, sip:, or sccp: )


(Lorne Gaetz) #3

A context name of ‘messages’ is pretty generic. To avoid a possibility of any conflict in the future, I would recommend something like messages-avayax.


#4

[messages] was my second choice after [m] :smiley:


(Avayax) #5

Is there a way to get the content of the message body and manipulate it from dial plan?


(Communication Technologies) #6

Something like this?


#7

The function MESSAGE(body) can be read or set. https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Function_MESSAGE

Example:

same => n,Set(MESSAGE(body)=${STRREPLACE(MESSAGE(body),"pizza","🍕")})

Sending a message to another account on the same device: