Engage Voice | Using the Scripting node

The Scripting node allows you to use custom JavaScript to add features to your IVR. Most people will probably only use the Scripting node when they want to include features in their IVRs that can’t be done with other nodes.
 
Although knowledge of JavaScript is required to use this node, there are some preexisting functions built into the node.

Adding a Scripting node

When you’re ready to add a Scripting node, follow these steps:
1. Drag and drop the Scripting node from the palette onto the background
2. Hover over the Scripting node to reveal the popup menu and select Edit to open the Script Properties modal window
3. Enter a name in the Node Id field (if desired)
4. Click on the third line of coding in the Java widget directly below the Node Id field
5. Press CTRL+SPACE to bring up a dropdown menu that lists the preexisting JavaScript functions
6. Continue entering code as desired
7. Click OK to close the modal window
View of adding Script Properties

JavaScript functions

Here are brief explanations of some of the functions that have been pre-built into the system.
  • stringToXml: Attempts to parse the provided string as an XML document and returns the document
    • Parameters: XML — a string of XML to parse
    • Returns: An org.w3c.dom.Document Java object
  • xmlToString: Returns the string representation of an org.w3c.dom.Document object
    • Parameters: XML — the document object to process
    • Returns: A string representation of the document
  • getNodeByUid: Returns a node from the IVR with the provided UID in the form of a JSON object. These nodes are a common parameter for other functions in the IVR scope
    • Parameters: UID — the UID string of the node to fetch
    • Returns: A JSON object representation of a node that can be used as a parameter for other API calls
  • goTo: Used to jump to another IVR node within the current visual IVR 
    • Parameters: UID —  pass in the UID of the desired IVR node to jump to another node 
  • executeHttpNode: This can be used to execute a WWW node without needing to leave the scope of the script block
    • Parameters: Node — the HTTP type node object to execute
    • Returns: A node object that the IVR would execute next if the HTTP node had been executed normally
  • enqueueCall: Used to take an IVR call and make it appear as if someone called another number on our platform
    • Parameters: ani (caller), dnis (number you want to enqueue to), and origDnis (original number the caller dialed)
  • waitForSilence: Waits and listens for a certain amount of silence. Once it ‘hears’ silence for that duration, or if the maxWaitTime has been reached, the function ends and the script can continue 
    • Parameters:
  • silenceDuration — the ‘amount’ of silence to wait for (in seconds) 
  • maxWaitTime — the max amount of time that the IVR will listen for silence
  • setDateFormat: Sets the date format used by the formatDate function
    • Parameters: Format — the format string to apply
  • formatDate: Returns the string representation of the given date object. The format can be set with the setDateFormat function
    • Parameters: Date — the date to format
    • Returns: A formatted string representation of the provided date
  • setAutoConference: Disables the auto conference that happens when a call enters an IVR 
    • Parameters: Autoconference (true or false) 
  • sendCallToConference: Used to manually send the call to conference if you setAutoConference to false 
  • makeOutboundCall: Joins another call to the IVR conference
    • Parameters:
  • Dial destination — the number you want to dial 
  • Caller ID — the caller ID you want to display to the called party
  • Ring duration — how long in seconds to ring the called party (the voicemail may pick up before this ends if you set it too high) 
  • TT accept — true or false (where true will require but not prompt  the called party to press a digit on their phone to connect the call) 
  • TT accept time — how long in seconds to wait for the called party to accept the call using TT accept
  • Whisper audio — the name of the audio file you want to play to the destination prior to joining the outbound call to the IVR 
  • setTTAcceptList: Sets the digits available for TT accept if it is enabled and you trigger an add session from the IVR (for example, a transfer from the IVR would trigger an add session)
  • setEarlyHangupMessage: Used to override the default earlyHangupMessage that eventually gets logged in the IVR result. Default is ‘caller_hungup’
  • setHangupHandler: Triggers a set node on hangup
    • Parameters: the response of getNodeByUid
  • setDTMFHandler: Triggers a node on DTMF
    • Parameters: the response of getNodeByUid
  • getSIPHeader: Used to pull data from the SIP header of the call to be usable in IVR Studio
    • Parameters: header name — the name of the header that was embedded in the SIP call
    • Returns: Data that is stored in the SIP header with the name used 
  • setAutoTermInfo: Enables/disables automatic termination reason updates (default is off)
    • Parameters: autoTermInfo — if true, enables auto term reason updates
  • setTermInfo: Sets termination information on caller session
    • Parameters:
  • Party — terminating party to set
  • Reason — terminating reason to set
  • setIvrTermInfo: Sets termination information on IVR session
    • Parameters
  • Party — terminating party to set
  • Reason — terminating reason to set
  • sendIvrSession: Sets flag for automatic sending of IVR specific session information on update
    • Parameters: sendIvrSession — T/F to auto send IVR session info
  • terminateCallSession: Used to terminate a particular session of a call once conferenced
    • Parameters: sessionId — ID of the session leg to terminate from the conference
  • getUii: Used to get the UII, a unique identifier of the current call in the CCI platform
    • Returns: A string representing the call UII
  • getAccountId: Returns the Account ID that the current call belongs to
  • getAni: Returns the caller’s phone number
    • Returns: An unformatted string of the ANI
  • getDnis: Returns the number the CCI platform received the call on
    • Returns: An unformatted string of the DNIS
  • getDialDisposition: Pulls the dial disposition off the session if it’s available. This should apply mostly to calls that were on platform and transferred to an IVR
  • getRecordingUrl: Returns the location where the call recording will be available after the call is terminated and processed
    • Returns: A string containing the eventual URL of the call recording
  • getData: Fetches data that was added to the key/value story by the putData() function
    • Parameters: Key — name of the data point to retrieve
  • putData: Adds data to a key/value store that is unique to the current call. This data is not persistent and is discarded at the end of the call. Use the putReportField() function if you wish to add data that will persist after the call terminates and be available in reports
    • Parameters: 
  • Key — a name for the data point
  • Value — the value to associate with the key
  • getReportField: Fetches data that was added to the reportable key/value store by the putReportField() function
    • Parameters: Key — name of the data point to retrieve
    • Returns: the value associated with the key
  • putReportField: Adds data to a key/value store that is unique to the current call and persists after the call completes
    • Parameters:
  • Key — a name for the data point
  • Value — the value to associate with the key
  • setConnection: Sets the name of the connection to the next node that will be processed when the current script ends
    • Parameters: Connection — the ID of a connection from the Scripting node
  • setContainerConnection: Used to define the path when exiting a container 
    • Parameters: Connection — the ID of a connection from the Container node
  • getConnection: Gets the name of the connection to the next node that will be processed when the current node ends
    • Returns: The ID of the connection currently set to be processed next
  • getContainerConnection: Gets the name of the connection to the next node that will be processed when the current container is complete
    • Returns: The ID of the connection currently set to be processed next
  • sleep: Pauses execution for the specified number of milliseconds
    • Parameters: Milliseconds — duration to sleep
  • error: Log an error message to the IVR debug log
    • Parameters: Message — error message to display
  • debug: Adds a message to the debug log 
    • Parameters: Message — string to include in the log

Using Scripting Connection Properties

Another important aspect of the Scripting node is that it can have more than one connector arrow extending from it. And for each connector arrow, there will be connector arrow properties that need to be configured. As with other connector arrows with properties, a question mark inside a circle over each arrow indicates there are properties to configure.
 
The Scripting node has connector arrow properties because it can be used for branching. 
 
For example, let’s say before your Scripting node you used a Get Input node to retrieve account numbers from callers. You might then follow the Get Input node with a WWW node to retrieve information about the accounts from an external resource. 
 
You can then process the information retrieved through the WWW node through a Scripting node and in this way determine which pathway calls should take.

When you double-click on the circle with a question mark on a connector arrow extending from a Scripting node, the Scripting Properties modal window will appear. You’ll see the Connection Id field. This is where you enter the variable that will determine whether or not calls follow this pathway.
© 1999-2022 RingCentral, Inc. Tous droits réservés.
Thanks!
We've sent you a link, please check your phone!
Please allow a full minute between phone number submissions.
There was an issue with SMS sending. Please try again. If the issue persists, please contact support.