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
- Go to Settings → Custom Actions
- Click "New Action"
- Select type: JavaScript
- 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
| Variable | Contains |
|---|---|
contact | Contact object (name, phone, email, tags) |
message | Last message object (text, type, timestamp) |
agent | Current agent (name, email) |
organization | Org 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
- Keep it simple — Complex logic belongs in webhooks
- Handle errors — Use try/catch
- Test locally — Verify logic before deploying
- Use for formatting — Best for data transformation, not business logic
Related Articles
Was this guide helpful?
Your feedback helps us make these guides better for everyone.