493: Undecipherable

-Blog-

-Projects-

-About me-

-RSS-

Asterisk and MessageSend

Dennis Guse

We are using Asterisk (running on FreeBSD 9.0 port stock version: 10.0.0-rc2) as SIP registrar/proxy. We are using the Android softphone cSipSimple, which also provides SIP SIMPLE messaging functionality. To enable this on Asterisk add to sip.conf: accept_outofcallmessage=yes and outofcall_message=message (the name of the context handler).

However, we had some trouble setting up Asterisk to really do it. In the message-ctx Asterisk provides the information of the current message as variables/function: MESSAGE(to), MESSAGE(from) and MESSAGE(body).

(First problem) The first problem is that MESSAGE(to) contains the complete address, e.g. sip:PHONENUMBER@SERVERIP. If you try to use this address asterisk sends the message to itself and complains on receive that their is no routing for the incoming message. So, we need to remove the @IP part using the CUT command from the TO and the FROM. Now we can send a message from one phone to another: MESSAGESEND(CUTED_TO, CUTED_FROM).

(Second problem) However, we cannot reply as the recipient got as sender address something like sip:UNKNOWN@SERVERIP. In short use MESSAGESEND(CUTED_TO, CUTED_FROM <CUTED_FROM>) or as example MESSAGESEND(sip:1, SOMEBODY <1>). The first part of the FROM is the name shown to the user and the second part the reply to phone number (without sip:).

Here is our working context for messaging of the extensions.conf:

1
2
3
4
5
6
7
[message]
  exten => _X.,1,Set(TO=${CUT(MESSAGE(to),@,1)})
  exten => _X.,n,Set(FROM=${CUT(MESSAGE(from),:,2)})
  exten => _X.,n,Set(FROM_PHONE_NUMBER=${CUT(FROM,@,1)})
  exten => _X.,n,MessageSend(${TO}, ${FROM_PHONE_NUMBER}&lt;${FROM_PHONE_NUMBER}&gt;)
  ;;DEBUG Print the status of the MessageSend
  exten => _X.,n,Verbose(0, ${TO} ${MESSAGE(from)} ${FROM} ${MESSAGE_SEND_STATUS})

Thanks to Nicolas.