这个问题不言自明。我想运行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();
}
}发布于 2014-01-09 12:19:35
找到了解决办法。正如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-08 17:39:11
不,不能对多个文件使用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
https://stackoverflow.com/questions/20991577
复制相似问题