Thread: [Asterisk-java-users] Dialer
Brought to you by:
srt
From: Aaron F. <aa...@la...> - 2007-05-24 00:10:07
|
Is there an example of an application that dials out? Any links would be great. Thanks, Aaron |
From: Stefan R. <ste...@re...> - 2007-05-24 00:28:56
Attachments:
signature.asc
|
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 =3DStefan --=20 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 |
From: Aaron F. <aa...@la...> - 2007-05-24 02:37:01
|
Ok I missed that as I was keying on the FastAGI -- but I can use either mechanism. Instead of dialing an extension, how would I dial a phone number using OriginateAction? 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 > > |
From: Aaron F. <aa...@la...> - 2007-05-24 04:40:46
|
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 > > |
From: Carlos G M. <tr...@ac...> - 2007-05-24 10:01:49
|
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...> |
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 > |
From: Carlos G M. <tr...@ac...> - 2007-05-24 15:40:48
|
I'll pass on that, I don't know about Trixbox... Aaron Freeman @ 24/05/2007 12:30 -0300 dixit: > 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 -- Carlos G Mendioroz <tr...@ac...> |
From: Aaron F. <aa...@la...> - 2007-05-24 15:48:47
|
How would you do it in extensions.conf? I can probably figure it out from comparing with yours. BTW what is callThreads? Is that a HashMap of threads? And callState? Thanks, Aaron > -----Original Message----- > From: ast...@li... > [mailto:ast...@li...] On > Behalf Of Carlos G Mendioroz > Sent: Thursday, May 24, 2007 10:41 AM > To: ast...@li... > Subject: Re: [Asterisk-java-users] Dialer > > I'll pass on that, I don't know about Trixbox... > > > Aaron Freeman @ 24/05/2007 12:30 -0300 dixit: > > 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 > > > -- > 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 > |
From: Aaron F. <aa...@la...> - 2007-05-24 16:21:55
|
Ah, I see -- this is a way of queueing up a bunch of calls. I missed the manipulation of callThreads in the onManagerEvent method. -a > -----Original Message----- > From: ast...@li... > [mailto:ast...@li...] On > Behalf Of Aaron Freeman > Sent: Thursday, May 24, 2007 10:50 AM > To: ast...@li... > Subject: Re: [Asterisk-java-users] Dialer > > How would you do it in extensions.conf? I can probably > figure it out from comparing with yours. > > BTW what is callThreads? Is that a HashMap of threads? And > callState? > > Thanks, > > Aaron > > > -----Original Message----- > > From: ast...@li... > > [mailto:ast...@li...] > On Behalf > > Of Carlos G Mendioroz > > Sent: Thursday, May 24, 2007 10:41 AM > > To: ast...@li... > > Subject: Re: [Asterisk-java-users] Dialer > > > > I'll pass on that, I don't know about Trixbox... > > > > > > Aaron Freeman @ 24/05/2007 12:30 -0300 dixit: > > > 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 > > > > > > -- > > 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 > > > > > -------------------------------------------------------------- > ----------- > 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 > |
From: Cord <co...@tv...> - 2007-05-25 08:58:13
|
=0D=0AHello list! I'm quite new to programming Asterisk-Java. I wrote a servlet which successfully calls an originate action with the giv= en parameters. My problem is related to the setAccount method: I have to authenticate the account, so if the given password is not right, = I reject calling the originate, else I do it. I would like to achive the same funcionality, which is in the Asterisk2Bill= ing php goodness: function login ($user, $pass) {=20 =09global $DBHandle; =09[...]=09 =09$QUERY =3D "SELECT userid, perms, confaddcust, groupid FROM cc_ui_authen= WHERE login =3D '".$user."' AND password =3D '".$pass."'"; =09$res =3D $DBHandle -> query($QUERY); =09if (!$res) { =09=09$errstr =3D $DBHandle->ErrorMsg(); =09=09return (false); =09} =09[...] } =20 I don't understand PHP much, but I have read about the DB handling of aster= isk-java, but no clue how to match the user password. How can I access Asterisk's database, where can I read about the scheme, et= c. Thanks in advance! =09Attila |
From: S. B. S. <bs...@no...> - 2007-05-25 09:57:55
|
The code sample you supplied is not an asterisk database but something that asterisk2billing layers on top of asterisk. The closet thing you will get is the sip_buddies table which is used in asterisk realtime. Normally sip entries are kept in sip.conf but you can move these to a sql db by using the asterisk realtime feature. Having said that sip entries are not users/accounts but telephone extensions. If you are doing some sort of billing application you will have to create/manage your own account tables. Cord wrote: > Hello list! > > I'm quite new to programming Asterisk-Java. > I wrote a servlet which successfully calls an originate action with the given parameters. > > My problem is related to the setAccount method: > > I have to authenticate the account, so if the given password is not right, I reject calling the originate, else I do it. > > I would like to achive the same funcionality, which is in the Asterisk2Billing php goodness: > > function login ($user, $pass) { > global $DBHandle; > [...] > $QUERY = "SELECT userid, perms, confaddcust, groupid FROM cc_ui_authen WHERE login = '".$user."' AND password = '".$pass."'"; > $res = $DBHandle -> query($QUERY); > if (!$res) { > $errstr = $DBHandle->ErrorMsg(); > return (false); > } > [...] > } > > I don't understand PHP much, but I have read about the DB handling of asterisk-java, but no clue how to match the user password. > > How can I access Asterisk's database, where can I read about the scheme, etc. > > > Thanks in advance! > > > > Attila > > > ------------------------------------------------------------------------- > 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 > |
From: Carlos G M. <tr...@hu...> - 2007-05-24 09:49:22
|
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...@hu...> LW7 EQI Argentina |