{
  "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": {
          "name": "<your 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(\"\u041c\u0430\u0442\u0447\u0438 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u044b\");\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') || '\u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e';\n  const rank = $(el).find('.rank-icon').attr('alt') || '\u0411\u0435\u0437 \u0440\u0430\u043d\u0433\u0430';\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  `\ud83c\udfae ${p.nick}\\n\ud83e\uddd9 \u0413\u0435\u0440\u043e\u0439: ${p.hero}\\n\ud83c\udfc6 \u0420\u0430\u043d\u0433: ${p.rank}\\n`\n);\nreturn [{ text: `\ud83d\udcca \u0418\u0433\u0440\u043e\u043a\u0438 \u043c\u0430\u0442\u0447\u0430:\\n\\n` + lines.join('\\n') }];\n"
      },
      "typeVersion": 1
    },
    {
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        100,
        100
      ],
      "parameters": {},
      "credentials": {
        "telegramApi": {
          "name": "<your 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
          }
        ]
      ]
    }
  }
}