Greetings Asterisk community,
I have to create standalone tool to archive Calls with it’s own database,
I am looking to do it on real time, so I select using AMI to do this.
Following code give me some of needs , but still miss call duration , and real caller:
public class Ast implements ManagerEventListener
{
private ManagerConnection managerConnection;
public Ast() throws IOException
{
ManagerConnectionFactory factory = new ManagerConnectionFactory(
"x.xx.xx", "xxxx", "xxx");
this.managerConnection = factory.createManagerConnection();
}
public void run() throws IOException, AuthenticationFailedException,
TimeoutException, InterruptedException
{
// register for events
managerConnection.addEventListener(this);
// connect to Asterisk and log in
managerConnection.login();
// request channel state
managerConnection.sendAction(new StatusAction());
// wait 10 seconds for events to come in
Thread.sleep(1000000000);
// and finally log off and disconnect
managerConnection.logoff();
}
public static void main(String[] args) throws Exception
{
Ast helloManager;
helloManager = new Ast();
helloManager.run();
}
public void onManagerEvent(ManagerEvent event)
{
System.out.println(" MAnager E "+event);
if(event instanceof CdrEvent){
//System.out.println(event);
CdrEvent ev = (CdrEvent)event;
System.out.println("caller ID "+ev);
}
}
}
Result is :
org.asteriskjava.manager.event.HangupEvent[dateReceived=‘Wed Apr 19 12:51:32 GST 2017’,privilege=‘call,all’,server=null,calleridname=‘Ahmad Osman’,channel=‘SIP/111-00000012’,cause=‘16’,connectedlinename=‘Ahmad Albat’,sequencenumber=null,calleridnum=‘111’,causetxt=‘Normal Clearing’,callerid=‘111’,connectedlinenum=‘225’,uniqueid=‘1492591874.18’,timestamp=null,systemHashcode=906972885]
org.asteriskjava.manager.event.HangupEvent[dateReceived=‘Wed Apr 19 12:51:32 GST 2017’,privilege=‘call,all’,server=null,calleridname=‘Ahmad Albat’,channel=‘SIP/225-00000011’,cause=‘16’,connectedlinename=‘Ahmad Osman’,sequencenumber=null,calleridnum=‘225’,causetxt=‘Normal Clearing’,callerid=‘225’,connectedlinenum=‘111’,uniqueid=‘1492591874.17’,timestamp=null,systemHashcode=1289092090]
Give me advice to get the required data.
Best Regards