Skip to main content

Javascript Example - DISA (direct inward system access)

About

Direct Inward System Access (DISA). It allows inbound callers to make internal or outbound calls.

Click here to expand Table of Contents

// is a javascript comment. The comment tells the interpreter not to process the line. To un-comment a line simply remove the two forward slashes.

Examples disa.js

disa.js

var pin = "757575"; //make sure to change the PIN number.
//var pin = ""; //don't require a pin
//if you choose not to require a pin then then you may want to add a dialplan condition for a specific caller id

var predefined_destination = ""; //example: 9999
//predefined_destination leave empty in most cases
//Use this to define a single destination

var digitmaxlength = 0;
var timeoutpin = 7500;
var timeouttransfer = 7500;

function mycb( session, type, obj, arg ) {
try {
if ( type == "dtmf" ) {
console_log( "info", "digit: "+obj.digit+"\n" );
if ( obj.digit == "#" ) {
//console_log( "info", "detected pound sign.\n" );
exit = true;
return( false );
}

dtmf.digits += obj.digit;

if ( dtmf.digits.length >= digitmaxlength ) {
exit = true;
return( false );
}
}
} catch (e) {
console_log( "err", e+"\n" );
}
return( true );
} //end function mycb

//console_log( "info", "DISA Request\n" );

var dtmf = new Object( );
dtmf.digits = "";

if ( session.ready( ) ) {
session.answer( );

if (pin.length > 0) {
digitmaxlength = 6;
session.streamFile( "/usr/local/freeswitch/sounds/custom/8000/pin.wav", mycb, "dtmf");
session.collectInput( mycb, dtmf, timeoutpin );
//console_log( "info", "DISA pin: " + dtmf.digits + "\n" );
}

if (dtmf.digits == pin || pin.length == 0) {

//console_log( "info", "DISA pin is correct\n" );

us_ring = session.getVariable("us-ring");
session.execute("set", "ringback="+us_ring); //set to ringtone
session.execute("set", "transfer_ringback="+us_ring); //set to ringtone
session.execute("set", "hangup_after_bridge=true");

if (predefined_destination.length == 0) {
dtmf.digits = ""; //clear dtmf digits to prepare for next dtmf request
digitmaxlength = 11;
session.streamFile( "/usr/local/freeswitch/sounds/custom/8000/please_enter_the_phone_number.wav", mycb, "dtmf");
session.collectInput( mycb, dtmf, timeouttransfer );
console_log( "info", "DISA Transfer: " + dtmf.digits + "\n" );
session.execute("transfer", dtmf.digits + " XML default");
}
else {
session.execute("transfer", predefined_destination + " XML default");
}

}
else {
session.streamFile( "/usr/local/freeswitch/sounds/custom/8000/pin_incorrect.wav", mycb, "dtmf");
console_log( "info", "DISA Pin: " + dtmf.digits + " is incorrect\n" );
}

}

Add the custom directory to /usr/local/freeswitch/sounds/ and then add another directory 8000 to that so that the path shows as /usr/local/freeswitch/sounds/custom/8000/. Download the sounds files and put them in the custom/8000 directory.

 pin.wav
pin_incorrect.wav
please_enter_the_phone_number.wav

To call the DISA application add something like the following in the dial plan. Defines the DISA extension as (DISA) 3472. Add this to /usr/local/freeswitch/conf/dialplan/default.xml

DISA with a PIN

 <extension name="DISA">
<condition field="destination_number" expression="3472">
<action application="javascript" data="disa.js" />
</condition>
</extension>

If you are not requiring a pin number you may want to secure access with the caller id. Make sure to change 1001 to represent the number you want to allow.

Without using a PIN

 <extension name="DISA">
<condition field="caller_id_number" expression="^1001$"/>
<condition field="destination_number" expression="3472">
<action application="javascript" data="disa.js" />
</condition>
</extension>

If you're trying to gain access from outside, add something like the following to the public context:

.... add to /usr/local/freeswitch/conf/dialplan/public.xml

External access

 <extension name="DISA">
<condition field="caller_id_number" expression="5551234567">
<action application="javascript" data="/usr/local/freeswitch/java/disa.js" />
<action application="set" data="domain_name=$${domain}"/>
<action application="transfer" data="3472 XML default"/>
</condition>
</extension>

Text.