Receiving SIP messages with asterisk

I have a test and try server running and GS Wave as the Grandstream soft phone on an Iphone 4s. I’m trying to figure out how to use the MessageSend() feature on Asterisk. I managed to send a message from asterisk to the GS Wave soft phone using the example code.

exten => 1111,n,Set(MESSAGE(from)=sip/${CALLERID(num)) 
exten => 1111,n,Set(MESSAGE(body)=From now on number ${CALLERID(num)}  also receives the incoming lines from extension  ${HOTDESK_LOGIN} ) 
exten => 1111,n,MessageSend(sip:5554)

This is working.

I try to figure out how to send a message from one phone to my Asterisk server and from one phone to an other phone. When I try to send a message to my Asterisk server the SIP debug looks like (I changed IP numbers and domain name):

<--- SIP read from UDP:11.11.11.111:49383 --->
MESSAGE sip:asterisk@myserver.nl SIP/2.0
Via: SIP/2.0/UDP 192.168.1.104:49383;branch=z9hG4bK101233472;rport
Route: <sip:myserver.nl:5060;lr>
From: <sip:5554@myserver.nl>;tag=1790228994
To: <sip:asterisk@myserver.nl>
Call-ID: 1897619614-49383-14@BJC.BGI.B.BAE
CSeq: 130 MESSAGE
Contact: <sip:5554@192.168.1.104:49383>
Max-Forwards: 70
User-Agent: Grandstream Wave 1.2.2
Supported: replaces, path, timer, eventlist
Allow: INVITE, ACK, OPTIONS, CANCEL, BYE, SUBSCRIBE, NOTIFY, INFO, REFER, UPDATE, MESSAGE
Content-Type: text/plain; charset=UTF-8
Content-Length: 4

test
<------------->
--- (14 headers 1 lines) ---
Sending to 11.11.11.111:49383 (NAT)
Receiving message!
Found peer '5554' for '5554' from 11.11.11.111:49383
Looking for asterisk in test (domain myserver.nl)

<--- Transmitting (NAT) to 11.11.11.111:49383 --->
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 192.168.1.104:49383;branch=z9hG4bK101233472;received=11.11.11.111;rport=49383
From: <sip:5554@myserver.nl>;tag=1790228994
To: <sip:asterisk@myserver.nl>;tag=as18ad80c0
Call-ID: 1897619614-49383-14@BJC.BGI.B.BAE
CSeq: 130 MESSAGE
Server: Asterisk PBX 13.11.2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0

I added a couple of lines to my dial plan so in the context [test] the extension Asterisk can be found. But it doesn’t seem to help.

asterisk => _XXXX,1, Answer()
asterisk => _XXXX,n  NoOp(XXXXXXXXXXXXXXXXX)
asterisk => _XXXX,n  NoOp(test test test test)
asterisk => _XXXX,n  NoOp(XXXXXXXXXXXXXXXXX)

I searched for info on what the next logical step should be to make it work. I assume that, since GS Wave receives messages using MessageSend() it most be possible to also send message to the Asterisk server and trigger something in the dial plan and to send messages to other extensions/phones.

I’m looking for examples and pointer to relevant info. Thanks in advance.

/EdW

That dialplan is not correct. The correct format is:

exten => asterisk,1,NoOp

As well as the device is sending to ‘asterisk’ it would be difficult to know what other phone it would want to send the message to.

I seem to have a typo phase. Thanks for pointing to it. With the corrections the code looks like:

exten  => asterisk,1, Answer()
exten  => asterisk,n, NoOp(XXXXXXXXXXXXXXXXX)
exten  => asterisk,n, NoOp(test test test test)
exten  => asterisk,n, NoOp(XXXXXXXXXXXXXXXXX)

When I send a message from GS Wave back to my Asterisk server it is now routed into this part of the dial plan so it seems to work as far as the routing is concerned. The CLI output looks like:

 -- Executing [asterisk@test:1] Answer("Message/ast_msg_queue", "") in new stack
    -- Executing [asterisk@test:2] NoOp("Message/ast_msg_queue", "XXXXXXXXXXXXXXXXX") in new stack
    -- Executing [asterisk@test:3] NoOp("Message/ast_msg_queue", "test test test test") in new stack
    -- Executing [asterisk@test:4] NoOp("Message/ast_msg_queue", "XXXXXXXXXXXXXXXXX") in new stack
    -- Auto fallthrough, channel 'Message/ast_msg_queue' status is 'UNKNOWN'

This is from the SIP debug output and the last line suggest that the content is part of the SIP message (“test 13:55”)

<--- SIP read from UDP:82.74.63.228:49383 --->
MESSAGE sip:asterisk@myserver.nl SIP/2.0
Via: SIP/2.0/UDP 192.168.1.104:49383;branch=z9hG4bK103075508;rport
Route: <sip:hmyserver.nl:5060;lr>
From: <sip:5554@myserver.nl>;tag=704729313
To: <sip:asterisk@myserver.nl>
Call-ID: 541190618-49383-20@BJC.BGI.B.BAE
CSeq: 190 MESSAGE
Contact: <sip:5554@192.168.1.104:49383>
Max-Forwards: 70
User-Agent: Grandstream Wave 1.2.2
Supported: replaces, path, timer, eventlist
Allow: INVITE, ACK, OPTIONS, CANCEL, BYE, SUBSCRIBE, NOTIFY, INFO, REFER, UPDATE, MESSAGE
Content-Type: text/plain; charset=UTF-8
Content-Length: 9

In what way can I get this content if the SIP message in a variable within the Asterisk Dial Plan so I can actually use it within the dial plan or as a message to send forward?

The message is available using the MESSAGE[1] dialplan function.

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_MESSAGE

It seems to work. @jcolp Thanks a lot for the patience with my typos, the extreme fast response and guidance to a working solution.

This is what makes it work:

exten  => asterisk,1, Answer()
exten  => asterisk,n, NoOp(XXXXXXXXXXXXXXXXX)
exten  => asterisk,n, NoOp(test test test test)
exten  => asterisk,n, NoOp(XXXXXXXXXXXXXXXXX)
**exten  => asterisk,n,Set(TEST-VAR=MESSAGE(body))**
exten  =  asterisk,n, NoOp(the content of the message is:  $[  ${TEST-VAR}])

This is the cli output that shows that it is working. I guess it can’t be that hard to make it in a way that it is is possible to send messages from one phone to the other with Asterisk in between.

    -- Executing [asterisk@test:1] Answer("Message/ast_msg_queue", "") in new stack
    -- Executing [asterisk@test:2] NoOp("Message/ast_msg_queue", "XXXXXXXXXXXXXXXXX") in new stack
    -- Executing [asterisk@test:3] NoOp("Message/ast_msg_queue", "test test test test") in new stack
    -- Executing [asterisk@test:4] NoOp("Message/ast_msg_queue", "XXXXXXXXXXXXXXXXX") in new stack
    -- Executing [asterisk@test:5] Set("Message/ast_msg_queue", "TEST-VAR=MESSAGE(body)") in new stack
[Nov 17 14:28:19] NOTICE[29498][C-00056b2a]: ast_expr2.y:763 compose_func_args: argbuf allocated 5 bytes;
[Nov 17 14:28:19] NOTICE[29498][C-00056b2a]: ast_expr2.y:782 compose_func_args: argbuf uses 4 bytes;
    -- Executing [asterisk@test:6] NoOp("Message/ast_msg_queue", "the content of the message is:  This is a message to test if it will be received by my Asterisk server. It is kind of hard to find any useful examples of it.") in new stack

Asterisk is sending messages in a proper way. Sending messages from one extension/phone to another isn’t working yet. (sorry for the weird lay-out, I have know idea why the large characters shows up)

It feels like the messaging between sip phones registered on my Asterisk server is almost working. The issue is that the name of the sender is asterisk and not the extension number of the account configured on the GS Wave soft phone.

exten => s,n, NoOp(Message from: ${MESSAGE(from)})

result in CLI output

 Executing [s@hotdesking:3] NoOp("Message/ast_msg_queue", "Message from: <sip:5556@myserver.nl>”)

Which is OK, the message is send from GS Wave soft phone with extension number 5556 to a GS Wave soft phone on an other iPhone with extension 5554.

If I check the SIP debug output I find

Reliably Transmitting (NAT) to 11.11.111.111:49383:
MESSAGE sip:5554@192.168.1.104:49383 SIP/2.0
Via: SIP/2.0/UDP 111.11.111.111:5060;branch=z9hG4bK405cb5fa;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk@11.11.11.111>;tag=as7b5cb503
To: <sip:5554@192.168.1.104:49383>
Contact: <sip:asterisk@11.11.11.111:5060>
Call-ID: 004d53e06a13d15c6b5bc8395ec84a06@11.11.11.111:5060
CSeq: 102 MESSAGE
User-Agent: Asterisk PBX 13.11.2
Content-Type: text/plain;charset=UTF-8
Content-Length: 76

This is a Message to test if the message will be delivered at extension 5554

GS Wave softphone shows a pop up message:

Receive message from Asterisk (asterisk)
Account: 5554
Content: <message>

The message is received under the name asterisk and the result is that it is not possible to answer the message from the 5554 extension.

I tried this:

exten => s,n, SipAddHeader(P-Preferred-Identity:  ${MESSAGE(from)} )

and it resulted in this CLI output:

    -- Executing [s@hotdesking:6] SIPAddHeader("Message/ast_msg_queue", "P-Preferred-Identity:  <sip:5556@myserver.nl> “)

But this doesn’t seem to have any effect on from field of the SIP message.

It feels I’m almost there, but is there a way to change the from: field in the sip message or another way to solve this? I assume that the asterisk@myserver.nl from field is the reason that the message is received with asterisk as the sender instead of the phone number. Thanks in advance.
/EdW

The MessageSend application[1] allows specifying the From.

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

1 Like

It is up and running. Thanks a lot! Just one more very last message related question. Is there a simple way to actually queue messages that couldn’t be delivered because the extension for the message was not registered at the moment the message was send. I did some searches but nothing pointing to a solution showed up. Thanks in advance.

There is no built in mechanism to explicit do this. You would need to build one.

Just another challenge. :slight_smile:

Hi Guys

I’ve have read your article, and I would like to understand in respect to the SIP INFO:

a) via the java fastagi or ami is it possible to retrieve a sip info header sent to an asterisk instance. if so how can could I do this via agi/ami.

b) if not how can I get the access to the info information?