VoltAPI is a powerful sandbox environment that allows you to write and execute custom JavaScript code directly within Chatvolt. It enables you to process data, transform content, and integrate with internal Chatvolt services in real-time.

Key Features

Internal Logic

Write JavaScript to process data, calculate values, or transform content for your agents and internal workflows.

Secure Execution

Your code runs in an isolated environment with built-in protection and monitored logs.

Workflow Integration

Execute your functions as part of your agent’s decision-making process or automation flows.

AI Assistant

Use our built-in AI assistant to help you write, debug, and optimize your functions.

Writing Your First Function

VoltAPI functions are asynchronous JavaScript functions that receive an input object and return a result. These functions are designed to be called by Chatvolt’s internal systems.

async (input) => {
    const name = input.name || 'Guest';
    console.log(`Processing request for ${name}`);
    
    return {
        success: true,
        message: `Hello, ${name}!`,
        timestamp: new Date().toISOString()
    };
}

The Sandbox Environment

The execution environment provides several built-in utilities:

input

The data sent to your function during execution by the calling internal service.

voltApi

A built-in utility to interact with Chatvolt services with pre-configured authentication.

  • voltApi.get(url): Performs an authenticated GET request.
  • voltApi.post(url, body): Performs an authenticated POST request.

fetch(url, options)

A standard fetch implementation with built-in SSRF (Server-Side Request Forgery) protection for reaching external services from within your function.

console

Standard logging utilities. Logs are captured and displayed in the execution console for debugging.

  • console.log()
  • console.error()
  • console.warn()
  • console.info()

Managing Your Functions

In the VoltAPI dashboard, you can easily manage your existing functions:

  • Create: Click the “Add” (+) button in the sidebar to create a new function. A unique name will be generated automatically, which you can rename later.
  • Rename: Use the menu (three dots) next to a function name in the sidebar to rename it.
  • Delete: Remove functions you no longer need. This action is irreversible.
  • Disable/Enable: Toggle the status of your function. Disabled functions will not execute when triggered by internal workflows.

Experimental Feature

VoltAPI is currently an Experimental Feature. While powerful, it may undergo changes as we refine the sandbox environment and its capabilities.

AI Assistant

If you’re unsure how to implement a specific logic, use the AI Assistant button in the toolbar. It can generate code snippets, explain complex functions, and help you debug execution errors.

Best Practices

  1. Async/Await: Always use async functions and await for promises to ensure proper execution flow.
  2. Error Handling: Use try/catch blocks within your functions to handle potential errors gracefully.
  3. Logs: Use console.log extensively during development; logs are invaluable for debugging failed executions.
  4. Input Validation: Always validate the input object to ensure it contains the expected data before processing.
  5. Security: Avoid including sensitive hardcoded secrets in your code. Use environment-aware integrations when possible.

Limitations

  • Internal Only: VoltAPI functions are designed for internal use within the Chatvolt ecosystem and are not exposed as public endpoints.
  • Timeout: Functions have a maximum execution time (typically 30 seconds).
  • Memory: There is a limit on the maximum memory available for each execution.
  • Modules: Standard Node.js modules are not available; you must use the provided built-in utilities.