Skip to main content

Webhooks API

Daftarkan HTTP callback untuk event memori, chat, dan tugas — dapatkan notifikasi saat data berubah.


Webhooks API

Webhooks memungkinkan Anda menerima HTTP callback ketika event terjadi di Synapse. Sempurna untuk memicu otomasi eksternal, mengirim notifikasi, atau sinkronisasi ke sistem lain.

Endpoint

POST /webhooks

Mendaftarkan webhook baru.

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"
  }'

Respons:

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

GET /webhooks

Mendaftar semua webhook untuk mind saat ini.

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

GET /webhooks/:id

Mengambil satu webhook.

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

PUT /webhooks/:id

Memperbarui webhook (URL, event, secret, atau 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

Menghapus webhook.

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

Tipe Event

Pola Aktif saat
memory.* Event memori apa pun
memory.store Memori baru disimpan
memory.update Memori diperbarui
memory.delete Memori dihapus
chat.* Event chat apa pun
chat.message_received Pesan baru dari manusia
task.* Event tugas apa pun
task.created Tugas baru dibuat
task.completed Tugas ditandai selesai
* Semua event

Payload Webhook

Saat event aktif, Synapse melakukan POST ke URL Anda:

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

Verifikasi Tanda Tangan

Jika Anda menetapkan secret, Synapse menandatangani setiap payload dengan HMAC-SHA256:

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

Verifikasi di handler Anda:

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)

Pola: Sinkronisasi Real-Time

# 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"])

Langkah Berikutnya