Current Publication | x
Close

Sample Preliminary and Postliminary Scripts

A preliminary is an executable script, written in the Javascript language, that defines processing actions (filtering or transformation) to be applied to a dial string before the dial rule’s action is performed.

A postliminary is an executable script, written in the Javascript language, that defines dial string transformations to be applied before querying an external device (gatekeeper, SIP peer, SBC, or MCU).

Transformation scripts output some modification of the DIAL_STRING variable (which is initially set to the dial string being evaluated).

Filtering scripts may pass the dial string on to the dial rule’s action (if the filter criteria aren’t met) or return one of the following:

NEXT_RULE: Skips the rule being processed and passes the dial string to the next rule.

BLOCK: Rejects the call.

The following sample scripts address many of the scenarios for which you might need a preliminary or postliminary script. You can use them as templates or starting points for your scripts.

 

// Example preliminary and postliminary scripts

 

///////////////////////////////

// STRIP PREFIX

// If the dial string has prefix 99, remove it

// 991234  --> 1234

 

DIAL_STRING = DIAL_STRING.replace(/^99/,"");

 

 

///////////////////////////////

// ADD PREFIX

// Add prefix 99 to the dial string

// 1234  --> 991234

 

DIAL_STRING = "99" + DIAL_STRING;

 

 

///////////////////////////////

// STRIP PREFIX (SIP)

// If the dial string is a SIP URI with prefix 99 in the user part, remove it

// SIP:991234@abc.com  --> sip:1234@abc.com

 

DIAL_STRING = DIAL_STRING.replace(/^sip:99([^@]*@)/i,"sip:$1");

 

 

///////////////////////////////

// ADD PREFIX (SIP)

// If the dial string is a SIP URI, add prefix 99 to the user part

// SIP:1234@abc.com  --> sip:991234@abc.com

 

DIAL_STRING = DIAL_STRING.replace(/^sip:([^@]*@)/i,"sip:99$1");

 

 

///////////////////////////////

// SUBSTITUTE DOMAIN (SIP)

// If the dial string is a SIP URI, change the domain part to "example.com"

// SIP:1234@abc.com  --> sip:1234@example.com

 

DIAL_STRING = DIAL_STRING.replace(/^sip:([^@]*)@(.*)/i,"sip:$1@example.com");

 

 

///////////////////////////////

// FILTER

// If the dial string has prefix 99, do not match on this rule.  Skip to the next rule.

// 991234  --> NEXT_RULE

 

if (DIAL_STRING.match(/^99/))

{

  return NEXT_RULE;

}

 

 

///////////////////////////////

// FILTER (Inverted)

// Do not match on this rule unless the dial string has prefix 99.

// 1234  --> NEXT_RULE

if (!DIAL_STRING.match(/^99/))

{

  return NEXT_RULE;

}

 

 

///////////////////////////////

// FILTER (SIP)

// If the dial string is a SIP URI with domain "example.com", do not match on this rule.

// Skip to the next rule.

// sip:1234@example.com  --> NEXT_RULE

 

if (DIAL_STRING.toLowerCase().match(/^sip:[^@]*@example\.com/))

{

  return NEXT_RULE;

}

 

 

///////////////////////////////

// PRINTLN

// Print out the information available to the script for this call.

// Information printed using the print or println functions

// is saved as a call audit event, which is viewable in the

// DMA interface under Reports > Call History, and also in the

// Script Debugging dialog box.

 

println("DIAL_STRING: " + DIAL_STRING);

println("CALLER_SITE_NAME: " + CALLER_SITE_NAME);

println("CALLER_SITE_COUNTRY_CODE: " + CALLER_SITE_COUNTRY_CODE);

println("CALLER_SITE_AREA_CODE: " + CALLER_SITE_AREA_CODE);

println("CALLER_SITE_DIGITS: " + CALLER_SITE_DIGITS);

println("CALLER_H323ID: " + CALLER_H323ID[0]);

println("CALLER_E164: " + CALLER_E164[0]);

println("CALLER_TEL_URI: " + CALLER_TEL_URI);

println("CALLER_SIP_URI: " + CALLER_SIP_URI);

 

 

///////////////////////////////

// FILTER (Site)

// Do not allow callers from the atlanta site to use this rule.

// (Caller site == "atlanta")  --> NEXT_RULE

 

if (CALLER_SITE_NAME == "atlanta")

{

  return NEXT_RULE;

}

 

 

///////////////////////////////

// SITE BASED NUMERIC NICKNAMES

// Allow caller to omit country and area code when calling locally.

// Assumes that country and area codes are set in site topology.

// Assumes that all endpoints are registered with their full alias, including

// country and area code.

// 5551212  --> 14045551212

 

if (DIAL_STRING.length == CALLER_SITE_DIGITS)

{

  DIAL_STRING = CALLER_SITE_COUNTRY_CODE + CALLER_SITE_AREA_CODE + DIAL_STRING;

}

else if (DIAL_STRING.length == (  parseInt(CALLER_SITE_AREA_CODE.length,10)

                              + parseInt(CALLER_SITE_DIGITS,10)))

