Get variable answeredtime -- help

Hi,

execute_agi(‘STREAM FILE you-entered “”’);
execute_agi(‘STREAM FILE goodbye “”’);
$rc = execute_agi("GET VARIABLE ANSWEREDTIME ");
file_get_contents(“http://localhost/mclapi/newd.php?call=".$rc[‘data’]."”);
execute_agi(‘HANGUP’);

I am trying to pass the total answered call duration to a URL, the url is called but i cannot access the duration.
Can someone please show me a code that gets the ANSWEREDTIME?

Thanks Alot
Michael

If you need the total call duration, after it got bridged you should use at billsec CDR entry.

Hi,

Id the any way to get this done using phpagi?

Michael

I suppose… It should be something like get_variable(‘CDR(billsec)’).

Hi,

Thanks for that. i get this result when i use ‘CDR(billsec)’

newz.php: Array
newz.php: (
newz.php: [code] => 200
newz.php: [result] => 1
newz.php: [data] => 0
newz.php: )

When i use $totaltime=$AGI->get_variable(“ANSWEREDTIME”); i get
newz.php: Array
newz.php: (
newz.php: [code] => 200
newz.php: [result] => 0
newz.php: [data] =>
newz.php: )

The call record on my phone is 13secs, i want to be able to capture that.
Is this possible?

Michael

Actually you should use get_variable(‘CDR(billsec)’, true) to get the data returned, instead of an array. As far as I remember to get the accurate billsec you should do this after the channel has been hung up.

Hi,

Please view my code, i am still kinda new to this so maybe you can point out my mistake

CODE
set_time_limit(30);
require(‘phpagi.php’);
error_reporting(E_ALL);
$agi = new AGI();
$agi->answer();

$cid = $agi->parse_callerid();
$agi->stream_file(“please-enter-your-extension-then-press-pound”,"#");
$result = $agi->get_data(“beep”, 9000, 20);
$agi->verbose($result);
$keys = $result[‘result’];
$agi->stream_file(“you-entered”);
$agi->say_digits($keys);
$agi->stream_file(‘thank-you-for-calling’);
$agi->stream_file(‘goodbye’);
$agi->hangup();
$vv=$agi->get_variable(‘CDR(billsec)’,true);
$agi->verbose($vv);

OUTPUT
– Attempting call on SIP/XXXXX/08098009386 for application AGI(newz.php) (Retry 1)
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
== Using SIP VRTP TOS bits 136
== Using SIP VRTP CoS mark 6
> Channel SIP/XXXX-0000006a was answered.
> Launching AGI(newz.php) on SIP/XXXX-0000006a
– Launched AGI Script /var/lib/asterisk/agi-bin/newz.php
– Playing ‘please-enter-your-extension-then-press-pound’ (escape_digits=#) (sample_offset 0)
– <SIP/MCL_GW-0000006a> Playing ‘beep.gsm’ (language ‘en’)
newz.php: Array
newz.php: (
newz.php: [code] => 200
newz.php: [result] => 5555
newz.php: [data] =>
newz.php: )
newz.php:
– Playing ‘you-entered’ (escape_digits=) (sample_offset 0)
– <SIP/MCL_GW-0000006a> Playing ‘digits/5.gsm’ (language ‘en’)
– <SIP/MCL_GW-0000006a> Playing ‘digits/5.gsm’ (language ‘en’)
– <SIP/MCL_GW-0000006a> Playing ‘digits/5.gsm’ (language ‘en’)
– <SIP/MCL_GW-0000006a> Playing ‘digits/5.gsm’ (language ‘en’)
– Playing ‘thank-you-for-calling’ (escape_digits=) (sample_offset 0)
– Playing ‘goodbye’ (escape_digits=) (sample_offset 0)
trixbox1*CLI>

I dont get see the value of (‘CDR(billsec)’,true) in the debug information.
What am i doing wrong?

Michael

I meant calling the AGI script from the dialplan after the hangup (h extension). Haven’t done this in quite a while. I’m gonna have to check my implementations to give you a better example.

Hi,

This is what i want to do:

  1. Trigger a Call using a call file
  2. Take a 4 digit PIN
  3. Say good by
  4. Send PIN/Call Duration/Call Status to a URL.
  5. END

Just so you have a clear picture of what i am trying to achieve.

Michael