خدمة الإشعارات

تتيح خدمة إشعارات AFP لمنصات AFP Direct تلقّي إشعارات على الحساب الفرعي وتغييرات حالة الموقع. يمكن للأنظمة الأساسية استخدام Platform API للتحقيق في التغييرات.

لتلقّي الإشعارات، يجب تنفيذ خادم يقبل طلبات POST ويحلّل حمولة JSON الموضحة في المخطط (يمكنك الاطّلاع على مثال على الإعداد). بعد ذلك، يجب تقديم عنوان URL لنقطة النهاية إلى مدير الشركاء الاستراتيجي لتفعيل الخدمة.

المخطّط

يجب أن تتقيّد حمولة الإشعارات بالمخطط التالي:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Notification",
  "type": "object",
  "properties": {
    "accountName": {
      "type": "string",
      "description": "The name of the modified sub-account."
    },
    "domain": {
      "type": "string",
      "description": "The domain the notification refers to, if any. Optional (only populated for SITE_APPROVAL)"
    },
    "notificationType": {
      "type": "string",
      "enum": ["PUBLISHER_APPROVAL", "SITE_APPROVAL"],
      "description": "Type of notification"
    }
  },
  "required": ["platformPublisherId", "publisherId", "notificationType"],
  "additionalProperties": false
}

يمكن إضافة المزيد من notificationTypes وحقول أخرى لاحقًا.

أمثلة

سيظهر إشعار موافقة الناشر على النحو التالي:

{
  "accountName" : "platforms/pub-1234567890123456/accounts/pub-0987654321654321",
  "notificationType": "PUBLISHER_APPROVAL"
}

سيظهر إشعار الموافقة على الموقع الإلكتروني على النحو التالي:

{
  "accountName" : "platforms/pub-1234567890123456/accounts/pub-0987654321654321",
  "domain": "afpsite.com",
  "notificationType": "SITE_APPROVAL"
}

مثال على الإعداد

في ما يلي مثال على خادم NodeJS الذي يُسجّل محتويات الإشعار:

// Import express
const express = require('express');

// Create an express application
const app = express();

// Middleware to parse JSON bodies
app.use(express.json());

// Define a route to receive POST requests
app.post('/notification', (req, res) => {
    console.log('Received account name:', req.body.accountName)
    console.log('Received Domain:', req.body.domain)
    console.log('Received notification type', req.body.notificationType)

    // Send a response back to the client
    res.status(200).send('Notification received');
});

// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

مثال على عنوان URL لنقطة النهاية: https://yourdomain.com/your-endpoint

يمكنك التحقّق من عمل نقطة النهاية من خلال إرسال طلب POST باستخدام curl:

curl -X POST https://yourdomain.com/your-endpoint \
     -H "Content-Type: application/json" \
     -d '{"accountName": "platforms/pub-1234567890123456/accounts/pub-0987654321654321", \
        "notificationType": "PUBLISHER_APPROVAL"}'

إعداد ملف robots.txt

تأكَّد من السماح لخدمة الإشعارات بالوصول إلى نقطة النهاية. وتلتزم خدمة الإشعارات بالتوجيهات الموضّحة في ملف robots.txt لجذر نطاقك، في حال توفّرها:

User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>