How to terminate incoming call/SIP session? sys.Respond?

Support zone
Post Reply
rybshik
Posts: 33
Joined: Mon Jun 08, 2009 2:20 am

How to terminate incoming call/SIP session? sys.Respond?

Post by rybshik » Sun Feb 08, 2015 3:33 am

I have IpKall DID, which points to my user@sipsorcery.com.

In my dialplan, for incoming calls placed via DID, caller number (CID) and the time of the call are sent out by email.
Then, the call, SIP session and dial plan are to be terminated.

Code: Select all

localTime = System::DateTime.UtcNow.AddMinutes(sys.GetTimezoneOffsetMinutes()).ToString("HH:mm")
caller = req.Header.From.FromURI.User.Trim('1').to_s

sys.Email("user@gmail.com", "Incoming call", "from #{caller},  #{localTime}")

sys.Respond(503, "unavailable")
For some incoming calls, it ends the call and permanently terminates DP, while for others keeps executing DP again and again, 3 times or so. As a result, for the same incoming call, email message is sent (duplicated) 3 times.
How to fix it?

I tried sys.Respond() with 403, 480, 486, 487, 503, 603. Code ‘503’ seems to work slightly better than others (or it may be just a random coincidence), but still, for some calls, DP is executed repeatedly.
.............................................................................................
DialPlan 06:09:20:596 sip1(5232): Call failed with a failure status of TemporarilyUnavailable and Forbidden.
DialPlan 06:09:20:596 sip1(5232): UAS call failed with a response status of 480 and Forbidden.
DialPlan 06:09:20:612 sip1(5232): Dialplan cleanup for <user_name>.
DialPlan 06:09:20:736 sip1(5232): Dial plan execution completed with normal clearing.
DialPlan 06:09:21:516 sip1(5232): Using dialplan default for In call to sip:<user_name>@sipsorcery.com.
NewCall 06:09:21:548 sip1(5232): Executing script dial plan for call to <user_name>
.............................................................................................

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Re: How to terminate incoming call/SIP session? sys.Respond?

Post by Aaron » Mon Feb 09, 2015 9:48 am

Any SIP error response code >= 400 indicates to the caller that the call will not be accepted. The caller may decide to try again if the error response code was something like "486 Busy Here" on the premise that the callee may now be free. But it's bad behaviour to automatically retry the call without human intervention. I have seen other cases where some servers do essentially ignore an error response and just retry the call 3 or more times. I guess their assumption is that the error may be transient. It's a poor assumption and poor behaviour.

You can get the gory details of all the error response codes from here https://tools.ietf.org/html/rfc3261#section-21.

You could try a 6xx response such as "603 Decline" to see if the caller's server treats 6xx any differently to 4xx.

rybshik
Posts: 33
Joined: Mon Jun 08, 2009 2:20 am

Re: How to terminate incoming call/SIP session? sys.Respond?

Post by rybshik » Mon Feb 09, 2015 2:10 pm

Aaron wrote: I have seen other cases where some servers do essentially ignore an error response and just retry the call 3 or more times. I guess their assumption is that the error may be transient. It's a poor assumption and poor behaviour.
In case of such "poor assumption and poor behaviour", will the following scenario necessarily help? First to automatically answer the call and then, after 1-2 sec, send sys.Respond(403) or 503/603. Which code to use to answer the call?

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Re: How to terminate incoming call/SIP session? sys.Respond?

Post by Aaron » Tue Feb 10, 2015 8:22 am

You can't answer a call with sys.Respond.

What you could do is answer by forwarding the call and set a timeout on it to hang up 1s after answering. Of course it won't be a very friendly experience for a genuine caller...

Code: Select all

sys.Dial("music@iptel.org[cd=1]")
See http://www.sipsorcery.com/mainsite/Help/DialPlans for an explanation of the dial string options.

Post Reply