File size: 9,162 Bytes
ac6f50a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# Webhook API Documentation

## Overview

The DEAF-FIRST Platform webhook system allows you to register and manage webhooks to receive real-time notifications about events in the platform. This replaces the functionality that was previously handled by Xano.

## Base URL

```

http://localhost:3000/api

```

## Webhook Management Endpoints

### 1. List All Webhooks

Get a list of all registered webhooks.

**Endpoint:** `GET /webhooks`

**Response:**
```json

{

  "success": true,

  "count": 2,

  "webhooks": [

    {

      "id": "wh_1234567890_abc123",

      "name": "Production Webhook",

      "url": "https://example.com/webhook",

      "events": ["user.created", "user.updated"],

      "secret": "***",

      "active": true,

      "createdAt": "2025-12-05T07:00:00.000Z",

      "updatedAt": "2025-12-05T07:00:00.000Z"

    }

  ]

}

```

### 2. Get Specific Webhook

Retrieve details of a specific webhook by ID.

**Endpoint:** `GET /webhooks/:id`

**Response:**
```json

{

  "success": true,

  "webhook": {

    "id": "wh_1234567890_abc123",

    "name": "Production Webhook",

    "url": "https://example.com/webhook",

    "events": ["user.created"],

    "secret": "***",

    "active": true,

    "createdAt": "2025-12-05T07:00:00.000Z",

    "updatedAt": "2025-12-05T07:00:00.000Z"

  }

}

```

### 3. Register New Webhook

Create a new webhook registration.

**Endpoint:** `POST /webhooks`

**Request Body:**
```json

{

  "name": "My Webhook",

  "url": "https://example.com/webhook",

  "events": ["user.created", "user.updated"],

  "secret": "optional-custom-secret"

}

```

**Response:**
```json

{

  "success": true,

  "message": "Webhook registered successfully",

  "webhook": {

    "id": "wh_1234567890_abc123",

    "name": "My Webhook",

    "url": "https://example.com/webhook",

    "events": ["user.created", "user.updated"],

    "secret": "generated-or-custom-secret",

    "active": true,

    "createdAt": "2025-12-05T07:00:00.000Z",

    "updatedAt": "2025-12-05T07:00:00.000Z"

  }

}

```

### 4. Update Webhook

Update an existing webhook.

**Endpoint:** `PUT /webhooks/:id`

**Request Body:**
```json

{

  "name": "Updated Webhook Name",

  "url": "https://new-url.com/webhook",

  "events": ["user.created", "user.deleted"],

  "active": false

}

```

**Response:**
```json

{

  "success": true,

  "message": "Webhook updated successfully",

  "webhook": {

    "id": "wh_1234567890_abc123",

    "name": "Updated Webhook Name",

    "url": "https://new-url.com/webhook",

    "events": ["user.created", "user.deleted"],

    "secret": "***",

    "active": false,

    "createdAt": "2025-12-05T07:00:00.000Z",

    "updatedAt": "2025-12-05T08:00:00.000Z"

  }

}

```

### 5. Delete Webhook

Delete a webhook registration.

**Endpoint:** `DELETE /webhooks/:id`

**Response:**
```json

{

  "success": true,

  "message": "Webhook deleted successfully"

}

```

### 6. Get Delivery History

View delivery history for a specific webhook.

**Endpoint:** `GET /webhooks/:id/deliveries`

**Response:**
```json

{

  "success": true,

  "count": 5,

  "deliveries": [

    {

      "id": "del_1234567890_xyz789",

      "webhookId": "wh_1234567890_abc123",

      "event": "user.created",

      "payload": {

        "event": "user.created",

        "timestamp": "2025-12-05T07:00:00.000Z",

        "data": { "userId": "123", "email": "user@example.com" }

      },

      "response": {

        "status": 200,

        "body": "OK"

      },

      "attempts": 1,

      "status": "success",

      "timestamp": "2025-12-05T07:00:00.000Z"

    }

  ]

}

```

### 7. List Available Event Types

Get a list of all available webhook event types.

**Endpoint:** `GET /webhooks/events/types`

**Response:**
```json

{

  "success": true,

  "count": 12,

  "events": [

    "user.created",

    "user.updated",

    "user.deleted",

    "auth.login",

    "auth.logout",

    "document.uploaded",

    "document.processed",

    "accessibility.request",

    "sync.started",

    "sync.completed",

    "ai.process.started",

    "ai.process.completed"

  ]

}

```

### 8. Trigger Webhook Event (Testing)

Manually trigger a webhook event for testing purposes.

**Endpoint:** `POST /webhooks/trigger`

