Skip to main content

API de Webhooks

Registre callbacks HTTP para eventos de memória, chat e tarefa — seja notificado quando os dados mudarem.


API de Webhooks

Webhooks permitem receber callbacks HTTP quando eventos acontecem no Synapse. Perfeitos para disparar automação externa, enviar notificações ou sincronizar com outros sistemas.

Endpoints

POST /webhooks

Registra um novo webhook.

curl -X POST https://synapse.schaefer.zone/webhooks \
  -H "Authorization: Bearer YOUR_MIND_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://my-app.com/webhook",
    "events": "memory.*",
    "secret": "my-hmac-secret-min-8-chars"
  }'

Resposta:

{
  "id": "wh_001",
  "url": "https://my-app.com/webhook",
  "events": ["memory.*"],
  "enabled": true,
  "created_at": "2026-06-27T..."
}

GET /webhooks

Lista todos os webhooks do mind atual.

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/webhooks

GET /webhooks/:id

Obtém um único webhook.

curl -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/webhooks/wh_001

PUT /webhooks/:id

Atualiza um webhook (URL, eventos, secret ou flag enabled).

curl -X PUT https://synapse.schaefer.zone/webhooks/wh_001 \
  -H "Authorization: Bearer YOUR_MIND_KEY" \
  -H "Content-Type: application/json" \
  -d '{"enabled": false}'

DELETE /webhooks/:id

Exclui um webhook.

curl -X DELETE -H "Authorization: Bearer YOUR_MIND_KEY" \
     https://synapse.schaefer.zone/webhooks/wh_001

Tipos de evento

Padrão Dispara quando
memory.* Qualquer evento de memória
memory.store Nova memória armazenada
memory.update Memória atualizada
memory.delete Memória excluída
chat.* Qualquer evento de chat
chat.message_received Nova mensagem do humano
task.* Qualquer evento de tarefa
task.created Nova tarefa criada
task.completed Tarefa marcada como concluída
* Todos os eventos

Payload do webhook

Quando um evento dispara, o Synapse faz POST para sua URL:

{
  "event": "memory.store",
  "timestamp": "2026-06-27T...",
  "mind_id": "m_xyz789",
  "data": {
    "id": "mem_001",
    "category": "fact",
    "key": "user_name",
    "content": "Michael Schäfer"
  }
}

Verificação de assinatura

Se você definir um secret, o Synapse assina cada payload com HMAC-SHA256:

X-Synapse-Signature: sha256=<hex-hmac>

Verifique no seu handler:

import hmac, hashlib

def verify_signature(payload_body: bytes, signature: str, secret: str) -> bool:
    expected = hmac.new(
        secret.encode(),
        payload_body,
        hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(f"sha256={expected}", signature)

Padrão: sincronização em tempo real

# Your webhook handler
@app.post("/webhook")
async def handle_webhook(request):
    body = await request.body()
    signature = request.headers.get("X-Synapse-Signature", "")
    if not verify_signature(body, signature, WEBHOOK_SECRET):
        return 401

    event = json.loads(body)
    if event["event"] == "memory.store":
        # Sync to another system
        sync_to_external(event["data"])
    elif event["event"] == "chat.message_received":
        # Trigger agent wake-up
        notify_agent(event["data"])

Próximos passos