[asterisk-users] How to send a SIP MESSAGE outside a call
Matthew Jordan
mjordan at digium.com
Sun Jul 29 17:24:18 CDT 2012
----- Original Message -----
> From: "Tiago Vasconcelos" <tiago.o.vasconcelos at gmail.com>
> To: asterisk-users at lists.digium.com
> Sent: Sunday, July 29, 2012 4:19:00 PM
> Subject: Re: [asterisk-users] How to send a SIP MESSAGE outside a call
>
>
> Matthew, you used the name "send_msg" which I found confusing since
> extensions.conf is the dialplan configuration file. So an "exten =>"
> is
> triggered by either an outbound or an inbound call.
> I admit I may be ignorant, so could you please clarify how the
> message
> sending code you wrote above fits in the dialplan? How can it be
> triggered other than by an inbound/outbound call?
send_msg is an extension. Extensions don't have to be numeric. I put
it in a 'send_msg' extension because its a fictitious example of using
the MessageSend application. You can use the MessageSend application
in any place in the dialplan.
> Since I didn't figure another way to do it, I associated your code
> with
> an extension. The idea was when the 101 extension is dialled, the SIP
> MESSAGE is sent to the provider:
>
> exten => 101,1,NoOp()
> same =>
> n,Set(MESSAGE_DATA(X-Movial-Content)=application/x-movial-control;forwarding=true)
> same => n,MessageSend(sip:54395135465 at provider)
>
> But when I test it I get two errors:
>
> -- Executing [101 at house:1] NoOp("SIP/me1-0000000e", "") in new
> stack
> -- Executing [101 at house:2] Set("SIP/me1-0000000e",
> "MESSAGE_DATA(X-Movial-Content") in new stack
> [Jul 29 21:09:25] WARNING[32728]: pbx.c:10208 pbx_builtin_setvar: Set
> requires an '=' to be a valid assignment.
> -- Executing [101 at house:3] MessageSend("SIP/me1-0000000e",
> "sip:54395135465 at provider") in new stack
> [Jul 29 21:09:25] WARNING[32728]: message.c:992 msg_send_exec: No
> message data found on channel to send.
Heh. A ';' is a special character in the dialplan (denoting a comment) -
sorry about that! You'll need to escape the semicolon.
Here's a dialplan I used to construct your scenario:
[general]
[default]
exten => send_msg,1,NoOp()
same => n,Answer()
same => n,Set(MESSAGE_DATA(X-Movial-Content)=application/x-movial-control\;forwarding=true)
same => n,MessageSend(sip:127.0.0.1:5060)
same => n,Hangup()
Note that this is going to send the SIP MESSAGE request to the local
instance of Asterisk that I'm running, which it won't like as I haven't
specified an extension for it to enter to, and my dialplan doesn't have
an 's' extension. However, all I'm looking to show here is that Asterisk
*sends* the SIP MESSAGE request. To do that, I'll originate a Local channel
to run the dialplan at extension send_msg. We can see the results with
'sip set debug on':
*CLI> sip set debug on
SIP Debugging enabled
*CLI> channel originate Local/send_msg at default application Echo
-- Executing [send_msg at default:1] NoOp("Local/send_msg at default-2578;2", "") in new stack
-- Executing [send_msg at default:2] Answer("Local/send_msg at default-2578;2", "") in new stack
ast_read() on chan 'Local/send_msg at default-2578;1' called with no recorded file descriptor.
*CLI> -- Launching Echo() on Local/send_msg at default-2578;1
-- Executing [send_msg at default:3] Set("Local/send_msg at default-2578;2", "MESSAGE_DATA(X-Movial-Content)=application/x-movial-control;forwarding=true") in new stack
-- Executing [send_msg at default:4] MessageSend("Local/send_msg at default-2578;2", "sip:127.0.0.1:5060") in new stack
Reliably Transmitting (NAT) to 127.0.0.1:5060:
MESSAGE sip:127.0.0.1:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bK6f1bb6cf;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk at 127.0.0.1>;tag=as34427565
To: <sip:127.0.0.1:5060>
Contact: <sip:asterisk at 127.0.0.1:5060>
Call-ID: 2015a6b01c3585d52096aae73230bfd7 at 192.168.0.103:5060
CSeq: 102 MESSAGE
User-Agent: Asterisk PBX SVN-branch-10-r370495M
X-Movial-Content: application/x-movial-control;forwarding=true
Content-Type: text/plain;charset=UTF-8
Content-Length: 0
---
<--- SIP read from UDP:127.0.0.1:5060 --->
MESSAGE sip:127.0.0.1:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bK6f1bb6cf;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk at 127.0.0.1>;tag=as34427565
To: <sip:127.0.0.1:5060>
Contact: <sip:asterisk at 127.0.0.1:5060>
Call-ID: 2015a6b01c3585d52096aae73230bfd7 at 192.168.0.103:5060
CSeq: 102 MESSAGE
User-Agent: Asterisk PBX SVN-branch-10-r370495M
X-Movial-Content: application/x-movial-control;forwarding=true
Content-Type: text/plain;charset=UTF-8
Content-Length: 0
<------------->
--- (12 headers 0 lines) ---
Receiving message!
Scheduling destruction of SIP dialog '2015a6b01c3585d52096aae73230bfd7 at 192.168.0.103:5060' in 32000 ms (Method: MESSAGE)
No matching peer for 'asterisk' from '127.0.0.1:5060'
-- Executing [send_msg at default:5] Hangup("Local/send_msg at default-2578;2", "") in new stack
== Spawn extension (default, send_msg, 5) exited non-zero on 'Local/send_msg at default-2578;2'
Looking for s in default (domain 127.0.0.1)
So: in your particular dialplan, you should be able to escape
the semicolon and rerun. You should see a SIP MESSAGE request
sent to SIP provider.
--
Matthew Jordan
Digium, Inc. | Software Developer
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com & http://asterisk.org
More information about the asterisk-users
mailing list