当其他方挂机时如何停止AGI脚本

时间:2014-01-15 11:11:31

标签: java asterisk terminate agi

我有一个Java程序,它发起对客户端的调用,并在接听后将其连接到拨号方案中的扩展名。该扩展又运行AGI脚本以与客户端进行一些交互。 如果客户端保持直到最后,一切都很完美。但如果他在中间挂起,AGI脚本会继续运行。我希望它在客户端挂机时停止。

以下是原始java程序的摘录:

OriginateAction originateAction;
ManagerResponse originateResponse;
originateAction=new OriginateAction();
originateAction.setChannel(phoneNumber);
originateAction.setExten("700");
originateAction.setContext("users");
originateAction.setPriority(new Integer(1));

//connect to Asterisk and login
ManagerConnectionFactory factory = new ManagerConnectionFactory("localhost","******","******");
managerConnection = factory.createManagerConnection();
managerConnection.login();
//send the originate action and wait for a maximum of 30 seconds to get a response
originateResponse=managerConnection.sendAction(originateAction, 30000);

拨号方案的摘录

exten =>700,1,Agi(agi://localhost/message.agi,${var1},${var2},${var3},${var4}); script to play

来自agi脚本的摘录

public void service(AgiRequest arg0, AgiChannel arg1) throws AgiException {
        setVariable("missedSteps","4");
        verbose("  --------------  missed steps: 4 ----------------", 3);
        // Answer the channel and welcome
        answer();
        streamFile("silence/1");
        streamFile("welcome");
        setVariable("missedSteps","3");
        verbose("  --------------  missed steps: 3 ----------------", 3);
        //Read the file
        streamFile(fileName);
        setVariable("missedSteps","2");
        verbose("  --------------  missed steps: 2 ----------------", 3);
            ..........
            ..........
        setVariable("missedSteps","1");
        verbose("  --------------  missed steps: 1 ----------------", 3);
            ..........
            ..........
        setVariable("missedSteps","0");
        verbose("  --------------  missed steps: 0 ----------------", 3);
        //hangup
        hangup();

因此,您可以看到我正在尝试保留一个跟踪脚本中的演变的变量,并且我希望保留该变量以将其存储在调用的日志中。正如您所看到的,我已经添加了一些用于调试的详细命令,我在控制台上看到的是“missSteps”变量从4到0继续进行,无论客户端是否挂起。

2 个答案:

答案 0 :(得分:0)

您可以查看CHANNEL(checkhangup)变量。

答案 1 :(得分:0)

意外地找到了解决方案。 事实上,AGI脚本在“streamFile”执行失败时会停止。所以我在更新跟踪变量之前,在每个关键步骤之前添加了一些“streamFile(”silence / 1“)”。 AGI脚本将在达到该指令时停止,变量将不会更新。