Hi,
I am new to php and have this problem,i cant figure out how to fix it.
I am trying to get the AMI Event AgentCalled and send it via curl to my web server.
My php script
<?php
$host="localhost";
$username="myusername";
$secret="mypassword";
$socket = fsockopen($host,"5038", $errno, $errstr,10);
if (!$socket){
echo "$errstr ($errno)\n";
}else{
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: $username\r\n");
fputs($socket, "Secret: $secret\r\n\r\n");
fputs($socket, "Action: WaitEvent\r\n");
fputs($socket, "Action: Logoff\r\n\r\n");
while(!feof($socket)){
$result=fread($socket,4096);
$r=explode("\n",$result);
print_r($r);
//catch the event name
$event=explode(" ",$r[0]);
echo "Event name1 is $event[1]\n";
//Match the Event
if (preg_match("/AgentCalled/","$event[1]")){
//extract parameters from AgentCalled
foreach( $r as $key=>$value){
echo " $key : $value\n";
}
//clean variables
$Event=cleanstr($r[0]);
$MemberName=cleanstr($r[32]);
$Queue=cleanstr($r[30]);
$CallerIDName=cleanstr($r[6]);
$CallerIDNum=cleanstr($r[5]);
//echo count_chars($member,3);
//clean variables from special characters.We could use trim($var,"\r")
$Event=trim($Event);
$MemberName=trim($MemberName);
$Queue=trim($Queue);
$CallerIDName=trim($CallerIDName);
$CallerIDNum=trim($CallerIDNum);
# Setup request to send json via POST.
$ch = curl_init();
$payload = json_encode( array( "Event"=>$Event,"MemberName"=>$MemberName,"Queue"=>$Queue, "CallerIDName"=> $CallerIDName,"CallerIDNum"=>$CallerIDNum) );
//echo "<pre>$payload</pre>";
curl_setopt($ch, CURLOPT_URL,"https://test.com/api/AgentCalled");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$response = curl_exec($ch);
$result = json_decode($response,true);
curl_close($ch);
echo "eventAgentCalled Hit";
}
continue;
}
// }
}
fclose($socket);
function cleanstr($var){
$var = explode(" ",$var);
$var=$var[1];
return($var);
}
?>
Outcome:
Array
(
[0] => Event: AgentCalled
[1] => Privilege: agent,all
[2] => Channel: SIP/xxxxxxxxxx-0000000f
[3] => ChannelState: 6
[4] => ChannelStateDesc: Up
[5] => CallerIDNum: xxxxxxxxx
[6] => CallerIDName: xxxx\u03a0\u0391\u03a0\u03a0\u0391\u03a3 \u03a7\u03a1\u0397\u03a3\u03a4\u039f\u03a3
[7] => ConnectedLineNum: <unknown>
[8] => ConnectedLineName: <unknown>
[9] => Language: en
[10] => AccountCode:
[11] => Context: ext-queues
[12] => Exten: 595
[13] => Priority: 65
[14] => Uniqueid: 1631432002.27
[15] => Linkedid: 1631432002.27
[16] => DestChannel: Local/1000@from-queue-00000003;1
[17] => DestChannelState: 0
[18] => DestChannelStateDesc: Down
[19] => DestCallerIDNum: +302610639501
[20] => DestCallerIDName: <unknown>
[21] => DestConnectedLineNum: xxxxxxxx
[22] => DestConnectedLineName: xxxxx\u03a0\u0391\u03a0\u03a0\u0391\u03a3 \u03a7\u03a1\u0397\u03a3\u03a4\u039f\u03a3
[23] => DestLanguage: en
[24] => DestAccountCode:
[25] => DestContext: from-queue
[26] => DestExten: 595
[27] => DestPriority: 1
[28] => DestUniqueid: 1631432003.28
[29] => DestLinkedid: 1631432002.27
[30] => Queue: 595
[31] => Interface: Local/1000@from-queue/n
[32] => MemberName: 1000
[33] =>
[34] =>
)
Event name1 is AgentCalled
0 : Event: AgentCalled
1 : Privilege: agent,all
2 : Channel: SIP/xxxxxxx-0000000f
3 : ChannelState: 6
4 : ChannelStateDesc: Up
5 : CallerIDNum: xxxxxxxx
6 : CallerIDName: xxxxx\u03a0\u0391\u03a0\u03a0\u0391\u03a3 \u03a7\u03a1\u0397\u03a3\u03a4\u039f\u03a3
7 : ConnectedLineNum: <unknown>
8 : ConnectedLineName: <unknown>
9 : Language: en
10 : AccountCode:
11 : Context: ext-queues
12 : Exten: 595
13 : Priority: 65
14 : Uniqueid: 1631432002.27
15 : Linkedid: 1631432002.27
16 : DestChannel: Local/1000@from-queue-00000003;1
17 : DestChannelState: 0
18 : DestChannelStateDesc: Down
19 : DestCallerIDNum: +xxxxxxxxxx
20 : DestCallerIDName: <unknown>
21 : DestConnectedLineNum: xxxxxxxxxxxx
22 : DestConnectedLineName: xxxxxxxx\u03a0\u0391\u03a0\u03a0\u0391\u03a3 \u03a7\u03a1\u0397\u03a3\u03a4\u039f\u03a3
23 : DestLanguage: en
24 : DestAccountCode:
25 : DestContext: from-queue
26 : DestExten: 595
27 : DestPriority: 1
28 : DestUniqueid: 1631432003.28
29 : DestLinkedid: 1631432002.27
30 : Queue: 595
31 : Interface: Local/1000@from-queue/n
32 : MemberName: 1000
33 :
34 :
eventAgentCalled Hit
Everything is working fine.
BUT if i add eventfilter=Event: QueueCallerJoin
in my manager.conf the the outcome is
Array
(
[0] => Event: QueueCallerJoin
[1] => Privilege: agent,all
[2] => Channel: SIP/xxxxxxx-00000019
[3] => ChannelState: 6
[4] => ChannelStateDesc: Up
[5] => CallerIDNum: xxxxxxxxxxx
[6] => CallerIDName: xxx\u03a0\u0391\u03a0\u03a0\u0391\u03a3 \u03a7\u03a1\u0397\u03a3\u03a4\u039f\u03a3
[7] => ConnectedLineNum: <unknown>
[8] => ConnectedLineName: <unknown>
[9] => Language: en
[10] => AccountCode:
[11] => Context: ext-queues
[12] => Exten: 595
[13] => Priority: 65
[14] => Uniqueid: 1631434390.46
[15] => Linkedid: 1631434390.46
[16] => Queue: 595
[17] => Position: 1
[18] => Count: 1
[19] =>
[20] => Event: AgentCalled
[21] => Privilege: agent,all
[22] => Channel: SIP/xxxxxxxxx-00000019
[23] => ChannelState: 6
[24] => ChannelStateDesc: Up
[25] => CallerIDNum: xxxxxxxxx
[26] => CallerIDName: xxxx\u03a0\u0391\u03a0\u03a0\u0391\u03a3 \u03a7\u03a1\u0397\u03a3\u03a4\u039f\u03a3
[27] => ConnectedLineNum: <unknown>
[28] => ConnectedLineName: <unknown>
[29] => Language: gr
[30] => AccountCode:
[31] => Context: ext-queues
[32] => Exten: 595
[33] => Priority: 65
[34] => Uniqueid: 1631434390.46
[35] => Linkedid: 1631434390.46
[36] => DestChannel: Local/1000@from-queue-00000004;1
[37] => DestChannelState: 0
[38] => DestChannelStateDesc: Down
[39] => DestCallerIDNum: +xxxxxxxxx
[40] => DestCallerIDName: <unknown>
[41] => DestConnectedLineNum: xxxxxxxxxxxx
[42] => DestConnectedLineName: xxxxxxx\u03a0\u0391\u03a0\u03a0\u0391\u03a3 \u03a7\u03a1\u0397\u03a3\u03a4\u039f\u03a3
[43] => DestLanguage: en
[44] => DestAccountCode:
[45] => DestContext: from-queue
[46] => DestExten: 595
[47] => DestPriority: 1
[48] => DestUniqueid: 1631434390.47
[49] => DestLinkedid: 1631434390.46
[50] => Queue: 595
[51] => Interface: Local/1000@from-queue/n
[52] => MemberName: 1000
[53] =>
[54] =>
)
Event name1 is QueueCallerJoin
Means i can not catch the AgentCalled Event.
Any help to fix it ???
Thank you