I want to capture duration, billsec, disposition & calldate and save them in my own custom database table for every outbound call.
The problem is in my update_outbound.php despite having it sleep(5), before querying the cdr table in asteriskcdrdb based on the $(UNIQUEID} value from the dial plan, the querying comes up empty.
This is part of my php script;
$servername = “asterisk-IP-address”;
$username = “name”;
$password = “pass”;
$dbname = “asteriskcdrdb”;
try {
$con = new mysqli($servername, $username, $password, $dbname);
sleep(5);
$sql1 = “SELECT duration, billsec, calldate, disposition FROM cdr WHERE uniqueid=’$unqID’;”;
$result = $con->query($sql1);
$data = $result->fetch_assoc();
if($data){
file_put_contents("/home/mandela/debug.txt",“yes DATA”);
}else{
file_put_contents("/home/mandela/debug.txt",“NO DATA”);
}
$duration = $data[‘duration’];
$billsec = $data[‘billsec’];
$calldate = strtotime($data[‘calldate’]);
$dispo = $data[‘disposition’];
} catch (Exception $e) {
echo "Connection failed: " . $e->getMessage();
}
I have this in my extensions_custom_conf:
[from-internal-custom]
include => outbound
[outbound]
;exten => 701,1,NoOp(Starting outbound call!)
exten => _254XXXXXXXXX,1,NoOp(Starting outbound call!)
same => n,NoOp(Customer number is ${EXTEN})
same => n,NoOp(Calling Extension number is ${CALLERID(num)})
same => n,DumpChan
same => n,NoOp(UNIQUE ID IS ${UNIQUEID})
same => n,AGI(fmscurl.php,${EXTEN},${CALLERID(num)})
same => n,Set(GLOBAL(lastID)=${lastID})
same => n,Set(GLOBAL(agentNo)=${CALLERID(num)})
same => n,Set(GLOBAL(custNo)=${EXTEN})
same => n,NoOp(THIS IS THE LAST ID ${lastID})
same => n,Dial(SIP/${EXTEN},10,U(record-on-answer))
same => n,GotoIf($["${DIALSTATUS}"=“NOANSWER”]?noanswer)
same => n,GotoIf($["${DIALSTATUS}"=“BUSY”]?busy)
same => n(noanswer),NoOp(NO ANSWER REACHED)
same => n,Set(CHANNEL(hangup_handler_push)=run-on-noAnswer-hangup,s,1)
same => n,Hangup
same => n(busy),NoOp(BUSY REACHED)
same => n,Set(CHANNEL(hangup_handler_push)=run-on-Busy-hangup,s,1)
same => n,MacroExit
[record-on-answer]
exten => s,1,Noop(Entering call record context)
same => n,Monitor(wav,Call-Record,m)
same => n,Set(CHANNEL(hangup_handler_push)=run-on-outbound-hangup,s,1)
same => n,MacroExit
[run-on-outbound-hangup]
exten => s,1,Noop(We are here, after outbound hangup)
same => n,AGI(update_outbound.php,${lastID},${agentNo},${custNo},${UNIQUEID})
same => n,Return
[run-on-noAnswer-hangup]
exten => s,1,AGI(update_outbound.php,${lastID},${agentNo},${custNo},${UNIQUEID})
same => n,Return
[run-on-Busy-hangup]
exten => s,1,AGI(update_outbound.php,${lastID},${agentNo},${custNo},${UNIQUEID})
same => n,Return