{

  DIAL_STRING = CALLER_SITE_COUNTRY_CODE + DIAL_STRING;

}

 

 

///////////////////////////////

// SITE BASED NUMERIC NICKNAMES (SIP)

// Allow caller to omit country and area code when calling locally.

// Assumes that country and area codes are set in site topology.

// Assumes that all endpoints are registered with their full alias, including

// country and area code.

// sip:5551212@example.com  --> sip:14045551212@example.com

 

if (DIAL_STRING.toLowerCase().match(/^sip:[^@]*@example\.com/))

{

  user = DIAL_STRING.replace(/^sip:([^@]*)@.*/i,"$1");

  if (user.length == CALLER_SITE_DIGITS)

  {

     user = CALLER_SITE_COUNTRY_CODE + CALLER_SITE_AREA_CODE + user;

   }

  else if (user.length == (  parseInt(CALLER_SITE_AREA_CODE.length,10)

                          + parseInt(CALLER_SITE_DIGITS,10)))

  {

     user = CALLER_SITE_COUNTRY_CODE + user;

  }

  DIAL_STRING = "sip:" + user + "@example.com";

}

 

 

///////////////////////////////

// Limiting calls to a certain numeric dial range.

// (like the range specified Conference Settings screen)

//

var minGeneratedRoomId = 1000;

var maxGeneratedRoomId = 9999;

 

var number  = parseInt(DIAL_STRING.replace(/^sip:([^@]*)@?(.*)/i,"$1"));

 

if (NaN != number && number > minGeneratedRoomId && number < maxGeneratedRoomId)

{

  return;

}

return NEXT_RULE;

 

 

////////////////////////////////

// A sample script that routes all dial-out calls from a

// whitelist of VMRs to a SIP peer with prefix 11.  All other dial-out

// calls will be routed to a SIP peer with prefix 22.

// The getConferenceRoomOrID() function returns a value only when

// the call is a dial-out from a VMR or Skype scheduled conference

// to an endpoint.

 

var whitelist_vmrs = [

  "1000",    // Specify list of VMRs; add or remove VMRs from this list.

  "2000",    // Make sure you use the syntax "<vmr number>"<comma>

   "3000",         

];

var prefix = "22";

 

 

////////////////////////////////

// Match against individual VMRs.  ACCEPT if any of them matches.

//

if (0 <= whitelist_vmrs.indexOf(getConferenceRoomOrID()))

{

  prefix = "11";

}

DIAL_STRING = prefix + DIAL_STRING;

 

 

////////////////////////////////

// This script may be useful with "Resolve to external SIP peer" dial rules.

//

// This script skips this dial rule unless the call is SIP or SIPs.   (Without

// this, the H.323-SIP gateway function could be invoked).

 

if (!DIAL_STRING.match(/^sips?:/i))

  {

     return NEXT_RULE;

  }

 

 

////////////////////////////////

// This script may be useful with "Resolve to registered endpoint" dial rules.

//

// This script applies to registered H.323 endpoints calling registered SIP

// endpoints (e.g., 1001, 1002, ...) and forces a H.323-SIP gateway call by

// adding the "sip:" dialing scheme.

//

// System configuration: Replace sip.domain.com with your system's SIP domain.

 

DIAL_STRING = DIAL_STRING.replace(/(^1001$)/,"sip:$1@sip.domain.com");

DIAL_STRING = DIAL_STRING.replace(/(^1002$)/,"sip:$1@sip.domain.com");

 

 

////////////////////////////////

// This script may be useful with "Resolve to registered endpoint" dial rules.

//

// This script applies to registered SIP endpoints calling registered H.323

// endpoints (e.g., 1001, 1002, ...) and forces a SIP-H.323 gateway call by

// removing the dialing scheme.

//

// System configuration: Replace sip.domain.com with your system's SIP domain.

 

DIAL_STRING = DIAL_STRING.replace(/^sips?:(1001)@sip.domain.com.*/,"$1");

DIAL_STRING = DIAL_STRING.replace(/^sips?:(1002)@sip.domain.com.*/,"$1");

 

 

///////////////////////////////

// This script illustrates how to accept SIP dial strings that include upper case

// characters and convert them into dial strings with only lower case characters. Thus,

// calls to sip:AbCdEfG123@MyDomain.com are converted to sip:abcdefg123@mydomain.com.

//

// This script can configured as the preliminary for a dial rule with the action "Resolve

// to registered endpoint".

//

// CAUTION: This script should be used in conjunction with some method to assure that all

// SIP registered endpoints have only lower-case characters. One way to assure this is to

// use this script in conjunction with a registration policy script that only allows

// endpoints with lower case SIP URIs to register. See "Sample Preliminary and

// Postliminary Scripts."

//

// Applying this script to other dial rules can cause problems with interoperability.

// For example, if this script is applied to calls to external SIP peers, then the

// endpoints that are eventually contacted through those SIP peers must have lower case

// SIP URIs, or the calls will fail.

//

// Convert all SIP dial strings to lower case and record instances where the dial string

// was changed.

//

