Re: [Asterisk-java-users] Originate a call, play recordings, and interact with callee
Brought to you by:
srt
From: Patrick A. <pat...@gm...> - 2012-09-24 00:11:57
|
Hi, I am going to go with the following solution. I'll just store the failed IP addresses in a map and originate the call. All the logic will be in the dialplan. Here is my mock extensions.conf: [phones] exten => 1000,1,Dial(SIP/1000) exten => 1000,n,Hangup() exten => 1001,1,Dial(SIP/1001) exten => 1001,n,Hangup() exten => 1002,1,Dial(SIP/1002) exten => 1002,n,Hangup() [wanmonitor] exten => s,1,Answer() same => n,Wait(1) same => n,Background(ThisIsTheWanMonitorIvr) same => n,SayNumber(${nonResponders}) same => n,Background(OutOf) same => n,SayNumber(${monitoredDevices}) same => n,Background(IpDevicesNotResponding) same => n(PressOneToList),Background(PressOneToList) same => n,WaitExten(7) same => n,Goto(wanMonitorByeBye,1) exten => 1,1,Set(X=1) same => n,Verbose(1,IP Addresses is: ${ipAddresses}) same => n,Set(ip=${CUT(ipAddresses,-,${X})}) same => n,Verbose(1,IP is: ${ip}) same => n,While($[${EXISTS(${ip})}]) same => n,Background(${ip}) same => n,Set(Y=1) same => n,Set(part=${CUT(ip,.,${Y})}) same => n,Verbose(1,Part is: ${part$}) same => n,While($[${EXISTS(${part})}]) same => n,SayNumber(${part}) same => n,Set(Y=${INC(Y)}) same => n,Set(part=${CUT(ip,.,${Y})}) same => n,EndWhile() same => n,Set(X=${INC(X)}) same => n,Set(ip=${CUT(ipAddresses,-,${X})}) same => n,EndWhile() same => n,Goto(wanmonitor,s,PressOneToList) exten => 2,1,Playback(AllFailuresAcknowledged) same => n,Goto(wanMonitorPost,1) exten => 3,1,Playback(KeyTheNumberOfHoursToSuspendMonitoring) same => n,Read(hoursKeyed,,2) same => n,Verbose(1,Hours keyed by user: ${hoursKeyed}) same => n,Playback(AllFailuresAcknowledged) same => n,Playback(AndSuspendedFor) same => n,ExecIf($[${hoursKeyed} = 0]?Playback(ZeroHours)) same => n,ExecIf($[${hoursKeyed} = 1]?Playback(OneHour)) same => n,ExecIf($[${hoursKeyed} > 1]?SayNumber(${hoursKeyed})) same => n,ExecIf($[${hoursKeyed} > 1]?Playback(Hours)) same => n,Goto(wanMonitorPost,1) exten => i,1,Playback(InvalidSelection) same => n,Goto(wanmonitor,s,1) exten => t,1,Goto(wanMonitorByeBye,1) exten => wanMonitorByeBye,1,Verbose(1,WAN monitor playing bye bye and hanging up) same => n,Playback(ByeBye) same => n,Wait(1) same => n,Hangup() exten => wanMonitorPost,1,Verbose(1,WAN monitor posting result) same => n,Set(response=${CURL(http://pla1.net/SnoopServlet?phoneNumber=${phoneNumber}&hours=${hoursKeyed})}) same => n,Goto(wanMonitorByeBye,1) Here is the Java source: package com.pla.ivr; import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.Map; import org.asteriskjava.manager.AuthenticationFailedException; import org.asteriskjava.manager.ManagerConnection; import org.asteriskjava.manager.ManagerConnectionFactory; import org.asteriskjava.manager.TimeoutException; import org.asteriskjava.manager.action.OriginateAction; import org.asteriskjava.manager.response.ManagerResponse; public class HelloManager { private ManagerConnection managerConnection; public HelloManager() throws IOException { ManagerConnectionFactory factory = new ManagerConnectionFactory("ub-asterisk", "managerusername", "managerpassword"); this.managerConnection = factory.createManagerConnection(); } public void run() throws IOException, AuthenticationFailedException, TimeoutException { OriginateAction originateAction; originateAction = new OriginateAction(); originateAction.setChannel("SIP/1001"); originateAction.setContext("wanmonitor"); originateAction.setPriority(new Integer(1)); originateAction.setTimeout(new Long(30000)); Map<String, String> variables = new HashMap<String, String>(); variables.put("ipAddresses", "10.1.0.138-10.1.0.185-10.1.0.248"); variables.put("monitoredDevices", "120"); variables.put("nonResponders", "3"); variables.put("phoneNumber", "8005551212"); originateAction.setVariables(variables); managerConnection.login(); ManagerResponse response = managerConnection.sendAction(originateAction, 30000); System.out.println("Response: " + response.getResponse()); managerConnection.logoff(); } public static void main(String[] args) throws Exception { System.out.println("Start " + new Date()); HelloManager helloManager; helloManager = new HelloManager(); helloManager.run(); } } Rock on, PLA Patrick L Archibald http://PatrickArchibald.com On Sun, Sep 23, 2012 at 12:22 AM, Patrick Archibald <pat...@gm...> wrote: > Hi, > > I am hoping to replace an AS/400 IVR application with the Asterisk > Manager API. The application is a WAN monitor. When an IP device fails > the IVR calls the administrator of the device. Each administrator can > have up to 4 phone numbers. Each device has a primary, secondary, and > third administrator. The IVR app rotates through the administrators > and their phone numbers until someone responds. > > I understand that the OriginateAction can connect to an extension or > an application. I have successfully called extension 1000 and played > back a recording the the following bit of code. > > OriginateAction originateAction = new OriginateAction(); > originateAction.setChannel("SIP/1000"); > originateAction.setApplication("Playback"); > originateAction.setData("Press1ToListPress2ToAckAllPress3ToAckForAnHourOrMore"); > managerConnection.login(); > ManagerResponse response = managerConnection.sendAction(originateAction); > > How can I retrieve the digit entered by the callee and play back the > next recording based on that input? How can I interact with the > callee? > > Thanks in advance! > > Rock on, PLA > > Patrick L Archibald > http://PatrickArchibald.com |