- Manipulate user input parameters before executing an API call.
- Manipulate the parameters from an API response payload before continuing with the dialog.
- Display custom error messages to the user.
- Make decisions based on complex business rules.
Add the Node
The setup of a Script node in a dialog task involves the following steps:- Select the AI Agent you want to work with.
- Open the dialog task to add the Script node to.
- Add the script node in the designated place. For steps in adding nodes, refer here.
- The Script window is displayed with the Component Properties tab selected by default.
- You can configure the Connection Properties — refer here for details.
You can add a script node within an existing sequence or outside any existing sequence. If you add it outside, a new, untitled sequence will automatically get created containing the new script node.
Configure the Node
Component Properties
The configurations you set up or edit in these sections reflect in all other dialog tasks that use this node.
- On the Component Properties tab, enter a Name and Display Name for the script node. Node names cannot have spaces.
- Under the Script Definition section, click Define Script to add JavaScript.
- On the Script Definition window, enter your JavaScript and then click Save. Enable Auto Save to save your work automatically after one second of inactivity. It must be re-enabled each time you open the editor. See below for JavaScript code examples.
- In the Variable Namespaces section, associate the variable namespaces to execute this node and its transitions. This option is visible only when the variable namespace is enabled for the AI Agent. You can go with the task level settings or customize it for this node. For more information, refer to Managing Namespace.
Instance Properties
Use the Instance Properties to define any user tags that you want to set for the Script node.The settings in the Instance Properties tab are specific to the current dialog task and do not reflect in other dialog tasks that use this node.
- On the Script node properties panel, click the Instance Properties tab.
- Under the Custom Tags section, add tags to build custom profiles of your AI Agent’s conversations. Click here for more.
Connections Properties
You can write conditional statements based on the values of any Entity or Context Objects in the dialog task, or you can use Intents for transitions.The conditions configured here are applicable only for this instance and will not affect this node when being used in any other dialog. The connection properties would be present only if this is the bottommost node of a sequence.
- Not Connected — No specific next node is defined.
- End of Dialog — Explicitly ends the current dialog.
- Return to Flow — Terminates the Dialog Task and returns control to the Flow Builder. The Flow Builder resumes from the next node.
- Enable the Deflect to Chat option to create conversation flows that transition from voice to chat-based interactions within the same context. It has two deflection types: Automation and Agent Transfer.
Deflect to Chat works only with Kore Voice Gateway Channels (Phone number or SIP Transfer).
JavaScript Examples
Using JavaScript, you can customize your dialog task by processing data before or after an API call — for example, directing the dialog task flow. You can use theContext object type-ahead feature to identify and select dynamic variables. For more information, refer to Context Object.
Manipulating Data
In JavaScript, you can fetch data from the session data using session variables. For example, you can GET the user ID usingcontext.session.UserContext.identities, and then PUT the data into context as shown in the following example.
Handling Conditions
The following code example returns the customer ID using aContext object variable from the Service node response body when the ID is not provided in the data.results.
Handling Flow
The next Script node code example validates the bank transfer amount that does not exceed limits for the type of account selected usingContext object variables.
- koreUtil libraries — Pre-written JavaScript functions to make common or complex tasks easy to implement.
- Script Nodes, Call Flows, Agent Utils, and userSessionUtils