The question speaks for itself. I would like to run the getoption method of the fastagi.AgiChannel, but with concatenated prompts, like you would do Background(press-1&or&press-2) in the dialplan directly. I tried all variations and searched everywhere on the net but couldn't find. I'm programming in java using eclipse. Below the code.
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();
}
}
Found the solution. As arehops suggested, you can't use getOption with multiple files. I was not able to replicate his proposal, but found this implementation that works, using the exec and 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();
}
}