if (CALLER_SIP_URI != null && CALLER_SIP_URI != "") {

  var origDS = DIAL_STRING;

  DIAL_STRING = DIAL_STRING.toLowerCase();

  if (origDS != DIAL_STRING) {

      println("Dial string case changed. Original dialstring=" + origDS + " Lowered=" + DIAL_STRING);

  }

}

 

 

////////////////////////////////

// This script may be useful with "Resolve to registered endpoint" or "Resolve

// to conference room ID" dial rules.

//

// This script prepends a prefix (8237) to any 4 digit dial string beginning

// with 4, 5, or 6 (SIP or H.323).

 

DIAL_STRING=DIAL_STRING.replace(/^([4-6][0-9]{3})$/,"8237$1");

DIAL_STRING=DIAL_STRING.replace(/^(sips?:)([4-6][0-9]{3})$/,"$18237$2");

DIAL_STRING=DIAL_STRING.replace(/^(sips?:)([4-6][0-9]{3})@/,"$18237$2");

 

 

////////////////////////////////

// This script may be useful with "Resolve to service prefix" dial rules.

//

// This applies to PSTN or ISDN dial-outs from H.323 endpoints where the E.164

// number is prefixed with 9.

// The MCU is configured with prefix 2082 and 001 is the gateway session

// prefix.  The MCU expects ** as the delimiter for the E.164 number.

 

DIAL_STRING=DIAL_STRING.replace(/^9([0-9]*$)/,"2082001**$1");

 

 

////////////////////////////////

// This script may be useful with "Resolve to external gatekeeper" dial rules

// that send h323 calls to a Cisco VCS device.

//

// This script skips this dial rule if the call is SIP or SIPs.  (Without this,

// the SIP-H.323 gateway function would be invoked).

// For H.323 Annex O dial strings of the form <alias>@<domain>, this script

// prepends the dialing scheme "h323:".

 

if (DIAL_STRING.match(/^sips?:/i))

   {   

     return NEXT_RULE;

  }

else

  {

     DIAL_STRING=DIAL_STRING.replace(/^([^:@]*)@([^@]*)/,"h323:$1@$2");

     println("new dial string is: " + DIAL_STRING);

  }

 

 

 

////////////////////////////////

// This script may be useful with "Resolve to external SIP peer" dial rules.

// System configuration: Each SIP peer selected in the dial rule is configured

// with a prefix (11, 22, or 33).

// The script skips this dial rule for dial strings that are't SIP, whose alias

// isn't 5 characters, or that don't specify one of the prefixes.

// For dial strings that meet these criteria, the domain is removed.

 

alias = DIAL_STRING.replace(/^sips?:([^@]*)@.*/i,"$1");

if (alias.length != 5)

  {

     return NEXT_RULE;

  }

if (alias.match(/^11/) || alias.match(/^22/) || alias.match(/^33/))

  {

     DIAL_STRING = DIAL_STRING.replace(/(^sips?:)([^@]*)@.*/i,"$1$2");

     println("new DIAL_STRING: " + DIAL_STRING);

  }

else

  {

     return NEXT_RULE;

  }

 

   

////////////////////////////////

// This script may be useful with various dial rules.

//

// This script skips this dial rule if the dial string is not a 10 digit

// number.  This works for both H.323 and SIP.

 

alias = DIAL_STRING.replace(/^sips?:([^@]*).*/i,"$1");

if (!alias.match(/^[0-9]{10}$/))

  {

     return NEXT_RULE;

  }

   

 

////////////////////////////////

//   This script may be useful with "Resolve to conference room ID" dial rules.

//

//   If there are conference rooms with the same numbers as registered endpoints,

//   this script adds a prefix for conference rooms to distinguish them.

 

if(CALLER_SITE_NAME.match(/USDMAs/))

{

  if(!(DIAL_STRING.match(/^61*|^(sip:61|h323:61)/)))

  {

     if(DIAL_STRING.match(/^sip:/))

     {

        DIAL_STRING = DIAL_STRING.replace(/^sip:([^@]*@)/i,"sip:61$1");

     }

     else if (DIAL_STRING.match(/^h323:/))

     {

        DIAL_STRING = DIAL_STRING.replace(/^h323:([^@]*@)/i,"h323:61$1");

     }

     else

     {

        DIAL_STRING = "61" + DIAL_STRING;

     }

  }

  println("New translated DIAL_STRING: " + DIAL_STRING);

}

if(!(DIAL_STRING.match(/^61*|^(sip:61|h323:61)/))){

return NEXT_RULE;

}

 

Related Topics

Machine Translation

You are cautioned that the translation of this document is generated by a machine; therefore, the translated document may have errors and be inconsistent with the original English language version of the document.

The English language version of this document shall be considered the governing document related to the Polycom product.

If there is any contradiction between the English language version of the document and the translated version of the document, the English language version of the document shall take precedence.

The translation is provided for your convenience only. Neither Google nor Polycom shall be responsible for translated content or for the performance of the translation tool. If you require further assistance on non-translation issues, please contact Polycom support.

Translated documents are not available in PDF format.