{
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "safehouse-alert",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [100, 200]
    },
    {
      "parameters": {
        "jsCode": "const staticData = $getWorkflowStaticData('global');\nif (!staticData.trusted) staticData.trusted = [];\nconst body = $input.first().json.body || {};\nreturn { isNew: !staticData.trusted.includes(body.mac), mac: body.mac, ip: body.ip, name: body.device_name };"
      },
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [300, 200]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [{ "value1": "={{$json.isNew}}", "value2": true }]
        }
      },
      "name": "If",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [500, 200]
    },
    {
      "parameters": {
        "chatId": "-1003716487381",
        "text": "🛡️ NEW DEVICE: {{ $json.name }}\nIP: {{ $json.ip }}\nMAC: {{ $json.mac }}",
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  { "text": "🚫 BLOCK", "additionalFields": { "callback_data": "={{'BLOCK|'+$json.mac}}" } },
                  { "text": "✅ TRUST", "additionalFields": { "callback_data": "={{'TRUST|'+$json.mac}}" } }
                ]
              }
            }
          ]
        }
      },
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [700, 180]
    }
  ],
  "connections": {
    "Webhook": { "main": [[{ "node": "Code", "type": "main", "index": 0 }]] },
    "Code": { "main": [[{ "node": "If", "type": "main", "index": 0 }]] },
    "If": { "main": [[{ "node": "Telegram", "type": "main", "index": 0 }]] }
  }
}