Bill an answered call
Well we’ve dialled the destination the user has requested, and when the call has terminated, Twilio did another GET request this time of the call_ended.php script. Since this is an example application, there is no point in showing such a script since I don’t actually do anything with it. Perhaps, sending the call back to the ‘verify_pin.php?Digits=xxxx’ page to ask the user to enter another destination.
The important variable in this part of the application passed back from Twilio is the DialStatus, under which Twillio reported what was the outcome of the call. The DialStatus could be:
| Value | Description |
|---|---|
| answered | The called party answered the call and was connected to the caller |
| busy | Twilio received a busy signal when trying to connect to the called party |
| no-answer | The called party did not pick up before the timeout period passed |
| failed | Twilio was unable to route to this phone number. This is frequently caused by dialing a properly formated, but non-existent phone number. |
One might have already noticed that there is something that is actually missing from the information reported back by Twilio after
Well, that’s pretty much it. I will probably be editing bits and pieces along the next days (I am sure I’ve missed out parts) but what the heck, I hope you got the point!
Is there a way to terminate the call when the user’s prepaid balance reaches $0?
Well the whole point when building such an application is to work pro-actively. When you actually verify the final destination called (in the example here), you should try and figure out what could be the maximum duration of the call based on the destination and his available funds.
Most of the time at this point there is a radius server that performs an Authorisation request. The process however is simple.
Take this for example: I have $5 worth of credit. And I am calling destination +447 which according to my rates costs $0.05/minute. The maximum duration, so that I won’t overcome the $5 credit is 5/0.05 = 100 call minutes. You pass 100*60=6000 seconds as the timeLimit parameter of the Dial Verb and it should terminate the call at exactly 100 minutes.
Reasonably the next question that comes in mind is what do you do if you have two simultaneous callers using the same PIN. Well there are two solutions into this, one easy and one not so easy.
Easy: You mark the PIN while being used as being used, and you don’t let anyone else use it.
Not so easy: You reserve a fund in the PIN beforehand, so that each new PIN usage will find the remaining credit to be ($5 – reservation). You would probably need a b2bua at this point to perform some kind of authorisation requests at specified intervals and terminate the calls when the credit has run out. However this involves Telephony infrastructure that destroy the whole benefit of using Twilio.
Hope I helped
it was very interesting to read.
I want to quote your post in my blog. It can?
And you et an account on Twitter?
Xodov, be my guest! Sorry but I am not using twitter yet