واجهة برمجة Webhooks
تكوين webhooks لتلقي إشعارات حول الأحداث.
قائمة Webhooks
GET /v1/webhooks
الاستجابة:
{
"success": true,
"webhooks": [
{
"id": "wh_abc123",
"url": "https://your-server.com/webhook",
"events": ["index.complete", "security.alert"],
"active": true,
"createdAt": "2024-01-10T08:00:00Z"
}
]
}
إنشاء Webhook
POST /v1/webhooks
نص الطلب:
{
"url": "https://your-server.com/webhook",
"events": ["index.complete", "security.alert"],
"secret": "سر-webhook-الخاص-بك"
}
الاستجابة:
{
"success": true,
"webhook": {
"id": "wh_xyz789",
"url": "https://your-server.com/webhook",
"events": ["index.complete", "security.alert"],
"active": true
}
}
حذف Webhook
DELETE /v1/webhooks/:id
الأحداث المتاحة
| الحدث | الوصف |
|---|---|
index.started | بدأت الفهرسة |
index.complete | اكتملت الفهرسة بنجاح |
index.failed | فشلت الفهرسة |
security.alert | تم العثور على ثغرة أمنية جديدة |
analysis.complete | اكتمل التحليل |
حمولة Webhook
تتلقى جميع webhooks حمولة JSON:
{
"event": "index.complete",
"timestamp": "2024-01-15T10:30:00Z",
"project": {
"id": "proj_abc123",
"name": "my-app"
},
"data": {
"filesCount": 234,
"symbolsCount": 1847,
"duration": 45
}
}
التحقق من التوقي عات
تتضمن Webhooks رأس توقيع للتحقق:
X-ArchiCore-Signature: sha256=abc123...
التحقق (Node.js):
const crypto = require('crypto');
function verifyWebhook(payload, signature, secret) {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(`sha256=${expected}`)
);
}
سياسة إعادة المحاولة
يتم إعادة محاولة تسليمات webhook الفاشلة:
- المحاولة 1: فورية
- المحاولة 2: بعد دقيقة واحدة
- المحاولة 3: بعد 5 دقائق
- المحاولة 4: بعد 30 دقيقة
- المحاولة 5: بعد ساعتين
بعد 5 محاولات فاشلة، يتم تعطيل webhook.