带有连接提示的星号getoption

时间:2014-01-08 09:27:40

标签: java concatenation asterisk agi

这个问题不言而喻。我想运行fastagi.AgiChannel的getoption方法,但是有连续的提示,就像你在拨号方案中直接做背景(按-1和& press-2)一样。 我尝试了所有的变化,并在网上到处搜索但找不到。 我正在使用eclipse在java中编程。 代码下方。

import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiException;
import org.asteriskjava.fastagi.AgiRequest;
import org.asteriskjava.fastagi.BaseAgiScript;

public class HelloAgiScript extends BaseAgiScript{

    @Override
    public void service(AgiRequest arg0, AgiChannel arg1) throws AgiException {
        int choice;
        // Answer the channel
        answer();
        //say hello
        streamFile("silence/1");
        streamFile("welcome");
        //Ask for an input and give feedback
        choice=getOption("press-1","1,2"); //Here is where I would like to prompt press-1 or press-2
        sayDigits(String.valueOf(choice-48));
        streamFile("silence/1");
        //and hangup
        hangup();   
    }
    }

2 个答案:

答案 0 :(得分:1)

不,您不能将getOption与多个文件一起使用。

但是你可以摆脱那个奇怪的java固件并使用asterisk AGI。

ExecCommand("Read(result,press-1&or&press-2,1,,3)");
choice=getVariable("result");

有关详细信息,请参阅

http://www.asterisk-java.org/development/apidocs/index.html

http://www.voip-info.org/wiki/view/Asterisk+cmd+Read

答案 1 :(得分:0)

找到解决方案。正如所建议的那样,你不能将getOption与多个文件一起使用。 我无法复制他的提议,但发现这个实现有效,使用exec和AgiReply:

import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiException;
import org.asteriskjava.fastagi.AgiRequest;
import org.asteriskjava.fastagi.BaseAgiScript;
import org.asteriskjava.fastagi.reply.AgiReply;

public class HelloAgiScript extends BaseAgiScript {

    @Override
    public void service(AgiRequest arg0, AgiChannel arg1) throws AgiException {
        String choice;
        // Answer the channel
        answer();
        //say hello
        streamFile("silence/1");
        streamFile("welcome");
        //Ask for an input and give feedback
        System.out.println("test");
        exec("Background","press-1&or&press-2&silence/3"); //Executes Background application
        AgiReply agiReply = getLastReply(); //Get the reply in the form of an AgiReply object
        choice=agiReply.getResult(); //Extract the actual reply
        choice=Character.toString((char) Integer.parseInt(choice)); // convert from ascii to actual digit
        System.out.println("choice: "+choice);
        streamFile("silence/1");
        sayDigits(choice);
        streamFile("silence/1");
        //and hangup
        hangup();   
    }
}