Add messaging support

Hi,
I take a look at several post on this forum and I googled a day. The procedure to add messaging support seems fair simple but in my asterisk server (13.8.1) it does not work.

Here my sip.conf:

[general]
accept_outofcall_message = yes 
outofcall_message_context = messages
auth_message_requests = no

while in extensions.conf I have:

[messages]
exten => _X.,1,MessageSend(sip:${EXTEN},"${CALLERID(name)}"${MESSAGE(from)})

when I send a message from the user agent i get:

– Executing [6011@messages:1] MessageSend(“Message/ast_msg_queue”, “sip:6011,”““6007” sip:mario@192.168.0.3”) in new stack
[Apr 28 17:01:38] WARNING[10735][C-00000000]: chan_sip.c:6225 create_addr: Purely numeric hostname (6011), and not a peer–rejecting!
– Auto fallthrough, channel ‘Message/ast_msg_queue’ status is ‘UNKNOWN’

I think the problem regarding the purely numeric hostname means I should have something like
sip:6011@192.168.0.3
which is the localhost. I don’t understand why and how have I to configure the messages context.
Moreover the syntax of the MessageSend command seems to have a quotation mark (") which should not be there.

Thank you.

What exactly do you want to do and need sip messaging?

Hi astbox, thank you for the reply.
I am developing a sip phone with some I/O. The idea is to send a message from a softphone (linphone or csipsimple), according to the message content I want to to set the outputs and send back a message with the state of the inputs.

mario

The message will be send from the softphone to asterisk, retrieve some data and output that data to the softphone?
Or do you want to send the message to another user, then the user inputs the data and sends back the message?

The second: Alice sends the message to Bob, Bob performs some task and sends back another message to Alice.

Reading the following link

https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Application_MessageSend

I think that your diaplan must be something like this

exten => _X.,1,Set(MESSAGE(body)=“My message”)
exten => _X.,n,MessageSend(sip:${EXTEN},sip:${CALLERID(number)})

Check also voip-info for examples

http://www.voip-info.org/wiki/view/Asterisk+cmd+MessageSend

Yes, I tested tons of examples, also with the above command I get “Purely numeric hostname” error:

[Apr 29 04:37:50] NOTICE[14203]: chan_sip.c:24403 handle_response_peerpoke: Peer ‘mario’ is now Reachable. (29ms / 2000ms)
– Executing [6011@messages:1] Set(“Message/ast_msg_queue”, “MESSAGE(body)=“My message””) in new stack
– Executing [6011@messages:2] MessageSend(“Message/ast_msg_queue”, “sip:6011,sip:”) in new stack
[Apr 29 04:38:20] WARNING[14153][C-00000000]: chan_sip.c:6225 create_addr: Purely numeric hostname (6011), and not a peer–rejecting!

There is something wrong I my conf. I am unable to find the problem.

Just for testing purposes hardcode the from option because there is nothing filled using the CALLERID variable. Run the following command in the asterisk cli and post here the output

sip show peers

ubuntuserver*CLI> sip show peers
Name/username             Host                                    Dyn Forcerport Comedia    ACL Port     Status      Description                      
mario/mario               192.168.0.210                            D  No         No             5060     OK (273 ms)                                  
pc1/pc1                   192.168.0.21                             D  No         No             5060     OK (19 ms)                                   
scheda1                   (Unspecified)                            D  No         No             0        UNKNOWN                                      
3 sip peers [Monitored: 2 online, 1 offline Unmonitored: 0 online, 0 offline]

And here the dialplan hints:

core show hints

    -= Registered Asterisk Dial Plan Hints =-
6021@ermes-phones   : SIP/scheda1           State:Unavailable     Presence:not_set         Watchers  0
6007@ermes-phones   : SIP/mario             State:Idle            Presence:not_set         Watchers  0
6011@ermes-phones   : SIP/pc1               State:Idle            Presence:not_set         Watchers  0
----------------
- 3 hints registered

You are getting purely numeric hostname because you have no sip.conf entry that matches the callerID.

1 Like

You should change the sip:${EXTEN} to sip:pc1.

@david551 I think you are right but, in sip.conf I have:

[mario](friends_internal_ermes)
callerid="mario" <6007>
mailbox=6007@ermes-internal
;
[pc1](friends_internal_ermes)
callerid="pc1" <6011>
mailbox=6011@ermes-internal
;
[scheda1](friends_internal_ermes)
callerid="scheda1" <6021>
mailbox=6021@ermes-internal

So the peers are defined.
With this,

exten => _X.,1,NoOp(SMS receiving dialplan invoked)
exten => _X.,n,NoOp(To ${MESSAGE(to)})
exten => _X.,n,NoOp(From ${MESSAGE(from)})
exten => _X.,n,NoOp(Body ${MESSAGE(body)})
exten => _X.,n,MessageSend(sip:${EXTEN},"${CALLERID(name)}"${MESSAGE(from)})
exten => _X.,n,Hangup()

I get,

– Executing [6007@messages:1] NoOp(“Message/ast_msg_queue”, “SMS receiving dialplan invoked”) in new stack
– Executing [6007@messages:2] NoOp(“Message/ast_msg_queue”, “To sip:6007@192.168.0.3”) in new stack
– Executing [6007@messages:3] NoOp(“Message/ast_msg_queue”, “From sip:pc1@192.168.0.3”) in new stack
– Executing [6007@messages:4] NoOp(“Message/ast_msg_queue”, “Body ciao”) in new stack
– Executing [6007@messages:5] MessageSend(“Message/ast_msg_queue”, “sip:6007,”“sip:pc1@192.168.0.3”) in new stack
[Apr 29 15:37:53] WARNING[3187][C-00000000]: chan_sip.c:6225 create_addr: Purely numeric hostname (6007), and not a peer–rejecting!
– Executing [6007@messages:6] Hangup(“Message/ast_msg_queue”, “”) in new stack
== Spawn extension (messages, 6007, 6) exited non-zero on ‘Message/ast_msg_queue’

@astbox you are right, if I change as follow:

exten => _X.,n,MessageSend(sip:mario,“${CALLERID(name)}”${MESSAGE(from)})

I can send a message from sip:pc1 to sip:mario. But why I can’t set a general rule using sip:${EXTEN}?

– Executing [6007@messages:1] NoOp(“Message/ast_msg_queue”, “SMS receiving dialplan invoked”) in new stack
– Executing [6007@messages:2] NoOp(“Message/ast_msg_queue”, “To sip:6007@192.168.0.3”) in new stack
– Executing [6007@messages:3] NoOp(“Message/ast_msg_queue”, “From sip:pc1@192.168.0.3”) in new stack
– Executing [6007@messages:4] NoOp(“Message/ast_msg_queue”, “Body ciao”) in new stack
– Executing [6007@messages:5] MessageSend(“Message/ast_msg_queue”, “sip:mario,”“sip:pc1@192.168.0.3”) in new stack
– Executing [6007@messages:6] Hangup(“Message/ast_msg_queue”, “”) in new stack
== Spawn extension (messages, 6007, 6) exited non-zero on ‘Message/ast_msg_queue’

I think I have to traslate the “TO” field from the extension sip:6007 to the peer sip:mario…
But why all the examples I found use the sip:${EXTEN} to define the message receiver?

The following work, but have I to replicate this for all the extensions. In particular the SendMessage statement in which I associate manually the extension to the peer.

; = SIP MESSAGE only works if in sip.conf "accept_outofcall_message=yes" is set! =
exten => 6007,1,GotoIf($[${LEN(${MESSAGE(from)})} < 1]?nomessage)
exten => 6007,n,NoOp(Message from: ${MESSAGE(from)})
exten => 6007,n,NoOp(Message to: ${MESSAGE(to)})
exten => 6007,n,NoOp(Message body: ${MESSAGE(body)})
;
exten => 6007,n,MessageSend(sip:mario,"${CALLERID(name)}"${MESSAGE(from)})
;
exten => 6007,n,NoOp(Message send status: ${MESSAGE_SEND_STATUS})
exten => 6007,n,HangUp
exten => 6007,n(nomessage),Dial(SIP/mypeername,30)
exten => 6007,n,HangUp

You need to have your extensions like this

[6011](friends_internal_ermes)
callerid="pc1" <6011>
mailbox=6011@ermes-internal

What you put between the [] at the first line is what asterisk understands as a sip extension. Normally you put a number there and then you use the callerid option to give a more user friendly name to the extension.

Thank you astbox.
But now I am a little confused. I followed the schema I found in the wiki asterisk:

The sip accounts in sip.conf are created as here
https://wiki.asterisk.org/wiki/display/AST/Creating+SIP+Accounts

[demo-alice](friends_internal)
secret=verysecretpassword ; put a strong, unique password here instead

then the account is associated to an extension.
see https://wiki.asterisk.org/wiki/display/AST/Creating+Dialplan+Extensions

[from-internal]
exten=>6001,1,Dial(SIP/demo-alice,20)

I have exactly the same scheme as in the wiki where in the sip.conf you don’t have

[6001](friends_internal)    

but you see:

[demo-alice](friends_internal)

As far as I am concerned I don’t see any extension number in sip.conf, isn’t it?

sip.conf contains device names. Although it is bad security practice and won’t work in multi-homed environments, most people make the device name the same as the principle extension number for that device.

1 Like

@peregrinus
From the tests that you have made for messaging to work you need to dial the actual sip extension and not what you map as a shortcode to this extension.
There are two ways doing this 1) you change the sip extension from a name to the number that you want to use 2) to keep consistency with the example that you used to configure your server, you keep using strings as the sip extensions and change your dialplan accordicly to send the message to this extenion.

