tags:

views:

437

answers:

2

I'm developing an application with PHP and a Asterisk Server. One of the features of the application is to check the call status (ringing, answered, hung...) of an specific caller ID, so I would like to know how to do this, because I'm trying with a socket and the command status but I think it has to be a better way to do it.

Thanks in advance.

+1  A: 

What API are you using to write this program? AMI? AGI? FastAGI? DeadAGI? Call files? There's a lot of ways to get this information.

NOTE: You cannot tell if a channel has been hungup unless you are using call files and/or CDR access.

With the AMI, you can use the Status command (documented here: http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Status).

With the AGI, you will know the status as it is determined by your program. If you are still in your AGI script, then the call is still in progress and already answered.

If you are using call files, and you have the Archive attribute set to 'yes', then once the call has completed then you can check your outoing_done directory (typically /var/lib/asterisk/outgoing_done/) for your call file. When you read the callfile, you'll notice that Asterisk has appended a status at the bottom of the call file, which will tell you the final status of the call.

The BEST way to get this information is by having your PHP script read from the CDR records on your Asterisk server. Have your CDR records log to a MySQL database, then pull records for your call from the database.

b14ck
Ok... here is the thing. I receive the called ID as a GET parameter from de URL (`$_GET['calledID']`). I need to get the call status of that caller id. (I'm not making a call using PHP)
Harph
Since you don't have the channel ID of the call, there is no way to directly get this information. You have to instead use the Asterisk CDR database. If you have your CDR logs going to a database (typically MySQL) then just have your PHP script connect to the SQL db and perform a query for the callerID you have from your script. Find the last call made by the given caller ID using a SELECT statement. Then just extract the information you need (like call time, end of call time, call state, etc.)
b14ck
Yeah, you're right, I can get the status of the call using the CDR log Data Base, but this just works when the call has finished, because the log record is created when the call ends. I need to get the status on real time using the variables that the phone can send me through the URL. Any idea?
Harph
+1  A: 

Harph,

You can create an AMI daemon to listen to AMI events streamed from Asterisk. I've done this many times, one of those being for the Asterisk GUI. If you create a table for status in your database, you can create a daemon to listen to the AMI events and update the status as they happen. Then your webpage won't have to interact with Asterisk at all, it'll just need to read the status from the database.

The following link is from the Asterisk GUI project. It is written in javascript, so your php would be a little different, but this will give you a good base to start with. Start with line 574.

http://svn.asterisk.org/view/asterisk-gui/branches/2.0/config/js/welcome.js?view=markup

One of the key differences in javascript vs php is that javascript has to use Asterisk's http daemon instead of a socket connection straight to AMI. Because of this it has to use the 'waitevent' stuff. But since you'll be using a TCP socket connection, just keep looping a read statement.

Hope this helps! This method seems to be the most reliable when trying to get information from Asterisk.

ocdcoder