Invoke a function on Asterisk and get response through SIP requests


#1

I have an Asterisk server and a custom developed client for extension registration. And I would like to trigger some function on this Asterisk server by sending a SIP request.
And also I need to get back the result of the executed task to the client application.
In my situation, a direct HTTP request sending is not possible between Asterisk server and the client.
So I require a solution based on SIP itself. Is there any way to do this using SIP OPTIONS, SIP MESSAGE or by means of any other requests?


#2

Why not use AMI to send action to Asterisk and monitor Events?

–Satish Barot


#3

You can send Asterisk SIP MESSAGE messages and take action on them in the dialplan. On a pjsip endpoint, just set “message_context” to a dialplan context like “incoming_messages” or something, then you can use the MESSAGE or MESSAGE_DATA functions to read the contents. You can then do anything the dialplan allows with the data.


#4

Thanks for the quick response. If you can, please provide more details or links about how we construct SIP MESSAGE request , where we include the data for the invocation and also how will be the response


#5

because In our case, we must use a SIP flow for this. clinet and Asterisk server can only communicate via SIP


#6

A SIP MESSAGE looks like any other SIP request. Here’s an example…

      MESSAGE sip:[extn]@[remote_ip]:[remote_port] SIP/2.0
      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
      From: charlie <sip:[service]@[local_ip]:[local_port]>;tag=[call_number]
      To: alice <sip:[extn]@[remote_ip]:[remote_port]>
      Call-ID: [call_id]
      CSeq: 1 MESSAGE
      Max-Forwards: 70
      Contact: <sip:[service]@[local_ip]:[local_port];transport=[transport]>
      Subject: Test
      Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, PRACK, REGISTER, REFER, MESSAGE
      User-Agent: Test
      Content-Type: text/plain
      Content-Length: [len]

      this is a test

Substitute the variables in ‘[]’ with your own values.

You’ll get a 202 response back.