2014-01-08 30 views
0

這個問題本身就說明了一切。我想運行fastagi.AgiChannel的getoption方法,但是使用級聯提示,就像你在背景(直接按dialplan中的-01 &或& press-2)。 我嘗試了所有的變化,並在網上到處搜索,但無法找到。 我正在用java編程使用eclipse。 下面的代碼。星號getoption連接提示

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(); 
    } 
    } 

回答

0

找到了解決辦法。正如ishops建議的那樣,您不能在多個文件中使用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(); 
    } 
} 
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

+0

Thanks.I無法實現它原樣。但是由於知道getOption不可能,我推動我去尋找其他解決方案,然後我回到了我發佈的那個解決方案。 –