Java 带有串联提示的星号getoption

Java 带有串联提示的星号getoption,java,concatenation,asterisk,agi,Java,Concatenation,Asterisk,Agi,这个问题不言而喻。我想运行fastagi.AgiChannel的getoption方法,但要使用串联的提示,就像您直接在拨号计划中执行后台操作一样(按-1或&press-2)。 我尝试了所有的变化,在网上到处搜索,但都找不到。 我正在使用eclipse用java编程。 下面是代码 import org.asteriskjava.fastagi.AgiChannel; import org.asteriskjava.fastagi.AgiException; import org.asterisk

这个问题不言而喻。我想运行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();   
    }
    }

不,不能对多个文件使用getOption

但是你可以摆脱那种奇怪的java固件,使用星号AGI

ExecCommand("Read(result,press-1&or&press-2,1,,3)");
choice=getVariable("result");
有关更多信息,请参阅


找到了解决方案。正如arehops所建议的,您不能对多个文件使用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();   
    }
}

谢谢。我无法按原样实施它。但知道getOption不可能实现这一点促使我寻找其他解决方案,于是我带着我发布的解决方案回来了。