Mirra
Mirra APIScripts

Scripts Overview

Scripts are serverless functions that run in isolated execution environments within the Mirra platform. Scripts execute in response to manual triggers, scheduled events, or real-time events from integrated services like Telegram, Gmail, and voice calls.

What are Scripts?

Scripts provide serverless compute capabilities for automation, data processing, and integrations. Each script runs in an isolated execution environment with configurable memory, timeout, and cost controls. Scripts can be triggered manually via the SDK API, automatically by subscribing to events from integrated services, or on a schedule.

The Mirra platform supports two runtime environments: Node.js 18 with TypeScript support and Python 3.11 with modern async/await syntax. Both runtimes provide access to the Mirra SDK, which enables scripts to interact with user data, send messages, create calendar events, and call external APIs through Resources.

Scripts support version control, allowing developers to maintain multiple versions and deploy specific versions safely. Each deployment creates a new function deployment, enabling rollback and testing workflows.

Syntax

Creating a Script

POST /api/sdk/v1/scripts

Node.js Handler

export async function handler(event, context) {
  // Process event data
  return { success: true, data: result };
}

Python Handler

async def handler(event, context):
    # Process event data
    return {"success": True, "data": result}

When to Use Scripts

Scripts are ideal for:

  • Automation - Auto-respond to messages, create reminders, log activities
  • Data Processing - Transform data, aggregate information, generate reports
  • Integrations - Connect external APIs, process webhooks, trigger workflows
  • Event Handling - React to Telegram messages, calendar events, voice calls
  • Scheduled Tasks - Run periodic jobs, health checks, data synchronization

Scripts abstract away infrastructure management, allowing developers to focus on business logic.


Runtime Environments

Node.js 18

The Node.js runtime provides TypeScript support, ES modules, and access to popular NPM packages. Scripts can import standard Node.js built-ins and common libraries like lodash, axios, and date-fns.

import { format } from 'date-fns';
 
export async function handler(event, context) {
  const timestamp = format(new Date(), 'yyyy-MM-dd HH:mm:ss');
  console.log('Executed at:', timestamp);
  
  return {
    success: true,
    timestamp,
    data: event
  };
}

Python 3.11

The Python runtime provides modern Python syntax with type hints, async/await support, and access to popular pip packages including requests, pandas, and numpy.

from datetime import datetime
 
async def handler(event, context):
    timestamp = datetime.now().isoformat()
    print(f"Executed at: {timestamp}")
    
    return {
        "success": True,
        "timestamp": timestamp,
        "data": event
    }

Event-Driven Execution

Scripts automatically execute when subscribed events occur. The event subscription system supports complex filtering with field-level conditions, enabling precise control over when scripts run. For example, a script can execute only for Telegram messages containing ticker symbols, or only for calendar events with specific attendees.

// Script automatically executes for matching events
export async function handler(event, context) {
  // event contains normalized fields across all trigger types
  const message = event.messageText;
  const sender = event.senderName;
  const timestamp = event.timestamp;
  
  // Process the event
  await mirra.memory.create({
    type: 'event_log',
    content: `${sender}: ${message}`,
    metadata: { timestamp }
  });
  
  return { success: true };
}

Event subscriptions are created via the SDK API. See Script Events for complete documentation on available events, filtering conditions, and subscription management.


Use Cases

Automation

  • Auto-respond to Telegram messages based on content or sender
  • Create calendar reminders before events
  • Log call summaries and transcripts to external systems
  • Track ticker mentions across all communication channels

Data Processing

  • Transform and validate incoming data
  • Aggregate information from multiple sources
  • Generate periodic reports
  • Sync data between Mirra and external systems

Integrations

  • Connect external APIs through Resources
  • Process webhooks from third-party services
  • Trigger workflows based on events
  • Send notifications to multiple channels

Marketplace Publishing

Scripts can be published to the Mirra marketplace with free, pay-per-execution, or subscription pricing models. Published scripts appear in marketplace listings and can be installed by other users. The marketplace supports staff picks, trending sections, and user reviews.


Next Steps

  • Endpoints - Complete API reference for all script operations
  • Events - Event-driven execution and subscriptions
  • Examples - Practical code examples and patterns
  • Technical Notes - Configuration, limits, and best practices

See Also

On this page