feat(n8n): wire notify and persist append logs
This commit is contained in:
@@ -1,24 +1,55 @@
|
||||
# openclaw-action workflow
|
||||
|
||||
This skill ships an importable draft workflow at:
|
||||
This skill ships an importable workflow at:
|
||||
|
||||
- `assets/openclaw-action.workflow.json`
|
||||
|
||||
It implements the first safe router contract for local OpenClaw → n8n calls.
|
||||
It implements a real local OpenClaw → n8n router.
|
||||
|
||||
## What it does
|
||||
|
||||
- accepts `POST /webhook/openclaw-action`
|
||||
- normalizes incoming JSON into:
|
||||
- `action`
|
||||
- `args`
|
||||
- `request_id`
|
||||
- routes two known actions:
|
||||
- normalizes incoming JSON into an action contract
|
||||
- supports two live actions:
|
||||
- `append_log`
|
||||
- `notify`
|
||||
- returns normalized JSON responses
|
||||
- returns `400` for unknown actions
|
||||
- returns `400` when required branch args are missing
|
||||
- returns `400` when required args are missing
|
||||
|
||||
## Current side effects
|
||||
|
||||
### `append_log`
|
||||
|
||||
- appends records into workflow static data under key:
|
||||
- `actionLog`
|
||||
- keeps the most recent `200` entries
|
||||
- persists in n8n's database when the workflow execution succeeds
|
||||
|
||||
Example stored record:
|
||||
|
||||
```json
|
||||
{"ts":"2026-03-12T07:00:00Z","source":"openclaw-action","request_id":"abc","text":"backup complete"}
|
||||
```
|
||||
|
||||
Why this first:
|
||||
- built-in, no extra credentials
|
||||
- persists without guessing writable filesystem paths
|
||||
- better fit than MinIO for small, recent operational breadcrumbs
|
||||
|
||||
When to use MinIO later:
|
||||
- long retention
|
||||
- rotated archives
|
||||
- large/batched exports
|
||||
- sharing logs outside n8n
|
||||
|
||||
### `notify`
|
||||
|
||||
- sends a Telegram message using credential:
|
||||
- `Telegram Bot (OpenClaw)`
|
||||
- sends a Discord message using credential:
|
||||
- `Discord Bot Auth`
|
||||
- current targets mirror the already-working reminder workflow
|
||||
|
||||
## Intentional security choice
|
||||
|
||||
@@ -48,8 +79,6 @@ After import, set this manually in n8n:
|
||||
|
||||
## Expected URLs
|
||||
|
||||
Assuming the current local service address:
|
||||
|
||||
- test: `http://192.168.153.113:18808/webhook-test/openclaw-action`
|
||||
- prod: `http://192.168.153.113:18808/webhook/openclaw-action`
|
||||
|
||||
@@ -60,20 +89,10 @@ Assuming the current local service address:
|
||||
|
||||
## Example tests
|
||||
|
||||
Direct curl:
|
||||
|
||||
```bash
|
||||
curl -i -X POST 'http://192.168.153.113:18808/webhook-test/openclaw-action' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H 'x-openclaw-secret: YOUR_SECRET_HERE' \
|
||||
--data @assets/test-append-log.json
|
||||
```
|
||||
|
||||
Via skill helper:
|
||||
|
||||
```bash
|
||||
export N8N_WEBHOOK_SECRET='YOUR_SECRET_HERE'
|
||||
scripts/call-action.sh append_log --args '{"text":"backup complete"}' --test --pretty
|
||||
scripts/call-action.sh append_log --args '{"text":"backup complete"}' --pretty
|
||||
scripts/call-action.sh notify --args '{"title":"Workflow finished","message":"n8n router test"}' --pretty
|
||||
```
|
||||
|
||||
## Expected success examples
|
||||
@@ -86,9 +105,14 @@ scripts/call-action.sh append_log --args '{"text":"backup complete"}' --test --p
|
||||
"request_id": "test-append-log-001",
|
||||
"result": {
|
||||
"action": "append_log",
|
||||
"status": "accepted",
|
||||
"status": "logged",
|
||||
"preview": {
|
||||
"text": "backup complete"
|
||||
},
|
||||
"sink": {
|
||||
"type": "workflow-static-data",
|
||||
"key": "actionLog",
|
||||
"retained_entries": 200
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,39 +126,12 @@ scripts/call-action.sh append_log --args '{"text":"backup complete"}' --test --p
|
||||
"request_id": "test-notify-001",
|
||||
"result": {
|
||||
"action": "notify",
|
||||
"status": "accepted",
|
||||
"status": "sent",
|
||||
"preview": {
|
||||
"title": "Workflow finished",
|
||||
"message": "n8n router test"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Expected failure examples
|
||||
|
||||
### unknown action
|
||||
|
||||
```json
|
||||
{
|
||||
"ok": false,
|
||||
"request_id": "",
|
||||
"error": {
|
||||
"code": "unknown_action",
|
||||
"message": "action is not supported"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### missing required args
|
||||
|
||||
```json
|
||||
{
|
||||
"ok": false,
|
||||
"request_id": "",
|
||||
"error": {
|
||||
"code": "invalid_request",
|
||||
"message": "required args are missing"
|
||||
},
|
||||
"targets": ["telegram", "discord"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user