Call Us Today! 877.742.2583




Page tree
Skip to end of metadata
Go to start of metadata

About

After-hours interactive voice response menu example JavaScript. 

Example

AfterHoursIVR.js
function getThreeDigits( session, type, data, arg ) {
  if ( type === "dtmf" ) {
    arg.digits += data.digit;
    if ( arg.digits.length < 3 ) {
      return true;
    }
  }
  return false;
}

if ( session.ready() ) {
  
  var dtmf = {
    digits : ''
  };
  session.answer();
  session.streamFile( "/usr/local/freeswitch/sounds/custom/afterhours.wav", getThreeDigits, dtmf, 4000 );
  session.collectInput( getThreeDigits, dtmf, 5000 );
  console_log( "info", "Got " + dtmf.digits + "\n" );
  
  if ( dtmf.digits === "0" ) {
    session.execute("transfer", "100 XML default");
  } else if ( dtmf.digits.length === 3 ) {
    session.execute("transfer", dtmf.digits + " XML default");
  } else {
    session.execute("transfer", "**100 XML default");
  }
}