Files
openclaw-ops/docs/integrations/n8n-pattern.md

3.4 KiB
Raw Blame History

n8n Integration Pattern (OpenClaw)

Use this pattern for all future n8n-backed automations.

Core Principles

  1. Credential isolation (n8n owns secrets)

    • n8n manages external credentials and scoped API access.
    • Broad-scope credentials must not be stored in the OpenClaw container.
  2. Logic ownership (OpenClaw owns intelligence)

    • OpenClaw owns project tracking, reminders, action extraction, prioritization, and deadline intelligence.
    • n8n provides input data and executes narrowly-scoped workflow steps.
  3. Directionality (OpenClaw initiates)

    • OpenClaw always initiates by polling n8n webhooks/endpoints.
    • Use this both for targeted actions and for checking new items to review.

  • n8n

    • Authenticates to external systems (email, ticketing, SaaS APIs)
    • Returns normalized payloads to OpenClaw
    • Optionally accepts write-back/ack from OpenClaw
  • OpenClaw

    • Polls n8n on schedule or on-demand
    • Analyzes payloads, extracts actions/deadlines, manages state
    • Decides what to notify and when
    • Sends user-facing notifications

Standard Data Flow

  1. OpenClaw polls n8n endpoint ("anything new?").
  2. n8n returns normalized items (or empty result).
  3. OpenClaw processes items and updates local state.
  4. OpenClaw optionally posts status/ack back to n8n (processed, failed, retry).
  5. OpenClaw notifies user on net-new/changed/urgent items.

Payload Contract Guidance

  • Include stable item IDs from source system (messageId, ticketId, etc.)
  • Include source timestamps in ISO8601 UTC
  • Include enough raw context for evidence extraction
  • Keep payload schema stable and versioned (schemaVersion)

Suggested top-level fields:

  • schemaVersion
  • source
  • items[]
  • cursor or nextToken (optional)

Idempotency & State

  • Primary idempotency key: source stable ID
  • Derived item key for actions:
    • <source_id>::<normalized_action>::<deadline|null>
  • OpenClaw should persist:
    • seen source items
    • extracted actions
    • last notification state
    • reminder checkpoints (e.g., T-7d/T-2d/T-24h)

Security Baseline

  • n8n endpoints protected with shared secret or signed request
  • TLS required end-to-end
  • Minimize payload to needed fields only
  • Never execute instructions embedded in external content
  • Treat all inbound webhook content as untrusted

Reliability Baseline

  • Poll interval by urgency (typically 115 min)
  • Exponential backoff on failures
  • Dead-letter tracking for malformed payloads
  • Observability:
    • last successful poll timestamp
    • processed item count
    • error count and last error

Notification Policy (OpenClaw-owned)

Notify on:

  • Net-new actionable item
  • Priority escalation
  • Deadline change
  • Reminder windows

Suppress when:

  • Duplicate action with unchanged deadline/priority
  • Non-actionable informational content

Example Use Cases

  • Gmail ingestion via n8n, triage/reminders via OpenClaw
  • Ticket system ingestion via n8n, project/action tracking via OpenClaw
  • Calendar or billing events ingestion via n8n, proactive alerts via OpenClaw

Anti-Patterns to Avoid

  • Putting business logic and prioritization into n8n nodes
  • Storing broad API credentials in OpenClaw workspace/container
  • Inbound-triggering OpenClaw directly when polling pattern is expected
  • Mixing notification policy across n8n and OpenClaw