Webhooks في Clawdbot

قم بتكامل مساعد الذكاء الاصطناعي Clawdbot مع الخدمات الخارجية باستخدام webhooks. تعلم كيفية استقبال وإرسال أحداث webhook للأتمتة.

نظرة عامة على Webhooks في Clawdbot

يدعم Clawdbot الـ webhooks للتكامل مع الخدمات الخارجية. تمكّن Webhooks من الأتمتة المدفوعة بالأحداث والمشغلات الخارجية والتواصل بين الخدمات.

Webhooks الواردة

التكوين

{
  "webhooks": {
    "incoming": {
      "enabled": true,
      "port": 3011,
      "secret": "your-webhook-secret"
    }
  }
}

نقطة النهاية

POST http://localhost:3011/webhook/<hook-id>

المصادقة

curl -X POST http://localhost:3011/webhook/my-hook \
  -H "X-Webhook-Secret: your-webhook-secret" \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello from external service"}'

معالجات Webhook

تعريف معالج

{
  "webhooks": {
    "handlers": [
      {
        "id": "github-events",
        "path": "/github",
        "action": "run_agent",
        "agentId": "devops",
        "template": "New GitHub event: {{event.action}} on {{event.repository.name}}"
      }
    ]
  }
}

إجراءات المعالج

الإجراءالوصف
send_messageإرسال رسالة إلى القناة
run_agentتشغيل الوكيل بأمر
forwardإعادة التوجيه إلى نقطة نهاية أخرى
customدالة معالج مخصصة

معالجة الجلسات

مفاتيح جلسة Webhook

تستخدم Webhooks جلسات مخصصة:

hook:<uuid>

خيارات الجلسة

{
  "webhooks": {
    "handlers": [
      {
        "id": "alerts",
        "sessionMode": "persistent",
        "sessionKey": "alerts-session"
      }
    ]
  }
}

Webhooks الصادرة

التكوين

{
  "webhooks": {
    "outgoing": [
      {
        "id": "slack-notify",
        "url": "https://hooks.slack.com/services/xxx",
        "events": ["message_received", "agent_response"],
        "method": "POST"
      }
    ]
  }
}

أنواع الأحداث

الحدثالوصف
message_receivedوصول رسالة جديدة
agent_responseالوكيل أنشأ استجابة
session_startedإنشاء جلسة جديدة
session_endedانتهاء/إغلاق الجلسة
errorحدث خطأ

تنسيق الحمولة

الحمولة الواردة

{
  "event": "custom_event",
  "data": {
    "key": "value"
  },
  "timestamp": "2024-01-15T10:30:00Z"
}

الحمولة الصادرة

{
  "type": "message_received",
  "session": "agent:main:whatsapp",
  "message": {
    "from": "+15551234567",
    "text": "Hello",
    "timestamp": "2024-01-15T10:30:00Z"
  }
}

الأمان

التحقق من المفتاح السري

{
  "webhooks": {
    "incoming": {
      "secretHeader": "X-Webhook-Secret",
      "secret": "your-secret"
    }
  }
}

قائمة IP المسموح بها

{
  "webhooks": {
    "incoming": {
      "allowedIPs": [
        "192.168.1.0/24",
        "10.0.0.1"
      ]
    }
  }
}

معالجة الأخطاء

تكوين إعادة المحاولة

{
  "webhooks": {
    "outgoing": [
      {
        "id": "notify",
        "retry": {
          "maxAttempts": 3,
          "backoff": "exponential"
        }
      }
    ]
  }
}

معالجة الفشل

  • يتم تسجيل webhooks الفاشلة
  • إعادة المحاولة مع تراجع أسي
  • قائمة انتظار الرسائل الميتة اختيارية

أمثلة

تكامل GitHub

{
  "webhooks": {
    "handlers": [
      {
        "id": "github",
        "path": "/github",
        "action": "send_message",
        "target": {
          "channel": "discord",
          "peer": "dev-channel"
        },
        "template": "🔔 {{event.action}}: {{event.pull_request.title}}"
      }
    ]
  }
}

إعادة توجيه التنبيهات

{
  "webhooks": {
    "handlers": [
      {
        "id": "alerts",
        "path": "/alerts",
        "action": "run_agent",
        "agentId": "oncall",
        "template": "Alert: {{alert.name}} - {{alert.message}}"
      }
    ]
  }
}

الخطوات التالية