Triggers

Triggers are the entry points into your agent's flows, handling incoming events and initializing conversations with context and memory.

Trigger Types

MindedJS supports two types of triggers:

1. Webhook Triggers

Triggered by HTTP requests to specific endpoints in the Minded platform. Configured through the Minded platform interface. Each webhook trigger belongs to a specific agent and cannot be shared between agents.

Note: All triggers are agent-specific and configured through the Minded platform.

Webhook Structure

For webhook triggers, triggerBody contains:

  • body: The HTTP request body payload

  • headers: The HTTP request headers

// Webhook triggerBody structure
{
  body: any;        // Request payload
  headers: {        // Request headers
    'content-type': string;
    'x-forwarded-for': string;
    'user-agent': string;
    // ... other headers
  }
}

Accessing headers:

Common headers: x-forwarded-for, content-type, user-agent, and custom headers.

Validate Webhook Input

2. Schedule Triggers

Triggered automatically based on a cron schedule. Configured with a cron expression and optional timezone (defaults to UTC).

Cron Expression Format

Examples:

  • '0 0 * * *' - Daily at midnight

  • '0 9 * * 1' - Every Monday at 9:00 AM

  • '*/15 * * * *' - Every 15 minutes

  • '0 12 * * 1-5' - Every weekday at noon

Timezone Configuration

Use IANA timezone identifiers:

Behavior:

  • Automatically deployed when agent is deployed

  • Enabled when agent is "live", disabled otherwise

  • Creates new session unless sessionId is provided

Trigger Event

The TRIGGER_EVENT is emitted when any trigger is invoked, allowing you to qualify triggers and modify state before processing.

TriggerEvent Interface

Event Lifecycle

The handler serves two purposes:

  1. Qualifying Triggers: Return { isQualified: boolean } to determine if processing should continue

  2. Adding Information to State: Modify state directly by reference

Handler must return:

Modifying state:

Development Environment: Dashboard Messages

In development, agents are invoked with triggerName = 'dashboard_message' for dashboard messages. Handle this case to prevent default webhook behavior. Otherwise, avoid using this parameter.

Extracting Session ID from Webhooks

Extract a unique sessionId from webhook payloads to maintain conversation continuity.

Using parseSessionIdFromTrigger

Configure the Agent to automatically extract sessionId:

How it works:

  • Receives triggerBody as parameter

  • Returns a string session identifier

  • If undefined/null, platform generates a new sessionId

  • Used to resume existing agent sessions or create new ones

Examples:

Fallback: If not provided or returns undefined/null, checks triggerBody.sessionId, then generates a new UUID.

Session ID in Trigger Events

  • Sandbox Playground: Platform auto-generates sessionId for each execution

  • Production: Users provide their own sessionId to support resuming sessions

  • Session Continuity: Matching sessionId resumes previous state instead of starting fresh

  • Schedule Triggers: Creates new session unless sessionId is explicitly provided

Last updated