Ring detection on SIP Channel

Hello All,

   I am a new user of asterisk. I am trying to make automated calls using Asterisk Manager API by Originate command and it is working fine when I call to SIP Number but when I make a call to PSTN number I got some strange behavior that Asterisk assumes the call as Answered just after dialing even though the phone is ringing or busy.
  And thats why the prerecorded message starts playing and the table entry shows the call as answered and deduct the money from the users account.
 Also when I run "SIP debug" command on CLI to debug the SIP message I got the following difference on calling to SIP number and PSTN number

To know more about SIP messages see this link [url]http://www.cyber-cottage.co.uk/wiki/index.php/SIP_messages[/url]

When I call to SIP number the Asterisk places the request (INVITE message) to the Gizmo Server then Gizmo reply as follows
100 Trying
180 Ringing
200 OK (When we pick up the call)

But when I call to PSTN number the Asterisk places the request (INVITE message) to the Gizmo Server then Gizmo reply as follows
100 Trying
200 OK (Even when we didn’t pick up the call and the mobile shows it as missed call)
Also 180 Ringing message is missing.
Now I saw that as Asterisk got the 200 OK message it assumes the call as Answered. So when I call to the SIP number it behaves well but when I call to PSTN number it gives us the wrong status and assumes the call as answered even the phone is ringing.

Is there any way to correct this or there is some application which can detect ringing and other tones on line. I found one application NVLineDetect by Newman Telecom at [url]http://www.voip-info.org/wiki/view/NVLineDetect[/url]

which says it can detect Answer, Ring, Busy etc on Line. But when I mailed to them for the code they didn’t reply to me.

So if any one have some clue to this application or some other application like this then please tell me. I am very thankful to him.

Please help me out in this matter. Thanks in Advance. And also Sorry for my poor english


Zap calls are considered ‘answered’ by asterisk once asterisk sends it over to the zap channel. Some users are fortunate to have true answer supervision with their telco, then you can use answeronpolarityswitch=yes in your zapata conf file.
Otherwise, you can use Backgrounddetect. Set the duration of nonsilence to 5 ms to detect the ring, and the duration of silence to greater than the time between rings (4000 ms in usa so try 4300).
Now your dial plan will proceed after the call is answered and there is at least 4300 ms of silence.
You can play a sound file that says please wait for my message, please wait for my message, …etc to make sure they don’t hang up early. Make sure to use an absolute timeout which can be cancelled later, or the phone might ring for a really long time!