So the final diaplan must be something like this

exten => _X.,1,NoOp(SMS receiving dialplan invoked)
exten => _X.,n,NoOp(To ${MESSAGE(to)})
exten => _X.,n,NoOp(From ${MESSAGE(from)})
exten => _X.,n,NoOp(Body ${MESSAGE(body)})
exten => _X.,n,GotoIf($["${EXTEN}" = "6011"]?6011)
exten => _X.,n,GotoIf($["${EXTEN}" = "6007"]?6007)
exten => _X.,n,GotoIf($["${EXTEN}" = "6021"]?6021)
exten => _X.,n,Hangup()
exten => _X.,n(6011),MessageSend(sip:pc1,"${CALLERID(name)}"${MESSAGE(from)})
exten => _X.,n,Hangup()
exten => _X.,n(6007),MessageSend(sip:mario,"${CALLERID(name)}"${MESSAGE(from)})
exten => _X.,n,Hangup()
exten => _X.,n(6021),MessageSend(sip:scheda1,"${CALLERID(name)}"${MESSAGE(from)})
exten => _X.,n,Hangup()

Just a draft, I haven’t test it but it should be somethig like this.

1 Like

Thank you astbox,
the solution 2, you provide works!!
but I suspect that if I use the solution 1, which david551 describes as a bad practice, I can avoid a lot of troubles.

Thank you to astbox and david551 for the support!