2

I am working with Freeswitch ESL client, I worked on originating call and establishing connection between two applications and making them communicate with each other. I have tried playing sound at one end and recording at the other, It is working fine now my requirement is to send dtmf at one end receiving at other end, I have tried following

private void sendDtmf(Channel channel) {
    SendMsg senDtmf = new SendMsg();
    senDtmf.addCallCommand("execute");
    senDtmf.addExecuteAppName("send_dtmf");
    senDtmf.addExecuteAppArg("2174");
    EslMessage response = sendSyncMultiLineCommand( channel,senDtmf.getMsgLines() );
    if (response.getHeaderValue(Name.REPLY_TEXT).startsWith("+OK")) {
        System.out.println(this.getClass().getName() + " >> DTMF Send");
        System.out.println("Resp: " + response.toString());
        log.info(this.getClass().getName() + " >> DTMF Send");
    } else {
        log.error(this.getClass().getName() + " >> DTMF failed :"
                + response.getHeaderValue(Name.REPLY_TEXT));
        System.out.println(this.getClass().getName() + " >> DTMF failed :"
                + response.getHeaderValue(Name.REPLY_TEXT));
    }
}

private void getdtmf( Channel channel, VoxtaMsg voxmsg) 
{ 
    SendMsg getDtmf= new SendMsg(); 
    getDtmf.addCallCommand( "execute" );
    getDtmf.addExecuteAppName( "play_and_get_digits" );
    getDtmf.addExecuteAppArg("4 4 3 7000 # /tmp/sounds/test.wav /tmp/sounds/test1.wav dtmf \\d+");
    EslMessage response = sendSyncMultiLineCommand( channel,getDtmf.getMsgLines() ); 
    if ( response.getHeaderValue( Name.REPLY_TEXT).startsWith( "+OK" ) )
    {
        System.out.println(this.getClass().getName()+" >> DTMF Received");
        log.info( this.getClass().getName()+" >> DTMF Received" ); 
    } 
    else
    {
        log.error( this.getClass().getName() + " >> DTMF failed: [{}}" +
        response.getHeaderValue( Name.REPLY_TEXT ));
        System.out.println(this.getClass().getName() + " >> DTMF failed: [{}}" +
                response.getHeaderValue( Name.REPLY_TEXT ) ); 
        log.debug("----------------------done-------------------------");
    }
 }

but could not get any result, Do I need to configure any thing in dial plans, or my total approach is wrong?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Ravikiran Reddy
  • 87
  • 4
  • 15

1 Answers1

3

You need to attach an event listener and wait for the "CHANNEL_EXECUTE_COMPLETE" command. Two things are needed. 1) Subscribe to the events on the connection 2) Add an event listener and get back the value of the response variable which you are setting to be dtmf.

Assume that the client object is the connection.

client.connect(...);
client.setEventSubscriptions("plain", "CHANNEL_EXECUTE_COMPLETE");
client.addEventListener(new IEslEventListener() {
        @Override
        public void eventReceived(EslEvent event) {
            Map<String, String> vars = event.getEventHeaders();

            if (event.getEventName().equals("CHANNEL_EXECUTE_COMPLETE") && vars.get("Application").equals("play_and_get_digits")) {
                 PlayAndGetDigitsCallback(vars.get("dtmf"));
            }
        }

        @Override
        public void backgroundJobResultReceived(EslEvent event) {

        }
});

private void PlayAndGetDigitsCallback(String digits) {
    System.out.println("Digits received: " + digits);
}
Danny G
  • 3,660
  • 4
  • 38
  • 50
  • Thanks a lot for your reply Sir, I will revert to you if I have any queries related to this problem – Ravikiran Reddy Nov 06 '13 at 06:26
  • Sir, I am sorry to say that this is not working I used the same code at sending application and the code you have given at receiving end I got nothing, I am getting following result - org.freeswitch.esl.client.transport.message.EslFrameDecoder >> read body line [{}]Application: send_dtmf - org.freeswitch.esl.client.transport.message.EslFrameDecoder >> read body line [{}]Application-Data: 2174 but dtmf cannot be retrieved into a variable – Ravikiran Reddy Nov 06 '13 at 09:20
  • Sure, Sir If you don’t mind, May I please know your mail address So that I can send full source code to your address – Ravikiran Reddy Nov 07 '13 at 05:05
  • Hi, Sir I have updated DTMF in my application its working, Thanks for your valuable suggestions, I need a small help from you, that is when user call, the application will play, record etc. I need to update music on hold when system takes some time to respond i.e when no event is triggered in application it should play noh, I tried it in sync mode and moh is continuously playing, in async mode moh is working but record is not working, please help me sir. – Ravikiran Reddy Nov 20 '13 at 05:59
  • Can you up-vote and accept this as the solution? You should start a new question for your other point. – Danny G Nov 20 '13 at 16:03
  • Sir I have voted for your solution and started new question, Please try to help me at the earliest, My question is at http://stackoverflow.com/questions/20047623/how-to-record-in-async-mode-in-freeswitch – Ravikiran Reddy Nov 21 '13 at 05:03