Code Node vs Custom Function
Write Your Code
1
Add a Code Node
Click the Code node from the left sidebar to add it to the canvas.
2
Open the code editor
Click Open on the code node to launch the code editor.
3
Write JavaScript
Write your JavaScript code in the editor. You have access to dynamic variables, call metadata, and the fetch function for HTTP requests.
4
Set response variables (optional)
Use Store Fields as Variables to extract values from your code’s return value and save them as dynamic variables. Specify a variable name and the JSON path to the value.For example, if your code returns
{ "status": "shipped", "estimated_delivery": "March 25" }:These variables can then be referenced as
{{order_status}} and {{delivery_date}} in other nodes.5
Test your code
Click Run Code at the bottom of the editor to test. Use the Dynamic Variables dropdown to set test values — these only apply during testing and won’t affect your live agent. The output panel shows the result and any
console.log() output.JavaScript Environment
Your code runs in a JavaScript sandbox with the following globals available. The code editor provides autocomplete for globals, dynamic variable names, and built-in functions.dv — Dynamic Variables
Access your agent’s dynamic variables as properties on the dv object. All values are strings.
metadata — Call Metadata
Access metadata passed when the call was created via the API.
fetch(url) — HTTP Requests
Make HTTP requests to external APIs. Works like the standard Fetch API.
console.log() — Debugging
Logs appear in the test output panel when using Run Code, and are also available in call logs.
- Standard JavaScript built-ins available:
Math,JSON,Date,Array,Object,Stringmethods, etc. - External packages (
require,import) are not available — usefetch()for external integrations - Code is limited to 5,000 characters
Examples
Format data from dynamic variables
Fetch data from a public API
Conditional logic with API call
Security and Architecture Guidance
When Can Transition Happen
If Wait for Result is turned off:- Speak During Execution on → transitions once agent is done talking
- Speak During Execution off → transitions immediately after code starts running
- User interrupts → transition happens once user is done speaking
- Speak During Execution on → transitions once code finishes and agent is done talking
- Speak During Execution off → transitions once code finishes
- User interrupts → transition happens once code finishes and user is done speaking