Re: [Asterisk-java-users] Dialer
Brought to you by:
srt
From: Aaron F. <aa...@la...> - 2007-05-24 15:29:23
|
Wow this looks very comprehensive. I will definitely use it as a starting point. I have a stupid question though (I am new to Trixbox): In FreePBX, how do I tie an extension to an IVR? I have a TestIVR menu that I created. I don't see anywhere in the Extensions menu that I can call TestIVR when an extension is dialed. Thanks for your help on this. In the mean time I am going to play with the code below to get familiar with it. Aaron > -----Original Message----- > From: ast...@li... > [mailto:ast...@li...] On > Behalf Of Carlos G Mendioroz > Sent: Thursday, May 24, 2007 5:01 AM > To: ast...@li... > Subject: Re: [Asterisk-java-users] Dialer > > Aaron, > here's what I do for such context, in case it fits you. > The originate can take a channel (your external dest) and an > extension, which can be tied to (via extensions.conf) to an > AGI script for your IVR. > > I use a function to make the originate: > > public String call(String dest, String dcontext, > String ext, String context, int prio, int to, > String vars) { > OriginateAction originateAction; > ManagerResponse originateResponse; > Thread me = Thread.currentThread(); > String cid = "Failure"; > synchronized(instance) { > originateAction = new OriginateAction(); > originateAction.setChannel("Local/" + > cleanup(dest) + "@" + dcontext); > originateAction.setContext(context); > originateAction.setExten(ext); > originateAction.setPriority(new Integer(prio)); > originateAction.setTimeout(new Long(to * 1000)); > originateAction.setVariable(vars); > callId++; > cid = "auto" + callId; > originateAction.setCallerId(cid); > originateAction.setActionId(cid); > originateAction.setAsync(Boolean.TRUE); > > // send the originate action and wait for a > maximum of 10 seconds for Asterisk > // to send a reply > try { > originateResponse = > > managerConnection.sendAction(originateAction, to * 1000); > } catch (IOException ioe) { > log.warn ("Originate: " + ioe.getMessage()); > return "Failure"; > } catch (TimeoutException toe) { > log.warn ("Originate: " + toe.getMessage()); > return "Failure"; > } > if (!originateResponse.getResponse().equals("Success")) { > log.warn ("Originate: " + > originateResponse.getResponse()); > return "Failed"; > } > callThreads.put(cid, me); > callState.put(cid, "Congestion"); > } // synchro > // Wait for call completion ? > log.debug ("Call " + cid + " waiting"); > synchronized(me) { > while (callThreads.get(cid) != null) { > try { > me.wait(5000); > } catch (InterruptedException ie) {} > } > } > String state = (String)callState.get(cid); > callState.remove(cid); > if (state == null) { > state = "Failure"; > } > log.debug ("Call " + cid + ": " + state); > return state; > } > > I use "Local" channel to reflect the call using whatever > dialing rules you have. cleanup() is just a user destination > phone cleaning like removing spaces and hiphens. > Then, a daemon thread looks for progress and notifies the > calling one of success or failure. The whole thing uses > Hashtables to communicate: > > public void onManagerEvent(ManagerEvent event) > { > if (event.getClass().equals(OriginateSuccessEvent.class)) { > String cid = > ((OriginateSuccessEvent)event).getActionId(); > if (cid != null) { > // Cool, keep waiting progress > log.info ("Call " + cid + " originate ok"); > } > } else if > (event.getClass().equals(OriginateFailureEvent.class)) { > String cid = > ((OriginateFailureEvent)event).getActionId(); > if (cid != null) { > // Oops, this one is not going to make it > log.debug("Call " + cid + " originate failed"); > synchronized(instance) { > Thread owner = (Thread)callThreads.get(cid); > // cleanup > if (owner != null) { > synchronized(owner) { > callThreads.remove(cid); > String ostate = > (String)callState.get(cid); > if (ostate == null || > ostate.equals("Congestion")) > callState.put(cid, "Failed"); > owner.notifyAll(); > } > } > } > } > } else if (event.getClass().equals(NewChannelEvent.class)) { > String chan = ((NewChannelEvent)event).getChannel(); > if (!chan.substring(0,6).equals("Local/")) { > // External calls, auto ? > String cid = > ((NewChannelEvent)event).getCallerIdName(); > if (cid != null && cid.startsWith("auto")) { > if (callIds.get(chan) == null) { > > callIds.put(((NewChannelEvent)event).getUniqueId(), cid); > callIds.put(cid, > ((NewChannelEvent)event).getUniqueId()); > callChannels.put(chan,cid); > callChannels.put(cid, chan); > } > // #4: Change of state > String state = > ((NewChannelEvent)event).getState(); > if (state.equals("Ringing")) { > callState.put(cid, "NoAnswer"); > } else if (state.equals("Busy")) { > callState.put(cid, "Busy"); > } else if (state.equals("Up")) { > callState.put(cid, cid); > } > log.debug ("Call " + cid + " " + state); > } > } > } else if (event.getClass().equals(NewStateEvent.class)) { > String chan = ((NewStateEvent)event).getChannel(); > String uid = ((NewStateEvent)event).getUniqueId(); > if (!chan.substring(0,6).equals("Local/")) { > // External calls, auto ? > String cid = ((NewStateEvent)event).getCallerIdName(); > if ((cid != null && cid.startsWith("auto")) > || callChannels.get(chan) != null > || callIds.get(uid) != null ) { > // Channels do change name in PRI... > if (callChannels.get(chan) == null) { > String ocid = (String)callIds.get(uid); > if (ocid != null) { > String ochan = > (String)callChannels.get(ocid); > if (ochan != null) > callChannels.remove(ochan); > callChannels.put(chan,ocid); > callChannels.put(ocid,chan); > } > if (cid != null && cid.startsWith("auto")) { > > callIds.put(((NewStateEvent)event).getUniqueId(), > cid); > callIds.put(cid, > ((NewStateEvent)event).getUniqueId()); > callChannels.put(chan,cid); > callChannels.put(cid,chan); > } > } > // ZAP changes caller id > cid = (String)callChannels.get(chan); > // #4: Change of state > String state = ((NewStateEvent)event).getState(); > if (state.equals("Ringing")) { > callState.put(cid, "NoAnswer"); > } else if (state.equals("Busy")) { > callState.put(cid, "Busy"); > } else if (state.equals("Up")) { > callState.put(cid, cid); > } > log.debug ("Call " + cid + " chan "+ chan > + ": " + state); > } > } > } else if (event.getClass().equals(RenameEvent.class)) { > String cid = > (String)callChannels.get(((RenameEvent)event).getNewname()); > if (cid != null) { > // we keep cid, and change references... > String oldid = (String)callIds.get(cid); > if (oldid != null) callIds.remove(oldid); > callIds.put(cid, ((RenameEvent)event).getUniqueId()); > callIds.put(((RenameEvent)event).getUniqueId(), cid); > } > } else if (event.getClass().equals(HangupEvent.class)) { > String cid = > (String)callIds.get(((HangupEvent)event).getUniqueId()); > if (cid != null) { > // #4: Hangup (beware of change of Uid!) > // Grr: It seems sometime Uids change > (according to note) but I failed > // to document the case, and it is a fact that > channels do change > // so I'm using now callIds{getUniqueID} instead of > // callChannles{getChannel} to access my call. > If Uids do change, > // we'll have to track renames. -tron 30/3/07 > // Yep, Channels get renamed. Fixed . (3 hours later) > String state = "Hangup: > "+((HangupEvent)event).getCauseTxt(); > String id = (String)callIds.get(cid); > String chan = (String)callChannels.get(cid); > log.info ("Call " + cid + " " + state); > Thread owner = (Thread)callThreads.get(cid); > // cleanup > callIds.remove(id); > callIds.remove(cid); > callChannels.remove(chan); > callChannels.remove(cid); > callThreads.remove(cid); > if (owner != null) { > synchronized(owner) { > owner.notifyAll(); > } > } > } > } > } > > I just fire a bunch of threads for work. Let me know if you > use it and spot any issues... > > -Carlos > > Aaron Freeman @ 24/05/2007 01:42 -0300 dixit: > > OK as I played with it a bit more I sorta answered my own > question. I > > can dial an number by doing this in the setChannel( ... ) method: > > > > originateChannel.setChannel("ZIP/g0/18005551212"); > > > > Now I am trying to figure out how to connect the call to an > IVR when > > they answer the phone ... I am guessing instead of > setExten( ... ) I > > will need setApplication( ... ) so I will try that in the morning. > > > > Thanks, > > > > Aaron > > > >> -----Original Message----- > >> From: ast...@li... > >> [mailto:ast...@li...] > On Behalf > >> Of Stefan Reuter > >> Sent: Wednesday, May 23, 2007 7:29 PM > >> To: ast...@li... > >> Subject: Re: [Asterisk-java-users] Dialer > >> > >> Aaron Freeman wrote: > >>> Is there an example of an application that dials out? Any > >> links would > >>> be great. > >> The most simple example is in the tutorial - it just uses > originate. > >> "Hello Manager!" at > >> http://asterisk-java.org/development/tutorial.html > >> > >> =Stefan > >> > >> -- > >> reuter network consulting > >> Neusser Str. 110 > >> 50760 Koeln > >> Germany > >> Telefon: +49 221 1305699-0 > >> Telefax: +49 221 1305699-90 > >> E-Mail: ste...@re... > >> Jabber: ste...@re... > >> > >> Steuernummern 215/5140/1791 USt-IdNr. DE220701760 > >> > >> > > > > > > > ---------------------------------------------------------------------- > > --- This SF.net email is sponsored by DB2 Express Download > DB2 Express > > C - the FREE version of DB2 express and take control of > your XML. No > > limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > Asterisk-java-users mailing list > > Ast...@li... > > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > > > > -- > Carlos G Mendioroz <tr...@ac...> > > -------------------------------------------------------------- > ----------- > This SF.net email is sponsored by DB2 Express Download DB2 > Express C - the FREE version of DB2 express and take control > of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > |