receive events

Example: Generate CDR for an outbound call based on call events

In this case, we will create a script cdrlog to generate CDR(call record details), the script will receive call events, based on these events we can create/update CDRs. The script is written in php and we use MySql database.

  • Call process:
    1. Agent tell asterCC that I want to dial number XXXX
    2. asterCC will originate a call to agent first, agent phone ring
    3. Agent answers (legA)
    4. asterCC will originate a call to number XXXX (legB)
    5. (when agent answered)Customer phone ring(the call bridged, create a CDR)
    6. Customer answered(call is answered, update CDR)
    7. When agent or customer hangeup, the call is finished(call hangup, update CDR)
  • Scenario Analysis: An outbound call is that agent call customer, so we will know(when agent login)
    • Agent number $agentno
    • The phone number bind to the agent $agentphone
    • Team identity $orgidentity
  • Events: A complete call is composed by several events, they have same “sessionid” during the call, sessionid is the identity for a call

source+event could describe the call status

The script will process call events, when it receive a “ringing” event, it will create a new CDR, when receive another event, it will update the record

function cdr() {
if($data ['calltype'] == ‘dialout’){
	//outbound call event
	 if($data['source'] == 'CALLEE' && $data['event'] == 'ringing'){
		//agent dial out, customer ring, call start
	$src = (string)$agentphone; //legA, agent number
	$dst = (string)$data['activenum'];//dialed number
	$starttime = $data['eventTime'];//ringing time is start time
	$disposition = 'NOANSWER';//ringing means no answer yet
	$target = 'DialOut';//it's a outbound call
	$diallogid = $data['sessionid']; //identity of the call
	$agentno;//agent number
		$orgidentity;//team identity
		If(!(SELECT * FROM `your cdr table` WHERE diallogid=$diallogid limit 1;)){
			//check if the record exists, if no, we create a new CDR, just in case we received duplicated events
			INSERT INTO `your cdr table` SET `variables above`;//save to database
}else if($data['source'] == 'CALLEE' && $data['event'] == 'answer'){
	//customer answered, we need to update CDR
  $disposition = 'ANSWER';//update call status
  $answertime =$data['eventTime'];//update answered time
  UPDATE  scenario WHERE diallogid=$diallogid limit 1;
}else if($data['source'] == 'CALLEE' && $data['event'] == 'hangup'){
	$endtime =$data['eventTime'];//end time
  UPDATE  scenario WHERE diallogid=$diallogid limit 1;


  • config post url in astercc

To receive call events for a team, you need to go to Team → Advanced, “Push event URL:” = your script address, like

restart astercc daemons

/etc/init.d/asterccd restart

en/custom_development_guide/apis/receive_call_events_via_http_post.txt · Last modified: 2014/11/27 03:32 by solo
Recent changes RSS feed Debian Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki