V8 JavaScript Engine Node
The V8 JS Engine Node is the most powerful tool in the Querlo Studio arsenal. It enables developers to execute custom JavaScript code directly within the chat flow, providing a "Do-it-all" environment for complex requirements.
How it Works
When the chat flow reaches a V8 Node, the execution engine spins up a isolated, high-performance V8 sandbox. Your code is executed within this sandbox, meaning it doesn't interfere with the main chat server while still having access to the current conversation's state.
Key Features
1. Full JS Runtime
You have access to a standard JavaScript environment. You can use standard objects like Math, JSON, Date, and perform operations on strings, arrays, and objects.
2. Session Variable & Global Access
The V8 Node provides comprehensive access to both system globals and session variables.
- Globals: Access metadata like
chat_idanduser_idinstantly. - Autocomplete Support: Our IDE-grade editor provides full autocomplete for every variable in your flow, significantly reducing bugs and development time.
// Example: Calculating a discount
let total = variables.order_subtotal;
if (total > 100) {
variables.discount_applied = true;
variables.final_price = total * 0.9;
}3. Debugging & Logging
Debugging complex logic is simple with built-in console support. You can use console.log() to output data not only to the Querlo Studio debug console but also to the browser's native console.
- Console Tracking: View outputs in real-time within the Studio editor.
- Native Browser Console: To see your logs in the browser's developer tools (F12), you must enable debug mode using one of these methods:
- URL Parameter: Add
debug=1to your chat URL (e.g.,https://chat.querlo.com/CHAT_ID?debug=1). - Embed Option: Set
debug: truein your JavaScript/SDK embed options.
- URL Parameter: Add
- Error Handling: Use
try/catchblocks to handle exceptions gracefully. - Detailed Exceptions: If a script fails, the engine provides detailed error messages and stack traces.
try {
let data = await callExternalAPI();
console.log("Data received:", data);
} catch (e) {
console.error("API Call failed:", e.message);
variables.api_error = true;
}Best Practices
- Keep it Modular: For very complex logic, consider breaking it into multiple V8 nodes or using our Global Scripts feature.
- Validate Data: Always check if the variables you are accessing exist before performing operations on them.
- Use try/catch: Ensure your bot doesn't "hang" by catching potential errors in network requests or data parsing.
API Reference
The following global objects are available within the V8 Node:
| Object | Description |
|---|---|
| `variables` | Access to session variables (Read/Write) |
| `console` | Standard logging (`log`, `warn`, `error`) |
| `fetch` | Perform HTTP requests to external APIs |
| `context` | Meta-data about the current user and session |