{
  "name": "Nabd signed webhook → Slack / نبض إلى Slack",
  "active": false,
  "nodes": [
    {
      "name": "Nabd webhook",
      "id": "Nabd-webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "nabd-events",
        "responseMode": "onReceived",
        "options": {
          "rawBody": true
        }
      }
    },
    {
      "name": "Verify signature",
      "id": "Verify-signature",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        250,
        0
      ],
      "parameters": {
        "jsCode": "const crypto = require('crypto');\nconst item = $input.first().json;\nconst ts = item.headers['x-nabd-timestamp'];\nconst raw = typeof item.body === 'string' ? item.body : null;\nconst secret = $env.NABD_WEBHOOK_SECRET;\nif (!secret || !raw || !/^\\d+$/.test(ts || '') || Math.abs(Date.now()/1000 - Number(ts)) > 300) throw new Error('Invalid webhook / حدث غير صالح');\nconst expected = crypto.createHmac('sha256', secret).update(ts + '.' + raw).digest('hex');\nconst valid = String(item.headers['x-nabd-signature'] || '').split(',').some(s => { const v = s.trim().replace(/^v1=/, ''); return /^[a-f0-9]{64}$/.test(v) && crypto.timingSafeEqual(Buffer.from(v, 'hex'), Buffer.from(expected, 'hex')); });\nif (!valid) throw new Error('Invalid signature / توقيع غير صالح');\nreturn [{json: JSON.parse(raw)}];"
      }
    },
    {
      "name": "Slack message",
      "id": "Slack-message",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        500,
        0
      ],
      "parameters": {
        "resource": "message",
        "operation": "post",
        "channel": {
          "__rl": true,
          "value": "REPLACE_CHANNEL_ID",
          "mode": "id"
        },
        "text": "={{ \"Nabd / نبض: \" + $json.type + \" · \" + $json.data.id }}",
        "otherOptions": {}
      }
    }
  ],
  "connections": {
    "Nabd webhook": {
      "main": [
        [
          {
            "node": "Verify signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify signature": {
      "main": [
        [
          {
            "node": "Slack message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
