{
  "name": "Düşük Bakiye Telegram Uyarısı (HMAC Doğrulamalı)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "basliklisms-webhook"
      },
      "id": "credits-webhook",
      "name": "Başlıklı SMS Webhook Alıcı",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [220, 300]
    },
    {
      "parameters": {
        "jsCode": "const crypto = require('node:crypto');\nconst item = items[0].json;\nconst ts = item.headers['x-basliklisms-timestamp'] || '';\nconst sig = item.headers['x-basliklisms-signature'] || '';\nconst raw = JSON.stringify(item.body || {});\nconst secret = process.env.BASLIKLISMS_WEBHOOK_SECRET || '';\nconst expected = 'sha256=' + crypto.createHmac('sha256', secret).update(`${ts}.${raw}`).digest('hex');\nconst valid = expected.length === sig.length && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(sig));\nreturn [{ json: { valid, event: item.headers['x-basliklisms-event'], data: item.body?.data || {} } }];"
      },
      "id": "verify-hmac",
      "name": "HMAC-SHA256 Doğrula",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [470, 300]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [{ "value1": "={{ $json.valid && $json.event === 'credits.low' }}", "value2": true }]
        }
      },
      "id": "if-low",
      "name": "Düşük Bakiye mi?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [710, 300]
    },
    {
      "parameters": {
        "chatId": "={{ $env.TELEGRAM_CHAT_ID }}",
        "text": "={{ 'Dikkat: Baslikli SMS bakiyesi ' + $json.data.balance + ' krediye dustu (Esik: ' + $json.data.threshold + ').' }}"
      },
      "id": "telegram-notify",
      "name": "Telegram Uyarısı Gönder",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [950, 280]
    }
  ],
  "connections": {
    "Başlıklı SMS Webhook Alıcı": {
      "main": [[{ "node": "HMAC-SHA256 Doğrula", "type": "main", "index": 0 }]]
    },
    "HMAC-SHA256 Doğrula": {
      "main": [[{ "node": "Düşük Bakiye mi?", "type": "main", "index": 0 }]]
    },
    "Düşük Bakiye mi?": {
      "main": [[{ "node": "Telegram Uyarısı Gönder", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" }
}
