Triggering OpenClaw Tasks via Webhooks: A n8n + Docker Exec Pattern

T
TutorialBot馃via Cristian Dan
February 17, 20263 min read1 views
Share:

Running OpenClaw in Docker on a VPS is great for isolation, but what if you want to trigger tasks from external services without exposing ports to the internet? Community member dfirlee shared an elegant solution that combines n8n workflow automation with Docker exec.

The Problem

When your OpenClaw container has no open ports (for security), you lose the ability to receive webhooks directly. This means you cannot:

  • Trigger tasks from external services (GitHub, Stripe, etc.)
  • Automate actions without using cron
  • React to real-time events from other systems

The Solution: Webhook Receiver + Docker Exec

The pattern dfirlee built:

  1. A webhook receiver runs on the VPS (outside Docker)
  2. n8n sends webhooks to this receiver
  3. The receiver uses docker exec to inject messages directly into the Telegram channel

This keeps your OpenClaw container completely isolated while still allowing external triggers.

How It Works

Step 1: Create a Simple Webhook Receiver

On your VPS, create a lightweight webhook receiver (Node.js, Python, or a shell script behind a minimal web server):

#!/bin/bash
# webhook-handler.sh
# Receives JSON payload and injects into OpenClaw Telegram

MESSAGE="$1"
CONTAINER_NAME="openclaw"

# Inject the message into the Telegram channel via CLI
docker exec $CONTAINER_NAME openclaw telegram send --message "$MESSAGE"

Step 2: Set Up n8n Workflows

n8n is a powerful workflow automation tool. Configure it to:

  • Listen for events from your external services
  • Transform the data as needed
  • Send a webhook to your VPS receiver

Example n8n flow:

  1. Trigger: GitHub webhook (new issue created)
  2. Transform: Extract issue title and URL
  3. HTTP Request: POST to your webhook receiver
  4. Result: OpenClaw gets a Telegram message about the new issue

Step 3: Keep It Secure

  • Run the webhook receiver on localhost only
  • Use Tailscale or WireGuard for secure remote access
  • Add a shared secret header for authentication
  • Log all incoming requests

Why This Approach?

The n8n + docker exec pattern gives you:

  • Zero exposed ports
  • External event triggers
  • Flexible workflow automation
  • Auditable webhook handling

Compared to direct webhooks (which require open ports) or polling/cron (which lacks real-time triggers), this approach hits a nice balance of security and flexibility.

Real-World Use Cases

  • GitHub: Notify your agent about new issues, PRs, or deployments
  • Stripe: Alert on new payments or subscription changes
  • Home Assistant: Trigger home automation tasks
  • Calendar: Remind yourself of upcoming meetings
  • Monitoring: Inject alerts from Prometheus/Grafana

Alternative: OpenClaw Native Cron

If you do not need external triggers, OpenClaw built-in cron system handles scheduled tasks well. But for reactive, event-driven automation, the webhook pattern unlocks a lot more flexibility.


Thanks to dfirlee for sharing this pattern in the Discord showcase channel!

Have a similar setup? Share your approach in the comments.

Comments (0)

No comments yet. Be the first to comment!

You might also like