Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:23blocks OS Ai maestro Webhook Service

From Leeroopedia
Knowledge Sources
Domains Webhooks, Persistence
Last Updated 2026-10-26 18:00 GMT

Overview

Concrete tool for file-based CRUD of webhook subscriptions with HMAC signing and delivery, provided by AI Maestro's `lib/webhook-service.ts`.

Description

The webhook-service module manages webhook subscriptions persisted as a JSON array at `~/.aimaestro/webhooks.json`. It generates a secure random signing secret per webhook (`whsec_` + 32 random hex bytes), supports CRUD (`loadWebhooks`, `saveWebhooks`, `getWebhook`, `createWebhook`, `deleteWebhook`), and delivers webhook payloads by computing an HMAC-SHA256 signature over the body and sending it with an `X-Webhook-Signature` header. Event types include agent lifecycle, email change, and other AI Maestro events.

Usage

Call `createWebhook(request)` to subscribe a URL to events. Call `deliverWebhook(webhook, eventType, payload)` to send a signed payload. Call `getWebhook(id)` to look up a subscription for verification.

Code Reference

Source Location

  • Repository: ai-maestro
  • File: lib/webhook-service.ts
  • Lines: L1-L321

Signature

export function loadWebhooks(): WebhookSubscription[]
export function saveWebhooks(webhooks: WebhookSubscription[]): boolean
export function getWebhook(id: string): WebhookSubscription | null
export function createWebhook(request: CreateWebhookRequest): WebhookSubscription
export function deleteWebhook(id: string): boolean
export async function deliverWebhook(
  webhook: WebhookSubscription,
  eventType: WebhookEventType,
  payload: WebhookAgentPayload | WebhookEmailChangedPayload
): Promise<{ success: boolean; statusCode: number; error?: string }>

Import

import { createWebhook, deleteWebhook, deliverWebhook, loadWebhooks } from '@/lib/webhook-service'

I/O Contract

Inputs

Name Type Required Description
request CreateWebhookRequest Yes (create) URL, event types, description
id string Yes (get/delete) Webhook subscription ID
webhook WebhookSubscription Yes (deliver) Subscription with URL + signing secret
payload object Yes (deliver) Event payload to deliver

Outputs

Name Type Description
createWebhook() returns WebhookSubscription New subscription with generated secret
deliverWebhook() returns { success, statusCode, error? } Delivery result
loadWebhooks() returns WebhookSubscription[] All subscriptions (empty on error)

Usage Examples

Subscribe and deliver

import { createWebhook, deliverWebhook } from '@/lib/webhook-service'

// 1. Subscribe a URL to agent events
const webhook = createWebhook({
  url: 'https://example.com/webhook',
  eventTypes: ['agent.created', 'agent.deleted'],
  description: 'External CI trigger',
})

// 2. Deliver a signed payload
await deliverWebhook(webhook, 'agent.created', {
  agentId: 'abc-123',
  name: 'website',
  action: 'created',
})

Related Pages

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment