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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With