Asterisk AMI 接口整理

来源:互联网 发布:综漫之知世 编辑:程序博客网 时间:2024/05/17 23:28

Asterisk AMI接口整理


将AMI接口整理成自己的一套app,后面开发者不用再熟悉ami接口,调用即可。

public ManagerResponse AMIAPP_CallExtension(String channel,String exten)
throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
//实例化命令响应对象
ManagerResponse response = new ManagerResponse();
//实例化Originate命令对象
OriginateAction originate = new OriginateAction();
// 设置actionid
originate.setActionId(ConnectAMI.getActionID("call"));  
// 设置主叫分机
originate.setChannel("SIP/"+channel);
// 设置路由器
originate.setContext("internal");  
// 设置被叫分机
originate.setExten(exten);
// 设置进入dialplan优先级
originate.setPriority(new Integer(1));
// 设置呼叫超时
originate.setTimeout(new Long(30000));
originate.setCallerId(exten);
// 设置异步才会有结果返回
originate.setAsync(true);  

response = ConnectAMI.getConnect().sendAction(originate);

return response;
}
// 挂断某个通道
public ManagerResponse AMIAPP_Hangup(String channel, Integer cause) throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();
HangupAction hangup = new HangupAction();

hangup.setActionId(ConnectAMI.getActionID("hangup"));
hangup.setChannel("SIP/"+channel);
hangup.setCause(cause);

response = ConnectAMI.getConnect().sendAction(hangup);

return response;
}
//获取指定分机的状态
public ManagerResponse AMIAPP_getExtensionState(String context, String extension) 
throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();
ExtensionStateAction extensionstate = new ExtensionStateAction();

extensionstate.setActionId(ConnectAMI.getActionID("extensionstate"));
extensionstate.setContext(context);
extensionstate.setExten(extension);

response = ConnectAMI.getConnect().sendAction(extensionstate);

return response;
}
// 创建会议室,并添加用户
public ManagerResponse AMIAPP_CreateRoomAddUser(String conference, String exten) 
throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();
OriginateAction originate = new OriginateAction();

originate.setActionId(ConnectAMI.getActionID("conference"));
originate.setChannel("SIP/"+ exten);
originate.setApplication("ConfBridge");
originate.setData(conference);
originate.setTimeout(new Long(30000));
originate.setCallerId("ConferenceRoom_"+conference);
originate.setAsync(true);

response = ConnectAMI.getConnect().sendAction(originate);
return response;
}

// 查询会议室成员
public ManagerResponse AMIAPP_getRoomUserList(String conference) 
throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();
ConfbridgeListAction list = new ConfbridgeListAction();

list.setActionId(ConnectAMI.getActionID("list"));
list.setConference(conference);

response = ConnectAMI.getConnect().sendAction(list);
return response;
}
// 从会议室中踢出一个成员
public ManagerResponse AMIAPP_ConfBridgeKick(String conference, String channel) 
throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();

ConfbridgeKickAction kick = new ConfbridgeKickAction();
kick.setActionId(ConnectAMI.getActionID("kick"));
kick.setConference(conference);
kick.setChannel(channel);

response = ConnectAMI.getConnect().sendAction(kick);

return response;
}
//静音设置
public ManagerResponse AMIAPP_ConfBridgeMute(String conference, String channel) 
throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();

ConfbridgeMuteAction mute = new ConfbridgeMuteAction();
mute.setActionId(ConnectAMI.getActionID("mute"));
mute.setConference(conference);
mute.setChannel(channel);

response = ConnectAMI.getConnect().sendAction(mute);
return response;
}
// 取消静音
public ManagerResponse AMIAPP_ConfbridgeUnmute(String conference, String channel) 
throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();
ConfbridgeUnmuteAction unmute = new ConfbridgeUnmuteAction();

unmute.setActionId(ConnectAMI.getActionID("unmute"));
unmute.setConference(conference);
unmute.setChannel(channel);

response = ConnectAMI.getConnect().sendAction(unmute);

return response;
}
//发送一个CLI命令
public ManagerResponse AMIAPP_CLICommand(String command) throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();
CommandAction commandaction = new CommandAction();

commandaction.setActionId(ConnectAMI.getActionID("commandaction"));
commandaction.setCommand(command);

response = ConnectAMI.getConnect().sendAction(commandaction);
return response;
}
// 获取Asterisk某个配置文件
public ManagerResponse AMIAPP_getConfig(String filename) throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();
GetConfigAction getconfig = new GetConfigAction();

getconfig.setActionId(ConnectAMI.getActionID("getconfig"));
getconfig.setFilename(filename);

response = ConnectAMI.getConnect().sendAction(getconfig);
return response;
}
// 获取某个通道变量
public ManagerResponse AMIAPP_getVal(String channel, String var) throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();
GetVarAction getvar = new GetVarAction();

getvar.setActionId(ConnectAMI.getActionID("getvar"));
getvar.setChannel(channel);
getvar.setVariable(var);

response = ConnectAMI.getConnect().sendAction(getvar);

return response;
}
// 监控某个通道,注意,pathname是linux系统文件路径,默认为.war后缀
public ManagerResponse AMIAPP_MonitorChannel(String channel, String pathname) throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();
MonitorAction monitor = new MonitorAction();

monitor.setActionId(ConnectAMI.getActionID("monitor"));
monitor.setChannel(channel);
monitor.setFile(pathname);

response = ConnectAMI.getConnect().sendAction(monitor);

return response;
}
// 获取family组的key值
public ManagerResponse AMIAPP_DBget(String family, String key) throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();

DbGetAction dbget = new DbGetAction();
dbget.setActionId(ConnectAMI.getActionID("dbget"));
dbget.setFamily(family);
dbget.setKey(key);

response = ConnectAMI.getConnect().sendAction(dbget);

return response ;
}
// 写入数据库值
public ManagerResponse AMIAPP_Dbput(String family, String key, String value) throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();

DbPutAction dbput = new DbPutAction();
dbput.setActionId(ConnectAMI.getActionID("dbput"));
dbput.setFamily(family);
dbput.setKey(key);
dbput.setVal(value);

response = ConnectAMI.getConnect().sendAction(dbput);

return response;
}

public ManagerResponse AMIAPP_DbDel(String family, String key) throws IllegalArgumentException, IllegalStateException, IOException, TimeoutException{
ManagerResponse response = new ManagerResponse();

DbDelAction dbdel = new DbDelAction();
dbdel.setActionId(ConnectAMI.getActionID("dbdel"));
dbdel.setFamily(family);
dbdel.setKey(key);

response = ConnectAMI.getConnect().sendAction(dbdel);

return response;
}
0 0