Using the AMI (API connection with an Asteriskserver so I can use a PHP Socket connection) I'm trying to catch the recieving data using PHP in a way that I can record outgoing and incomming calls for the CRM system (webbased) used at the company I work for. But I'm not getting the result I am hoping for... The full code can be found on PasteBin http://pastebin.com/AwRNBW2G
I catch the outgoing calls this way, and that works:
if($givenkey = array_search("Context: from-internal", $content)){
$calleridKey = $givenkey + 1;
$idSIP = $givenkey - 1;
$dialNumber = str_replace("Extension: 0","31",$content[$calleridKey]);
$dialNumber = str_replace("Extension: ", "", $dialNumber);
$fromSIP = str_replace("Channel: SIP/", "", $content[$idSIP]);
$fromSIP = substr($fromSIP, 0, 2);
$dialTime = date('r');
$uitgaand = array(
"Phonenumber" => $dialNumber,
"Type" => "Uitgaand",
"datetime" => $dialTime,
"SIP" => $fromSIP
);
T开发者_StackOverflow社区he incomming calls are being catched this way, but that's not working properly:
if($givenkey = array_search("AppData: Using CallerID ", $content)){
if(array_search("Channel: SIP/31000000000", $content)+5 == $InCallKey = array_search("AppData: Using CallerID", $content)){
$calleridNum = explode('"',str_replace('AppData: Using CallerID "',"",$content[$InCallKey]));
$pickupSource = array_search("Source: SIP/31000000000", $content);
if($pickupSource+1 == $pickupKey = array_search("Destination: SIP/", $content)){
$pickupBy = str_replace("Destination: SIP/","",$content[$pickupkey]);
$pickupBy = substr($pickupBy, 0, 2);
$dialTime = date('r');
$inkomend = array(
"Phonenumber" => $calleridNum[0],
"Type" => "Binnenkomend",
"datetime" => $dialTime,
"SIP" => $pickupBy
);
I have the array that I make not available right now but, if necessary, I can save the array and post it here with personal data filtered.
I know that the code I'm using right now is not neat, but I wrote it with the goal: quick result. If I have a working code I will optimize it and clean it up. Tips about this are also very welcome. It's too bad that I cannot find any good documentation about this so I have to start from the beginning and could only find the working class that I'm using right now, however it's not very complete. I had to write this part without any knowledge about VOIP or AMI or Asterisk.
To be short, here are my questions: - How can I record incoming and outgoing calls to eventually save them in a database by using the AMI? - How can I keep alive the connection with the server the best way? The method I'm using now is not optimal as the connection fails atleast once within 48 hours. - Do you have tips or suggestions about optimizing the code and neater code-writing? And do you maybe know any functions that I could use instead of a function that I am using?
With regards, Dempsey
Since recently I get this error which I cannot solve properly. This error creates itself after about 15 minutes running. It would run atleast 24 hours before:
PHP Notice: fwrite(): send of 16 bytes failed with errno=32 Broken pipe in /var/www/html/phpami/AMILoader.php on line 147 Net_AsteriskManagerException: Authorisation failed in /var/www/html/phpami/AMILoader.php on line 173 #0 /var/www/html/phpami/AMILoader.php(173): Net_AsteriskManager-login('GEBRUIKERSNAAM','WACHTWOORD') #1 /var/www/html/phpami/AMILoader.php(306): Net_AsteriskManager-_sendCommand('Action: Ping???...') #2 /var/www/html/phpami/AMILoader.php(543): Net_AsteriskManager->ping() #3 {main}
Can anyone help me with this too? The authorisation data is correct (it is using the same data in the whole script and it does get a connection). Also I don't get the response 'Action: Ping???...' which it says is being send by the script as command, but where do the three questionmarks and periods come from?
this framework should be handy: https://github.com/marcelog/PAMI
otherwise you can check vTiger sources and how it handles ami integration: http://www.vtiger.com/index.php?Itemid=57&id=30&option=com_content&task=view
If your using php, one of the easiest way to connect to the AMI is using the php-astmanager class. It supports callback on certain "events" so that you can catch the data you need. The best (only?) maintained copy is part of FreePBX and can be pulled right out of the latest version (2.9 as of this writing).
精彩评论