如何在Freeswitch ESL客户端中发送和接收DTMF

时间:2013-10-31 12:22:08

标签: freeswitch

我正在与Freeswitch ESL客户端合作,我致力于发起呼叫并在两个应用程序之间建立连接并使它们相互通信。我试过在一端播放声音并在另一端录音,现在工作正常我的要求是在另一端接收dtmf,我试过跟随

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-------------------------");
    }
 }

但无法获得任何结果,我是否需要在拨号计划中配置任何内容,或者我的总体方法是错误的?

1 个答案:

答案 0 :(得分:1)

您需要附加事件侦听器并等待“CHANNEL_EXECUTE_COMPLETE”命令。需要做两件事。 1)订阅连接上的事件2)添加事件监听器并获取您设置为dtmf的响应变量的值。

假设client对象是连接。

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);
}