Dial command from AGI, billsec

I have an AGI which is started when a user calls in. AGI asks for destination number and executes
Dial command. After Dial finishes, AGI script catches the sighup to do some cleanup. Is there a way (within the AGI script) to get the billsec variable out of this Dial command?

Thanks.

As I remember duration and billsec CDR variables are available only when call is completed. If you want to get the duration of the dialed call and use it in your AGI script then you can do this:

$start_time=date +%s;
$AGI->exec(‘Dial’,“SIP/$dialnumber”);

and in the sighup handling function you can calculate the dialed duration as below;

$end_time=date +%s;
$dialed_duration=$end_time - $start_time;

[quote=“DanielDegnan”]As I remember duration and billsec CDR variables are available only when call is completed. If you want to get the duration of the dialed call and use it in your AGI script then you can do this:

$start_time=date +%s;
$AGI->exec(‘Dial’,“SIP/$dialnumber”);

and in the sighup handling function you can calculate the dialed duration as below;

$end_time=date +%s;
$dialed_duration=$end_time - $start_time;[/quote]

Actually, the start time would be wrong in your example because you never know how long will the phone will ring
before the call is actually answered (if ever). I found out a solution like:

$AGI->exec(‘Dial’, “SIP/number@provider”);
$billsec = $AGI->get_variable(‘ANSWEREDTIME’);
$dialstatus = $AGI->get_variable(‘DIALSTATUS’);

It works fine, however it is not very clear from the documentation what the ANSWEREDTIME variable
is about. Turns out it holds exactly the value of billsec, which I happen to need.

Thanks anyway.