Webhook Integration
Webhooks allow you to receive real-time notifications about events that happen in Daisy. This guide explains how to set up and use webhooks.
What are Webhooks?
Webhooks are automated messages sent from apps when something happens. They have a message—or payload—and are sent to a unique URL—a webhook URL. In Daisy, you can use webhooks to be notified about events like the completion of a document generation task.
Setting up a Webhook
- Get your Webhook URL: This is the URL of your application's endpoint that will receive the webhook payloads.
- Create a Webhook in Daisy: In the Daisy dashboard, go to the "Webhooks" section and create a new webhook. You will need to provide your webhook URL and select the events you want to be notified about.
- Secure your Webhook: Daisy signs each webhook payload with a secret. You should verify this signature to ensure that the payload was sent by Daisy.
Webhook Events
You can subscribe to the following events:
document.completed: Sent when a document generation task is completed.document.failed: Sent when a document generation task fails.research.completed: Sent when a research task is completed.research.failed: Sent when a research task fails.
Payload Structure
All webhook payloads have the following structure:
json
{
"event": "document.completed",
"data": {
"document_id": "doc_12345",
"status": "completed",
"download_url": "https://api.daisy.ai/v1/documents/doc_12345/download"
}
}Verifying the Signature
Daisy includes a signature in the X-Daisy-Signature header of each webhook request. The signature is a HMAC-SHA256 hash of the request body, using your webhook secret as the key.
Here is an example of how to verify the signature in Node.js:
javascript
const crypto = require('crypto');
function verifySignature(body, secret, signature) {
const hmac = crypto.createHmac('sha256', secret);
const digest = 'sha256=' + hmac.update(body).digest('hex');
return crypto.timingSafeEqual(Buffer.from(digest), Buffer.from(signature));
}