这个问题不言自明。我想运行 fastagi 的 getoption 方法。AgiChannel,但带有串联提示,就像您直接在拨号计划中执行背景(按-1&or&按-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");
有关更多信息,请参阅
http://www.asterisk-java.org/development/apidocs/index.html
http://www.voip-info.org/wiki/view/Asterisk+cmd+Read
找到了解决方案。正如 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();
}
}