Re: [Asterisk-java-users] How can i use this library to make a call and run an audio file on it
Brought to you by:
srt
From: adriano s. <sle...@bs...> - 2018-11-27 20:12:09
|
Hi Brandon! Some updates.... I am already able to dial through the management interface. Now all i have to do is use AGI to send some useful info to the call. If you have any other tips that you want to share I will be very grateful to you! Regards, Adriano Santos Em sáb, 24 de nov de 2018 às 19:54, adriano santos <sle...@bs...> escreveu: > Hello Brandon! > Thank you for your suggestions. I will try to use the agi in the context > to and start the call through the management interface. > If I succeed, I'll leave the shared solution here. > > Regards, > Adriano Santos > > Em sáb, 24 de nov de 2018 às 15:21, Brandon Haugen <bh...@ta...> > escreveu: > >> Hey Adriano, >> >> I was looking for a way to send audio through the Manager Interface and I >> found this in the FAQ for Asterisk Java. >> >> Currently, there is no support for sending media or files across the >>> Manager interface or the Gateway interface. Having access to the media >>> stream without participating in the call would require saving it to a file >>> or modifications to Asterisk itself, and you can expose any files (media or >>> otherwise) through some other means (HTTP, SSH, etc). >> >> >> So you will need to play the audio through either regular dialplan code >> in *extensions.conf* or by using Agi and Asterisk Java together. Since >> you are specifying the context as "from-internal" you can call out to Agi >> from within that context and use the code I shared earlier in this thread. >> >> Thanks, >> Brandon >> >> On Fri, Nov 23, 2018 at 6:31 PM adriano santos <sle...@bs...> >> wrote: >> >>> Hi! >>> >>> I'm trying to use the management interface to originate a call, but in >>> the moment I can not do play an audio file. The code is something like this: >>> >>> @Slf4j >>> public class OriginateCall { >>> private static final int PORT = 5038; >>> private static final String HOSTNAME = "*.*.*.*"; >>> private static final String USERNAME = "*"; >>> private static final String PASSWORD = "*"; >>> private static final String CONTEXT = "context"; >>> // Number to call, prefaced by 1+areacode (just like your home phone). >>> public String call = "some_number"; >>> private ManagerConnection managerConnection; >>> >>> public OriginateCall() { >>> ManagerConnectionFactory factory = new >>> ManagerConnectionFactory(HOSTNAME, PORT, USERNAME, PASSWORD); >>> >>> this.managerConnection = factory.createManagerConnection(); >>> } >>> >>> public void call() throws IllegalStateException, IOException, >>> AuthenticationFailedException, TimeoutException { >>> OriginateAction originateAction; >>> ManagerResponse originateResponse; >>> >>> originateAction = new OriginateAction(); >>> /* >>> * Format the call for dialing Channel example: >>> Local/12065551234@outgoing-42 >>> */ >>> Integer timeoutCall = 50000; >>> originateAction.setChannel("SIP/" + call + "@" + CONTEXT); >>> originateAction.setContext("from-internal"); >>> originateAction.setCallerId("55011100"); // what will be showed >>> on the phone screen (in most cases your phone) >>> originateAction.setExten(""/*[targetExten]*/); //where to call.. >>> the target extension... internal extension or the outgoing number.. the >>> 0[nomberToCall] >>> originateAction.setPriority(1);// priority of the call >>> >>> originateAction.setTimeout(timeoutCall ); // the time that a pickup >>> event will be waited for >>> originateAction.setVariable("UUID", >>> UUID.randomUUID().toString()); // asigning a unique ID in order to be able >>> to hangup the call. >>> >>> managerConnection.login(); >>> >>> /* >>> * send the originate action >>> */ >>> originateResponse = managerConnection.sendAction(originateAction, 50000); >>> >>> // print out whether the originate succeeded or not >>> log.info("Call Response -> {}", originateResponse.getResponse()); >>> >>> // and finally log off and disconnect >>> managerConnection.logoff(); >>> } >>> public static void main(String... args) throws IllegalStateException, >>> IOException, AuthenticationFailedException, TimeoutException { >>> OriginateCall originate = new OriginateCall(); >>> originate.call(); >>> } >>> >>> } >>> >>> I'll view the information you sent me. Again thank you for your time and >>> knowledge. >>> >>> Regards, >>> Adriano Santos >>> >>> Em sex, 23 de nov de 2018 às 19:45, Brandon Haugen < >>> bh...@ta...> escreveu: >>> >>>> Hey Adriano, >>>> >>>> Yes, the code I shared is showing how to receive a call and respond >>>> with audio. >>>> >>>> I have a scenario where we allow users to initiate a call to themselves >>>> (by pressing a button in a Web App) and when they pick up the call, we >>>> stream a couple of audio files (one after the other) to give them >>>> instructions for the system they are using. In our scenario though, we are >>>> just initiating the call through the use of Call Files ( >>>> https://wiki.asterisk.org/wiki/display/AST/Asterisk+Call+Files). When >>>> the user picks up, they just drop into the context specified in the Call >>>> File which directs them to our Asterisk Java AgiScript. In this case, I >>>> still use `getData` on the `AgiChannel` to stream the files when I need >>>> DTMF, otherwise I just use the `exec` method on the AgiChannel to use the >>>> Playback application within Asterisk. >>>> >>>> If you are going to originate the Call in some other way, I won't be of >>>> much help at the moment as I have not worked with the Asterisk Manager >>>> Interface, ( >>>> https://wiki.asterisk.org/wiki/display/AST/The+Asterisk+Manager+TCP+IP+API) >>>> yet. Asterisk Java does also support the Manager Interface so you might >>>> find something that more closely resembles what you are looking to do at >>>> http://asterisk-java.org . >>>> >>>> On Fri, Nov 23, 2018 at 3:21 PM adriano santos <sle...@bs...> >>>> wrote: >>>> >>>>> Hi Brandon! Thank you for your response. >>>>> >>>>> Is the example you sent to receive a call and respond with correct >>>>> audio? >>>>> What I need to do is originate a call to cell phone and play audio. >>>>> For now no need for DTMF. >>>>> >>>>> Regards, >>>>> Adriano Santos >>>>> >>>>> Em sex, 23 de nov de 2018 às 18:34, Brandon Haugen < >>>>> bh...@ta...> escreveu: >>>>> >>>>>> Hey Adriano, >>>>>> >>>>>> I have within the last few months started using Asterisk-Java for a >>>>>> project and you can certainly playback an audio file. There are a couple of >>>>>> things that you will have to think about to determine the best approach for >>>>>> your situation, here is what I can tell you though >>>>>> >>>>>> - If you do *not* need to listen for DTMF input (keypresses) >>>>>> while playing the audio file then you can play an audio file on an >>>>>> AgiChannel in Java by using something like `agiChannel.exec("playback", >>>>>> "<path to audio file>");` >>>>>> - This example in the Asterisk Java GitHub repository shows >>>>>> answering a call, playing a file back, and then hanging up (note that in >>>>>> the example they rely on methods defined in the AgiOperations class so they >>>>>> aren't operating directly on the AgiChannel like the line of code I am >>>>>> sharing is doing) >>>>>> https://github.com/asterisk-java/asterisk-java/blob/master/src/main/java/org/asteriskjava/examples/fastagi/ExampleCallIn.java >>>>>> - If you *do* need to listen for DTMF input while playing the >>>>>> audio file then you will want to use the `getData` or `getOption` methods >>>>>> defined on AgiChannel. You will need to pick which method is appropriate >>>>>> depending on the length of DTMF you need to listen for (`getOption` returns >>>>>> a single char while `getData` will return a String) >>>>>> >>>>>> Thanks, >>>>>> Brandon >>>>>> >>>>>> On Thu, Nov 22, 2018 at 12:09 PM adriano santos <sle...@bs...> >>>>>> wrote: >>>>>> >>>>>>> Hello, guys! >>>>>>> >>>>>>> I would like to play an audio file on a initialized call via java. I >>>>>>> haven't found an example for this. >>>>>>> Is this possible? >>>>>>> >>>>>>> -- >>>>>>> Adriano P. Santos >>>>>>> >>>>>>> "O homem erudito é um descobridor de fatos que já existem - mas o >>>>>>> homem sábio é um criador de valores que não existem e que ele faz existir." >>>>>>> Albert Einstein >>>>>>> _______________________________________________ >>>>>>> Asterisk-java-users mailing list >>>>>>> Ast...@li... >>>>>>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>>>>>> >>>>>> _______________________________________________ >>>>>> Asterisk-java-users mailing list >>>>>> Ast...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>>>>> >>>>> >>>>> >>>>> -- >>>>> Adriano P. Santos >>>>> >>>>> "O homem erudito é um descobridor de fatos que já existem - mas o >>>>> homem sábio é um criador de valores que não existem e que ele faz existir." >>>>> Albert Einstein >>>>> _______________________________________________ >>>>> Asterisk-java-users mailing list >>>>> Ast...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>>>> >>>> _______________________________________________ >>>> Asterisk-java-users mailing list >>>> Ast...@li... >>>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>>> >>> >>> >>> -- >>> Adriano P. Santos >>> >>> "O homem erudito é um descobridor de fatos que já existem - mas o homem >>> sábio é um criador de valores que não existem e que ele faz existir." >>> Albert Einstein >>> _______________________________________________ >>> Asterisk-java-users mailing list >>> Ast...@li... >>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>> >> _______________________________________________ >> Asterisk-java-users mailing list >> Ast...@li... >> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >> > > > -- > Adriano P. Santos > > "O homem erudito é um descobridor de fatos que já existem - mas o homem > sábio é um criador de valores que não existem e que ele faz existir." > Albert Einstein > -- Adriano P. Santos "O homem erudito é um descobridor de fatos que já existem - mas o homem sábio é um criador de valores que não existem e que ele faz existir." Albert Einstein |