**Request Body:**
```json

{

  "event": "user.created",

  "data": {

    "userId": "123",

    "email": "test@example.com",

    "name": "Test User"

  }

}

```

**Response:**
```json

{

  "success": true,

  "message": "Webhook event triggered successfully"

}

```

## Incoming Webhook Endpoints

These endpoints receive webhooks from external services like Xano.

### Receive External Webhook

**Endpoint:** `POST /incoming-webhooks/:service`

Where `:service` can be:
- `xano` - For Xano webhooks
- `stripe` - For Stripe webhooks
- `custom` - For custom webhooks

**Headers:**
- `X-Webhook-Signature`: HMAC signature for verification
- `X-Webhook-Event`: Event type

**Request Body:** (varies by service)
```json

{

  "event": "record.created",

  "data": {

    "id": "123",

    "table": "users",

    "record": { "name": "John Doe" }

  }

}

```

**Response:**
```json

{

  "success": true,

  "message": "Webhook received successfully",

  "eventId": "evt_1234567890_xyz789"

}

```

### Health Check

**Endpoint:** `GET /incoming-webhooks/health`

**Response:**
```json

{

  "success": true,

  "message": "Incoming webhook endpoint is healthy",

  "timestamp": "2025-12-05T07:00:00.000Z"

}

```

## Webhook Security

### Signature Verification

All outgoing webhooks include an `X-Webhook-Signature` header containing an HMAC-SHA256 signature of the payload.

To verify a webhook:

```javascript

const crypto = require('crypto');



function verifyWebhook(payload, signature, secret) {

  const expectedSignature = crypto

    .createHmac('sha256', secret)

    .update(payload)

    .digest('hex');

  

  return crypto.timingSafeEqual(

    Buffer.from(signature),

    Buffer.from(expectedSignature)

  );

}

```

### Headers

Every webhook delivery includes these headers:
- `Content-Type`: `application/json`
- `X-Webhook-Signature`: HMAC signature for verification
- `X-Webhook-Event`: The event type (e.g., "user.created")
- `X-Webhook-Delivery`: Unique delivery ID

## Event Types

### User Events
- `user.created` - Triggered when a new user is created
- `user.updated` - Triggered when user information is updated
- `user.deleted` - Triggered when a user is deleted

### Authentication Events
- `auth.login` - Triggered when a user logs in
- `auth.logout` - Triggered when a user logs out

### Document Events
- `document.uploaded` - Triggered when a document is uploaded
- `document.processed` - Triggered when document processing completes

### Accessibility Events
- `accessibility.request` - Triggered when accessibility features are requested

### Sync Events
- `sync.started` - Triggered when synchronization begins
- `sync.completed` - Triggered when synchronization completes

### AI Events
- `ai.process.started` - Triggered when AI processing begins
- `ai.process.completed` - Triggered when AI processing completes

## Example Webhook Payload

```json

{

  "event": "user.created",

  "timestamp": "2025-12-05T07:00:00.000Z",

  "data": {

    "userId": "usr_1234567890",

    "email": "user@example.com",

    "name": "John Doe",

    "preferences": {

      "signLanguage": true,

      "visualAccessibility": true

    }

  }

}

```

## Migrating from Xano

If you were previously using Xano webhooks:

1. **Register your webhook endpoints** using the `POST /webhooks` endpoint
2. **Configure incoming webhooks** to receive events from Xano at `/incoming-webhooks/xano`
3. **Update your Xano configuration** to point to your new webhook URL
4. **Test webhook delivery** using the trigger endpoint

## Error Handling

All endpoints return consistent error responses:

```json

{

  "success": false,

  "error": "Error type",

  "message": "Detailed error message"

}

```

Common HTTP status codes:
- `200` - Success
- `201` - Created
- `400` - Bad Request
- `404` - Not Found
- `500` - Internal Server Error

## Rate Limiting

Currently, there are no rate limits applied to webhook endpoints. In production, consider implementing rate limiting based on your needs.

## Best Practices

1. **Verify signatures** - Always verify webhook signatures to ensure authenticity
2. **Handle idempotency** - Webhook events may be delivered multiple times; handle duplicates gracefully
3. **Respond quickly** - Return a 200 response as soon as possible; process webhooks asynchronously
4. **Log deliveries** - Use the delivery history endpoint to monitor webhook health
5. **Use HTTPS** - Always use HTTPS URLs for webhook endpoints in production
6. **Rotate secrets** - Periodically rotate webhook secrets for security

## Support

For issues or questions about the webhook system, please refer to the main documentation or create an issue in the repository.