Custom JavaScript Code Block
Inserts a fragment of programmer-defined JavaScript code into the voice application.
The JavaScript programmer is responsible for the validation of the code.
Settings
•Label - Change the name of the block if needed to uniquely identify the use of this block in the application flowchart.
When Configuration for this Block is Complete:
•Click Update to apply the settings.
Application Context
Every voice application is associated with an application context. The objAppCtx variable holds a reference to Application Context object which can be accessed in the Java script block. The object exposes methods which are available to be invoked in Java Script Block.
Logging
The objAppCtx can be used to log information in the Java script block with different log levels.
Methods
•LogDebug()
•LogInfo()
•LogError()
•LogPanic()
Example
objAppCtx.LogInfo("Some Information for log"); // log some data
Config Data
The objAppCtx exposes the following methods to store custom data in the form of a key value pair, and access it across the application through a Javascript block.
•objAppCtx.Config.Item() - Store or Retrieve custom data by passing the key
•objAppCtx.Config.CheckKey() - Check if the key is valid
• objAppCtx.Config.Delete() - Delete the data associated with the key
Example
objAppCtx.Config.Item("SomeKey") = “SomeData”;
if(objAppCtx.Config.CheckKey(“SomeKey”))
{
objAppCtx.LogInfo("Data stored in SomeKey is: " + objAppCtx.Config.Item("SomeKey"));
}
objAppCtx.Config.Delete(“SomeKey”);
Interaction Properties
Interaction properties stored for the application can also be accessed in the Javascript block using the methods exposed by objAppCtx.
Examples:
if(!objAppCtx.Config.CheckKey("Interaction"))
{
objAppCtx.LogError("No interaction attached to call!");
return "error";
}
else
{
Var hData["InteractionData"] = objAppCtx.Config.Item("Interaction").Attributes;
objAppCtx.LogInfo("ANI: " + hData.Item(“ANI”));
}
XML DOM Node
objBlockDOMNode variable contains a reference to the MS XML object, which refers to the block XML node in the application XML file.
Examples
objBlockDOMNode.selectSingleNode("Configuration/Param[@Name='SomeCustomParam']/text()").nodeValue // custom parameters access