SIGN UP

IVR

This is a helper module to provide your apps with IVR functionality. Of course, you can do it on lower level by using the Call.say(), Call.startPlayback and Call.handleTones methods, but this module gives more straightforward approach.

Add the following line to your scenario code to use the module:

 require(Modules.IVR);

All functions, events and classes of the module can be used only after this line.

There are 4 types of IVR states supported by this module:

  1. Prompt with no input

    var mainState = new IVRState("main",
    {
    type:"noinput",
    prompt:{
     play:"http://www.example.com/question1.mp3"
    },
    nextState:state1
    
    });

    nextState property defines state that IVR will transit to after prompt has been played successfully. If it's not specified, onInputComplete callback will be invoked.

  2. Selection menu. You need to specify voice prompt and states that IVR will transit to on each specific input

    function onInputTimeout() {
        //User didn't enter anything. Handle it somehow
    }
    
    var state1 = new IVRState("1", {
        type:"select",
        prompt:{play:"http://www.example.com/question1.mp3"},
        nextStates:{
          "1":state2,
          "2":state2
        }
    
    }, null, onIVRTimeout);
    
    state1.settings.nextStates["0"] = state1;

    In this example we say, that if user presses 1 or 2, IVR proceeds to state2 and if one presses 0, state1 loops. Pay attention at the last line - for more information about settings see the appropriate section IVRSettings.

  3. Fixed length input. This can be used if you need user to enter, for example, extension number and you know exact length of desired input.

    function onInputFinished(data) {
        //Input is complete, data is string with desired length
    }
    
    function onInputTimeout(data) {
        //Input timed out, but data still contains what user has entered
    }
    
    var mainState = new IVRState("Main", {
        type:"inputfixed",
        inputLength:3,
        prompt: {
          play:"http://example.org/main.mp3" 
        }
    
    }, onInputFinished, onInputTimeout);
  4. Variable length input. This can be used when you don't know how many digits must be entered. First option: say that input must be terminated on #.

    function onInputFinished(data) {
        //Input is complete, data is string terminated with #
    }
    
    function onInputTimeout(data) {
        //Input timed out, but data still contains what user has entered
    }
    
    var mainState = new IVRState("Main", {
        type:"inputunknown",
        terminateOn:"#",
        prompt: {
          play:"http://example.org/main.mp3" 
        }
    }, onInputFinished, onInputTimeout);

    Second option: check input every time user presses any digit and see if it's ok. For example, input may be considered correct when user presses same digits 2 times straight.

    function onInputFinished(data) {
        //Input is complete
    }
    
    function onInputTimeout(data) {
        //Input timed out, but data still contains what user has entered
    }
    
    function validate(input) {
        if (input.length >= 2 && ( input[input.length - 1] == input[input.length - 2] ) ) {
            //notify IVR that input is complete
            return true;
        }
        return false;
    }
    
    var mainState = new IVRState("Main", {
        type:"inputunknown",
        inputValidator: validate,
        prompt: {
          play:"http://example.org/main.mp3" 
        }
    }, onInputFinished, onInputTimeout);

Example


 require(Modules.IVR);

 function onInputFinished(input) {
  //Call local user, treat input as extension number
}

 function onInputTimeout(input) {
  //Route call to queue
}

 VoxEngine.addEventListener(AppEvents.CallAlerting, function(e) {
  
  inCall = e.call;
  dn = e.displayName;
  //start IVR
	
  
  
  var mainState = new IVRState("Main", {
    type:"inputfixed",
    inputLength:3,
    prompt: {
      play:"http://example.com/main.mp3" 
    }
    
  }, onInputFinished, onInputTimeout);
  
  inCall.answer();
  inCall.addEventListener(CallEvents.Connected, function(e) {
    
    mainState.enter(inCall);
  });
  
  inCall.addEventListener(CallEvents.Disconnected, function (e) {
    VoxEngine.terminate();
  });
  
  inCall.addEventListener(CallEvents.Failed, function(e) {
    VoxEngine.terminate();
  });
  
  
});

  • IVRPrompt

    IVR menu prompt settings. Note that it's possible to specify play parameter or pair of the say and lang parameters.

  • IVRSettings

    IVR menu state settings

  • IVRState

    IVR menu state

  • reset

    Reset the IVR; i.e., the method clears the list of existed IVRState objects. It can be useful if you want to stop the entire IVR logic (e.g. near the call's ending).

functions

reset

reset(): void

Reset the IVR; i.e., the method clears the list of existed IVRState objects. It can be useful if you want to stop the entire IVR logic (e.g. near the call's ending).

Returns

  • Return:

    void