通过asterisk-java传出IVR

时间:2014-04-23 06:42:33

标签: java sip text-to-speech asterisk ivr

我正在使用Asterisk和asterisk-java构建简单的传出IVR 我在同一网络中的两台不同的计算机(A和B)中安装了Xlite软电话,并将它们设置为星号,我可以成功调用它们 这是我的星号-java代码

public class PhoneUtility {

    private static ManagerConnection instanceManagerConnection;

    private static ManagerConnection getManagerConnectionInstance() {
        if (instanceManagerConnection == null) {
            ManagerConnectionFactory factory = new
                    ManagerConnectionFactory("192.132.0.01", "admin", "amp111");
            instanceManagerConnection = factory.createManagerConnection();
        }
        return instanceManagerConnection;
    }

    public static boolean phoneCall() {
        try {
            ManagerConnection managerConnection = getManagerConnectionInstance();
            OriginateAction originateAction;
            ManagerResponse originateResponse;

            originateAction = new OriginateAction();
            originateAction.setChannel("SIP/ivan");
            originateAction.setCallerId("1234");
            originateAction.setContext("ivr-ext");
            originateAction.setExten("1235");
            originateAction.setPriority(new Integer(1));
            originateAction.setActionId("2");
            originateAction.setTimeout(300000l);
            originateAction.setAsync(new Boolean(false));

            // connect to Asterisk and log in
            managerConnection.login();

            AsteriskServerImpl asteriskServer = new AsteriskServerImpl(managerConnection);
            AsteriskChannel asteriskChannel = asteriskServer.originate(originateAction);

            // Play a prompt by text to speach 


            Character dtmf = asteriskChannel.getDtmfSent();
            if (dtmf.equals("1")) {
                managerConnection.logoff();
                return true;
            } else {
                managerConnection.logoff();
                return false;
            }

        } catch (Exception e) {
            System.out.println(e);
            return false;
        }
    }
}

我在计算机A中执行代码(调用phoneCall())来调用计算机B. 当代码在计算机A中执行时,我的软电话首先在计算机A上响铃,我必须在软电话A上接听,然后计算机B软电话响铃, 如何通过编码自动打开计算机A的频道(我根本不想在计算机A中安装软电话)

1 个答案:

答案 0 :(得分:0)

你可以先打电话B,如果接听电话,那么电话A响铃(IVR-Extension将由IVR APP代替,它会自动回答):

使用扩展名交换CallerID,如下所示:

        originateAction = new OriginateAction();
        originateAction.setChannel("SIP/1235");
        originateAction.setCallerId("1235");//put the target extension here
        originateAction.setContext("ivr-ext");
        originateAction.setExten("1234"); //put IVR-extension  here
        originateAction.setPriority(new Integer(1));
        originateAction.setActionId("2");
        originateAction.setTimeout(300000l);
        originateAction.setAsync(new Boolean(false));