Back to Help Home
Integrations & API

Using the JavaScript VM for custom actions

4 minutes read time Difficulty: advanced

JavaScript VM for custom actions

Execute JavaScript code as custom actions during conversations for advanced automation.

What is the JS VM?

AIsoule includes a sandboxed JavaScript virtual machine that can execute custom code when triggered by an agent or chatbot flow.

Creating a JS action

  1. Go to Settings → Custom Actions
  2. Click "New Action"
  3. Select type: JavaScript
  4. Write your code:
// Available context:
// contact - current contact object
// message - last message
// agent - current agent

// Example: Format and return data
const result = {
  formatted_phone: contact.phone_number.replace('+91', '0'),
  greeting: `Hello ${contact.name || 'there'}!`
};

return result;

Available context variables

VariableContains
contactContact object (name, phone, email, tags)
messageLast message object (text, type, timestamp)
agentCurrent agent (name, email)
organizationOrg details (name, id)

Limitations

  • Timeout: 5 seconds max execution
  • No network access: Cannot make HTTP calls (use webhook type instead)
  • Sandboxed: No access to filesystem or system APIs
  • Memory: Limited to 10MB

Use cases

  • Format data before displaying
  • Calculate values (discounts, dates)
  • Generate reference numbers
  • Transform contact data

Tips

  1. Keep it simple — Complex logic belongs in webhooks
  2. Handle errors — Use try/catch
  3. Test locally — Verify logic before deploying
  4. Use for formatting — Best for data transformation, not business logic

Was this guide helpful?

Your feedback helps us make these guides better for everyone.