AMI > Abandoned Call Report

Whenever a call is abandoned, I need to capture the following information:

  1. Queue number
  2. Extensions logged into the queue
  3. Current state of each extension (busy, available, not logged in etc)
  4. Caller id of the abandoned call
  5. Wait time before the call was abandoned

What is the best way to get this data? Can an AMI script do this?

Looking for some directions to get started.

Thanks!!

https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerEvent_QueueCallerAbandon

https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+ManagerAction_Agents

Unless the Sangoma commercial Queue Management module provides it, you’re going to probably end up grovelling through the interface @comtech recommends.

Thanks @comtech . I believe you have shared really good pointers to get started. I think I’ll be able to get almost all the information I need.

I’ll post my script in this thread if it helps others.

Thanks!!

1 Like

Here is my script. I hope it helps someone!!


error_reporting(E_ALL);

$msg = "";

//CONNECTION TO THE AMI SERVER TO LISTEN TO EVENTS FROM ASTERISK
$socket = fsockopen("127.0.0.1","5038", $errno, $errstr, 10);
if (!$socket)
{
	echo "$errstr ($errno)\n";
}
else
{
fputs($socket, "action: login\r\n");
fputs($socket, "username: admin\r\n");
fputs($socket, "secret: secret\r\n\r\n");
fputs($socket, "action: Waitevent\r\n");
$wrets=fgets($socket,128);

$found = false;

while(!feof($socket))
{
	$buffer = fgets($socket,4096);
	if(strpos($buffer, "QueueCallerAbandon"))
	{
		$found = true;
		$msg = "+++++++++++++++++++++++++++++\n";
		$msg .= "Call Abandoned: " .  date("d M, h:i:s T") . "\n\n";
	}

	if($found)
	{
		if(preg_match("/^Channel:/", $buffer))
		{
			$msg .= $buffer;
		}
		if(preg_match("/^ChannelStateDesc:/", $buffer))
		{
			$msg .= $buffer;
		}

		if(preg_match("/^CallerIDNum:/", $buffer))
		{
			$msg .= $buffer;
		}

		if(preg_match("/^CallerIDName:/", $buffer))
		{
			$msg .= $buffer;
		}

		if(preg_match("/^Queue:/", $buffer))
		{
			$msg .= $buffer;
			$xx = explode(":", $buffer);
			$queueNo = trim($xx[1]);
		}

		if(preg_match("/^Position:/", $buffer))
		{
			$msg .= $buffer;
		}

		if(preg_match("/^OriginalPosition:/", $buffer))
		{
			$msg .= $buffer;
		}

		if(preg_match("/^HoldTime:/", $buffer))
		{
			$msg .= $buffer;
		}


		//CHECK FOR A BLANK LINE TO FIND END OF EVENT
		if(strlen(trim($buffer))==0)
		{
			$sub = "Call Abandoned: Queue: " . $queueNo . ": " . date("Y-m-d H:i T");
			$msg .= "End of Call Abandoned Report for Queue " . $queueNo . "\n";
			$msg .= "+++++++++++++++++++++++++++++\n\n\n";
			$msg .= checkQueueMembers($queueNo);

				// SEND EMAIL VIA CURL POST
				// echo $msg;
				// SEND EMAIL VIA CURL POST
			$found = false;
		}
	}
}
}

fclose($socket);




function checkQueueMembers($exten)
{
	//CONNECTION TO THE AMI SERVER TO LISTEN TO EVENTS FROM ASTERISK
	$socket1 = fsockopen("127.0.0.1","5038", $errno, $errstr, 10);
	if (!$socket1)
	{
	     echo "$errstr ($errno)\n";
	}
	else
	{
		fputs($socket1, "action: login\r\n");
		fputs($socket1, "username: admin\r\n");
		fputs($socket1, "secret: secret\r\n\r\n");
		fputs($socket1, "Action: QueueStatus\r\n");
		fputs($socket1, "Queue: ".$exten."\r\n\r\n");
		$wrets=fgets($socket1,128);
		
		$foundQueueStatus = false;

		while(!feof($socket1))
		{

			$buffer1 = fgets($socket1,4096);

			if(preg_match("/Queue status will follow/", $buffer1))
			{
				$foundQueueStatus = true;
			$msgQueueStatus = "+++++++++++++++++++++++++++++\n";
			$msgQueueStatus .= "Queue Members: " .  date("d M, h:i:s T") . "\n\n";
		}

		if($foundQueueStatus)
		{
			if(preg_match("/^Name:/", $buffer1))
			{
				$msgQueueStatus .= $buffer1;
			}
			if(preg_match("/^CallsTaken:/", $buffer1))
			{
				$msgQueueStatus .= $buffer1;
			}
			if(preg_match("/^LastCall:/", $buffer1))
			{
				$msgQueueStatus .= $buffer1;
			}
			if(preg_match("/^InCall:/", $buffer1))
			{
				$msgQueueStatus .= $buffer1;
			}
			if(preg_match("/^Status:/", $buffer1))
			{
				$msgQueueStatus .= $buffer1;
				$xx = explode(":", $buffer1);
				if($xx[1] == 0)		$msgQueueStatus .= "Extn status: UNKNOWN\n";
				if($xx[1] == 1)		$msgQueueStatus .= "Extn status: NOT_INUSE\n";
				if($xx[1] == 2)		$msgQueueStatus .= "Extn status: INUSE\n";
				if($xx[1] == 3)		$msgQueueStatus .= "Extn status: BUSY\n";
				if($xx[1] == 4)		$msgQueueStatus .= "Extn status: INVALID\n";
				if($xx[1] == 5)		$msgQueueStatus .= "Extn status: UNAVAILABLE\n";
				if($xx[1] == 6)		$msgQueueStatus .= "Extn status: RINGING\n";
				if($xx[1] == 7)		$msgQueueStatus .= "Extn status: RINGINUSE\n";
				if($xx[1] == 8)		$msgQueueStatus .= "Extn status: ONHOLD\n";

				$msgQueueStatus .= "----------\n";
			}

			//CHECK FOR END OF QUEUESTATUS
			if(preg_match("/^Event: QueueStatusComplete/", $buffer1))
			{
				$msgQueueStatus .= "End of Queue Member Report for Queue " . $exten . "\n";
				$msgQueueStatus .= "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n";
				$foundQueueStatus = false;
				fclose($socket1);
				return $msgQueueStatus;
			}
		}
		
	}
}
}
?>
2 Likes

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.