Webhooks للمطورين

كل منافسة تطابق تنبيهًا تصل نظامك برسالة POST موقّعة. متاحة في Business.

شكل الرسالة

جسم الرسالة JSON، والحدث الوحيد الآن tender.matched.

{
  "type": "tender.matched",
  "timestamp": "2026-09-26T09:00:00Z",
  "data": {
    "notification_id": 1,
    "search_id": "…",
    "search_name": "تكييف القصيم",
    "tender": {
      "tenderId": 1106290,
      "name": "…"
    },
    "url": "https://…"
  }
}

التحقق من التوقيع

نوقّع كل رسالة وفق معيار Standard Webhooks بالرؤوس webhook-id وwebhook-timestamp وwebhook-signature. تحقق منها قبل المعالجة:

import crypto from "node:crypto";

// secret: "whsec_..." as shown once when the endpoint was added
export function verify(secret, headers, rawBody) {
  const id = headers["webhook-id"];
  const ts = headers["webhook-timestamp"];
  if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false; // replay window
  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const expected = crypto.createHmac("sha256", key).update(`${id}.${ts}.${rawBody}`).digest("base64");
  // during a rotation two signatures are sent, space separated
  return headers["webhook-signature"].split(" ").some((s) => {
    const sig = s.replace(/^v1,/, "");
    return sig.length === expected.length && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
  });
}

الإعادة والإيقاف

ننتظر الرد 10 ثوانٍ ولا نتبع التحويلات. نعيد المحاولة عند المهلة وأخطاء الشبكة و408 و429 و5xx. الرد 410 يوقف الوجهة فورًا، وكذلك فشلها المتواصل 24 ساعة.