{
  "id": "",
  "name": "Sleeper NFL Get Draft Results",
  "tags": [
    {
      "name": "Sleeper App"
    },
    {
      "name": "NFL"
    },
    {
      "name": "Sports Analytics"
    },
    {
      "name": "Fantasy Football"
    }
  ],
  "nodes": [
    {
      "id": "ae2aa101-cf58-43c2-a3fe-21e6ecc39196",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1712,
        80
      ],
      "parameters": {
        "height": 320,
        "content": "This chatbot will give you the ability to pull your Sleeper team drafted players \n & position & team by typing your username into a chatbot in Telegram.\n\nEnsure Telegram credentials are set via your n8n credentials panel before running \n\n\nBe sure to check your Sleeper App for your username & enter your username including upper or lower case letter. If entered incorrectly, no results will present 0 results back."
      },
      "typeVersion": 1
    },
    {
      "id": "744e3c17-3862-4c27-b083-5361b18c3f55",
      "name": "Extract Username",
      "type": "n8n-nodes-base.code",
      "position": [
        -1136,
        -32
      ],
      "parameters": {
        "jsCode": "const message = $json.message.text || '';\nconst username = message.replace('/team ', '').trim();\n\nreturn [{ json: { username } }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "b3810718-3973-45dd-86cb-6cadfb4a832c",
      "name": "Get Sleeper User ID",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -912,
        -32
      ],
      "parameters": {
        "url": "= https://api.sleeper.app/v1/user/{{ $json.username }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "f18ce331-acf4-47dd-8d9f-1741d9263ca2",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        224,
        -32
      ],
      "parameters": {
        "text": "=Your draft results\nFrom {{ $json.season }} {{ $json.league_name }} ({{ $json.scoring_type }}) season!\n\nHere are your picks:\n{{ \n  $input.all().map(item => \n    `\u2022 Round ${item.json.round}, Pick ${item.json.draft_slot}: (${item.json.pick_no} overall) ${item.json.metadata.first_name} ${item.json.metadata.last_name} (${item.json.metadata.position} - ${item.json.metadata.team})`\n  ).join('\\n') \n}}\n",
        "chatId": "={{ $node[\"Send Message to Chatbot\"].json.message.chat.id }}\n",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "bc08b5a1-b16e-491f-a93c-07fa942367e6",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        -272
      ],
      "parameters": {
        "width": 150,
        "height": 192,
        "content": "Please note this GET address will reference 2024 and will probably need to be changed for 2025 after completion of your draft results"
      },
      "typeVersion": 1
    },
    {
      "id": "1f55e71b-fe06-429c-88ad-252418f64d9c",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        192,
        -208
      ],
      "parameters": {
        "width": 272,
        "height": 144,
        "content": "Message back to your Telegram chatbot\n\nYou can change some of the text & information messaging if you want to be creative. \n"
      },
      "typeVersion": 1
    },
    {
      "id": "62ae7d4f-b8cc-45d2-aa73-7815d8550b39",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1136,
        -288
      ],
      "parameters": {
        "width": 176,
        "height": 192,
        "content": "Please note that this pulls the first Sleeper league found. For users in multiple leagues, customize logic to prompt selection or filter by name."
      },
      "typeVersion": 1
    },
    {
      "id": "356d7343-fdfb-4fd0-aa86-58d7a8dc876d",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1888,
        -320
      ],
      "parameters": {
        "color": 4,
        "width": 608,
        "height": 320,
        "content": "# Sleeper NFL Get Draft Results\n**You will need the following to run:**\n\n-Telegram Chatbot via the BotFather or use any Trigger for your messaging you would prefer.\n\n-An active Sleeper account and team. If you have multiple leagues/drafts this workflow will pull the most recent\n\nThis should give you a way to look up your team by username & basic information on players in your rosters using Sleeper App.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "222d3430-6092-41c3-b889-52d5de62b2db",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1152,
        112
      ],
      "parameters": {
        "color": 5,
        "width": 160,
        "height": 144,
        "content": "However, if you want to hardcode a username instead of using Telegram, you can modify this node directly."
      },
      "typeVersion": 1
    },
    {
      "id": "f646ab17-798e-4997-9719-771fae94586e",
      "name": "Send Message to Chatbot",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1360,
        48
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "userIds": ""
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "71db68bd-efb2-46b6-9f53-6fbf097bb40a",
      "name": "Get Drafts",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "This will need update for upcoming years",
      "position": [
        -688,
        -32
      ],
      "parameters": {
        "url": "=https://api.sleeper.app/v1/user/{{$json[\"user_id\"]}}/drafts/nfl/2024",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "0f64ebaf-c4e7-4809-822f-063828c38208",
      "name": "Extract Draft ID",
      "type": "n8n-nodes-base.code",
      "position": [
        -464,
        -32
      ],
      "parameters": {
        "jsCode": "const drafts = $input.all();\nconst draft = drafts[0].json; // Grab the first league from input items\nreturn [{ json: { draft_id: draft.draft_id, owner_id: draft.user_id } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "1aa338b8-4850-45a0-a747-c5db5998213b",
      "name": "Get Draft Picks",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -240,
        -32
      ],
      "parameters": {
        "url": "=https://api.sleeper.app/v1/draft/{{ $json.draft_id }}/picks",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {}
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "047d410b-8382-4bb9-9a4c-268c7a6e76e5",
      "name": "Return Picked By results from User ID w/ League year and format included",
      "type": "n8n-nodes-base.code",
      "position": [
        -32,
        -32
      ],
      "parameters": {
        "jsCode": "// Pull user_id and username from Get Sleeper User ID node\nconst userNode = $node[\"Get Sleeper User ID\"].json;\nconst userId = userNode[\"user_id\"];\nconst username = userNode[\"username\"] || \"Unknown User\";\n\n// Extract from metadata inside Get Drafts\nconst draftData = $node[\"Get Drafts\"].json;\n\nconst leagueName = draftData.metadata?.name || \"Unknown League\";\nconst scoringType = draftData.metadata?.scoring_type || \"Unknown Scoring\";\nconst season = draftData.season || \"Unknown Season\";\n\n// Filter and enrich the player data\nreturn items\n  .filter(item => item.json.picked_by === userId)\n  .map(item => {\n    return {\n      json: {\n        ...item.json,\n        username,\n        league_name: leagueName,\n        scoring_type: scoringType,\n        season\n      }\n    };\n  });\n"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "",
  "connections": {
    "Get Drafts": {
      "main": [
        [
          {
            "node": "Extract Draft ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Draft Picks": {
      "main": [
        [
          {
            "node": "Return Picked By results from User ID w/ League year and format included",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Draft ID": {
      "main": [
        [
          {
            "node": "Get Draft Picks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Username": {
      "main": [
        [
          {
            "node": "Get Sleeper User ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Sleeper User ID": {
      "main": [
        [
          {
            "node": "Get Drafts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Message to Chatbot": {
      "main": [
        [
          {
            "node": "Extract Username",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Return Picked By results from User ID w/ League year and format included": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}