{
  "id": "1",
  "name": "Deadlock Match Stats Bot",
  "nodes": [
    {
      "name": "Send Telegram Message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        900,
        300
      ],
      "parameters": {
        "updates": [
          {
            "text": "={{$node[\"Format Message\"].json[\"text\"]}}",
            "chatId": "={{$json[\"message\"][\"chat\"][\"id\"]}}",
            "resource": "message",
            "operation": "send"
          }
        ]
      },
      "credentials": {
        "telegramApi": {
          "id": "credential-id",
          "name": "telegramApi Credential"
        }
      },
      "typeVersion": 1
    },
    {
      "name": "Fetch Profile HTML",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        300,
        100
      ],
      "parameters": {
        "url": "https://deadlocktracker.gg/player/97170387",
        "options": {},
        "responseFormat": "string"
      },
      "typeVersion": 1
    },
    {
      "name": "Extract Match ID",
      "type": "n8n-nodes-base.function",
      "position": [
        500,
        100
      ],
      "parameters": {
        "functionCode": "\nconst html = $json[\"body\"] || $json;\nconst matchIdMatch = html.match(/\\(#(\\d{8})\\)/g);\nif (!matchIdMatch) throw new Error(\"Матчи не найдены\");\nconst ids = matchIdMatch.map(m => m.match(/\\d+/)[0]);\nconst lastMatchId = ids[ids.length - 1];\nreturn [{ matchId: lastMatchId }];\n"
      },
      "typeVersion": 1
    },
    {
      "name": "Fetch Match HTML",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        700,
        100
      ],
      "parameters": {
        "url": "={{\"https://deadlocktracker.gg/match/\" + $json[\"matchId\"]}}",
        "options": {},
        "responseFormat": "string"
      },
      "typeVersion": 1
    },
    {
      "name": "Parse Players",
      "type": "n8n-nodes-base.function",
      "position": [
        700,
        300
      ],
      "parameters": {
        "functionCode": "\nconst cheerio = require('cheerio');\nconst $ = cheerio.load($json[\"body\"] || $json);\nconst players = [];\n\n$('.player-wrapper').each((i, el) => {\n  const nick = $(el).find('.player-name').text().trim();\n  const hero = $(el).find('.character-icon').attr('alt') || 'Неизвестно';\n  const rank = $(el).find('.rank-icon').attr('alt') || 'Без ранга';\n  players.push({ nick, hero, rank });\n});\n\nreturn players;\n"
      },
      "typeVersion": 1
    },
    {
      "name": "Format Message",
      "type": "n8n-nodes-base.function",
      "position": [
        900,
        100
      ],
      "parameters": {
        "functionCode": "\nconst lines = items.map(p =>\n  `🎮 ${p.nick}\\n🧙 Герой: ${p.hero}\\n🏆 Ранг: ${p.rank}\\n`\n);\nreturn [{ text: `📊 Игроки матча:\\n\\n` + lines.join('\\n') }];\n"
      },
      "typeVersion": 1
    },
    {
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        100,
        100
      ],
      "parameters": {},
      "credentials": {
        "telegramApi": {
          "id": "credential-id",
          "name": "telegramApi Credential"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {},
  "connections": {
    "Parse Players": {
      "main": [
        [
          {
            "node": "Format Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Message": {
      "main": [
        [
          {
            "node": "Send Telegram Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Match ID": {
      "main": [
        [
          {
            "node": "Fetch Match HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Match HTML": {
      "main": [
        [
          {
            "node": "Parse Players",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Fetch Profile HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Profile HTML": {
      "main": [
        [
          {
            "node": "Extract Match ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}