0

这个问题不言自明。我想运行 fastagi.AgiChannel 的 getoption 方法,但要使用串联的提示,就像您直接在拨号计划中执行 Background(press-1&or&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();   
    }
    }
4

2 回答 2

1

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

但是您可以摆脱那个奇怪的 java 固件并使用星号 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

于 2014-01-08T17:39:11.283 回答
0

找到了解决方案。正如 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();   
    }
}
于 2014-01-09T12:19:35.623 回答