Webhooks Integration
Webhooks allow your application to receive real-time notifications when events occur in Memoram, such as when memories are created, updated, or deleted.
This eliminates the need for polling the API for updates and allows for a more reactive user experience.
Auto-Registration
When you create a new AI connector project in the Memoram dashboard, webhook subscriptions are automatically created for you (initially inactive). You can configure the target URL and activate these webhooks through the developer dashboard.
Benefits of Using Webhooks
- Real-time Updates: Receive notifications immediately when events occur.
- Reduced API Calls: Avoid constant polling.
- Better User Experience: React to changes instantly.
Implementation Steps
- Configure Webhook URL: Set up an endpoint in your application (a publicly accessible URL) to receive HTTP POST requests from Memoram.
- Activate Webhooks: Enable the desired event types and provide your endpoint URL in the Memoram Developer Dashboard for your registered application.
- Implement Signature Verification: Verify webhook signatures to ensure the requests genuinely originate from Memoram and haven’t been tampered with.
- Process Events: Handle the incoming webhook event payloads in your application.
- Respond Quickly: Your endpoint should respond with a
2xx
status code (e.g.,200 OK
) promptly to acknowledge receipt. Avoid lengthy processing in the webhook handler itself; process asynchronously if needed.
Supported Event Types
(Verify these event names are correct)
memory.created
: Triggered when a new memory is created.memory.updated
: Triggered when a memory is updated.memory.deleted
: Triggered when a memory is deleted.tag.created
: Triggered when a new tag is created.tag.updated
: Triggered when a tag is updated.access_request.approved
: Triggered when a user approves an access request.access_request.rejected
: Triggered when a user rejects an access request.access_request.revoked
: Triggered when user access is revoked.
Webhook Payload Example
The payload sent to your webhook URL will look similar to this:
Webhook Signature Verification
All webhook requests sent by Memoram include a signature header to ensure authenticity and integrity:
To verify the signature:
- Extract Timestamp and Signature: Parse the
Memoram-Signature
header. Separate the timestamp (t=...
) and the signature (v1=...
). Thev1
indicates the signature scheme (HMAC-SHA256). - Prepare the Signed Payload String: Concatenate the timestamp (as a string), a dot (
.
), and the raw HTTP request body. - Compute the Expected Signature: Calculate the HMAC (Hash-based Message Authentication Code) using the SHA-256 hash function. Use your Webhook Signing Secret (provided in the Memoram Developer Dashboard) as the key and the
signed_payload
string as the message. - Compare Signatures: Compare the signature you computed (hex-encoded) with the
v1
signature extracted from the header. If they match, the webhook is valid. Implement timing attack protection by using a constant-time comparison function.
Important: Reject any webhook request that fails signature verification.