wulf-pulse/app/api/admin/openclaw-instances/route.ts
lorentz 414ad78c36 feat: repo commit tracking and OpenClaw notification
- Migration 058: repo_commits + openclaw_instances tables (seeded with overwatch)
- POST /api/webhooks/forgejo: receives Forgejo push events, stores commits,
  forwards HMAC-signed payload to all enabled OpenClaw instances, sends Telegram
- GET /api/openclaw/repo-commits: OpenClaw polling endpoint (filters: since, repo, branch, limit)
- GET/POST /api/admin/openclaw-instances: manage instance registry
- PATCH/DELETE /api/admin/openclaw-instances/[id]: update/remove instances
- FORGEJO_WEBHOOK_SECRET in .env.local (leave empty to skip HMAC verification)
2026-03-21 18:52:22 -04:00

32 lines
1 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { postgresClient } from '@/lib/services/postgres-client';
export async function GET() {
const result = await postgresClient.query(
`SELECT id, name, webhook_url, enabled, last_notified_at, created_at
FROM openclaw_instances
ORDER BY created_at`
);
return NextResponse.json({ data: result.rows });
}
export async function POST(request: NextRequest) {
const body = await request.json();
const { name, webhook_url, webhook_secret, enabled = true } = body;
if (!name || !webhook_url || !webhook_secret) {
return NextResponse.json(
{ error: 'name, webhook_url, and webhook_secret are required' },
{ status: 400 }
);
}
const result = await postgresClient.query(
`INSERT INTO openclaw_instances (name, webhook_url, webhook_secret, enabled)
VALUES ($1, $2, $3, $4)
RETURNING id, name, webhook_url, enabled, created_at`,
[name, webhook_url, webhook_secret, enabled]
);
return NextResponse.json({ data: result.rows[0] }, { status: 201 });
}