0

我有一个 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();

如您所见,我试图保留一个跟踪脚本内演变的变量,并且我想保留该变量以将其存储在调用日志中。如您所见,我添加了一些用于调试的详细命令,而我在控制台上看到的是,无论客户端是否挂断,“missedSteps”变量都会从 4 变为 0。

4

2 回答 2

0

偶然找到了解决办法。事实上,AGI 脚本会在“streamFile”执行失败时停止。因此,在更新跟踪变量之前,我只在每个关键步骤之前添加了一些“streamFile(“silence/1”)”。AGI 脚本将在到达该指令时停止,并且不会更新变量。

于 2014-01-16T12:08:26.653 回答
0

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

于 2014-01-15T14:48:47.150 回答