This block doesn’t allow you to create a custom visual block

Configuration Options
Script Name
- Name Field: Optional identifier for organizing and debugging scripts (default: “Script”)
- Purpose: Helps identify scripts in flow diagrams and logs
Code Editor
- Full JavaScript Editor: Syntax highlighting and multi-line support
- Variable Integration: Direct access to bot variables using
{{Variable Name}}syntax - Variable Button: Insert variables directly into your code
Execution Environment
Choose where your script executes:-
Client-side (Default): Code runs in the user’s browser
- Full access to browser APIs (
window,document,navigator, etc.) - No access to
setVariable()function - Depends on user’s browser capabilities
- Good for DOM manipulation, browser APIs, and client-side features
- Full access to browser APIs (
-
Server-side: Code runs in a secure, isolated environment
- Access to
setVariable()function for modifying bot variables - Custom
fetch()API for external HTTP requests - No access to browser APIs
- Better for security-sensitive operations and API integrations
- Access to
Variables in script are not parsed, they are evaluated. So it should be treated as if it were real javascript variables.You need to write
console.log({{My variable}}) instead of console.log("{{My variable}}")Features
Variable Management (Server-side Only)
Use thesetVariable() function to modify bot variables programmatically when running server-side:
- First parameter: Variable name (as a string, exactly as it appears in your bot)
- Second parameter: The new value to set
- The variable must already exist in your bot
API Integration (Server-side)
Server-side scripts have access to a custom
fetch() function. Client-side scripts can use the
standard browser fetch() API.Conditional Logic
Implement complex business logic that’s difficult to achieve with standard blocks:Advanced Features
External API Calls
Integrate with third-party services and APIs:Data Processing
Process and transform user data:Browser Interactions (Client-side Only)
Access browser APIs when running on the client (default execution):Server-side Limitations
Because server scripts run in an isolated, secure environment:Unavailable APIs
- Console Functions:
console.log,setTimeout,setIntervalnot available - Browser APIs: No access to
window,document,localStorage, etc. - Node.js Modules: Cannot use
importorrequirestatements - Global Objects: Limited global scope compared to browser environment
Modified Fetch Behavior
Thefetch function works differently on the server:
Example Use Cases
CRM Integration (Server-side)
Dynamic Pricing (Server-side)
Browser Page Control (Client-side)
Troubleshooting
Common Script Errors
- Variable Access: Ensure variables exist and contain expected data types
- Syntax Errors: Check JavaScript syntax and bracket matching
- Async Issues: Use await with Promise-based operations
- Type Errors: Validate variable types before processing
Server-side Issues
- Fetch Errors: Remember server-side fetch returns strings directly
- Missing Functions: Global browser functions aren’t available
- API Timeouts: Implement proper error handling for external calls
- Memory Limits: Keep scripts efficient to avoid timeout issues
Client-side Issues
- Browser Compatibility: Test across different browsers and devices
- Security Restrictions: Some browsers block certain operations
- Network Issues: Handle offline scenarios gracefully
- Mobile Limitations: Consider mobile browser capabilities
Performance Problems
- Slow Execution: Optimize loops and reduce API calls
- Memory Usage: Clean up variables and avoid memory leaks
- Network Delays: Implement reasonable timeouts for external calls
- Error Recovery: Provide fallbacks when scripts fail