{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "85aa3f89-515f-43a8-b4fc-7e371a13d013",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -256,
        240
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "002c3998-0be6-4dda-8ce2-e13bcf4ddadf",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        496,
        224
      ],
      "parameters": {
        "text": "=geneaate 25-40 playlist similer to  :{{ $('Telegram Trigger').item.json.message.text }} and return in json ",
        "options": {
          "systemMessage": "you are greatest dj ever lived, return json"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "7420a039-331b-4591-a737-fa82d7ede059",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        496,
        448
      ],
      "parameters": {
        "model": "openai/gpt-5-nano",
        "options": {
          "responseFormat": "json_object"
        }
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8787f13c-acb8-4ed6-8e99-b5e77681f137",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        640,
        448
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"array\",\n  \"title\": \"SongList\",\n  \"description\": \"An array of musical tracks extracted from a creative list.\",\n  \"items\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"track\": {\n        \"type\": \"string\",\n        \"description\": \"The title of the song, derived from the input list.\"\n      },\n      \"artist\": {\n        \"type\": \"string\",\n        \"description\": \"The suggested artist for the song, based on the input name.\"\n      }\n    },\n    \"required\": [\n      \"track\",\n      \"artist\"\n    ]\n  }\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "14e8ced5-82d7-4013-b888-897487e5901d",
      "name": "Split Out Array",
      "type": "n8n-nodes-base.splitOut",
      "notes": "Splits the 'output' list into individual items",
      "position": [
        848,
        224
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "output"
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "id": "e9c8e594-3227-4a62-8b40-51041292c0f3",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1072,
        224
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "c1b4a3b5-815b-4944-a537-7241d5f2c47e",
      "name": "Search tracks by keyword",
      "type": "n8n-nodes-base.spotify",
      "position": [
        1344,
        240
      ],
      "parameters": {
        "limit": 1,
        "query": "={{ $json.artist }} {{ $json.track }}",
        "filters": {},
        "resource": "track",
        "operation": "search"
      },
      "credentials": {
        "spotifyOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "94f3902d-18de-48af-8120-4d34cd9e41fc",
      "name": "Create a playlist",
      "type": "n8n-nodes-base.spotify",
      "position": [
        48,
        224
      ],
      "parameters": {
        "name": "={{ $('Telegram Trigger').item.json.message.from.username }} {{ $('Telegram Trigger').item.json.message.text }} gen {{ (new Date()).getMinutes().toString().padStart(2, '0') + ':' + (new Date()).getHours().toString().padStart(2, '0') }}",
        "resource": "playlist",
        "operation": "create",
        "additionalFields": {}
      },
      "credentials": {
        "spotifyOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c1ff45ea-541e-43ed-aa9d-91defea0b2f9",
      "name": "Add an Item to a playlist",
      "type": "n8n-nodes-base.spotify",
      "position": [
        1760,
        224
      ],
      "parameters": {
        "id": "=spotify:playlist:{{ $('Create a playlist').item.json.id }}",
        "trackID": "=spotify:track:{{ $json.id }}",
        "resource": "playlist",
        "additionalFields": {}
      },
      "credentials": {
        "spotifyOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": false,
      "typeVersion": 1
    },
    {
      "id": "7ded2fe4-f212-4512-9d56-f9c33521c8f2",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        272,
        160
      ],
      "parameters": {
        "text": "={{ $('Create a playlist').item.json.external_urls.spotify }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4c0ae3e9-4fde-4014-bc2e-f8ec1612e3a5",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1552,
        240
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "42496754-42f6-4f5d-8aef-0e8a38272d35",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.uri }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "de3e5a97-455f-49d6-8daf-41f5260b77d1",
      "name": "Wait 1 Sec",
      "type": "n8n-nodes-base.wait",
      "position": [
        1968,
        224
      ],
      "parameters": {
        "unit": "seconds"
      },
      "typeVersion": 1
    },
    {
      "id": "09199a93-9e6e-410c-bf6c-81a2cbef91cd",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -976,
        -64
      ],
      "parameters": {
        "width": 560,
        "height": 752,
        "content": "## How it works\n\nThis workflow lets users create a brand-new Spotify playlist directly from Telegram in one message.\n\n1. User sends a message in Telegram (e.g. \"Create a chill house playlist\")\n2. workflow create play list for user (e.g \"<username> chill house\")\n3. The AI (acting as a DJ) generates 30\u201350 track suggestions with perfect 3-column CSV format\n4. Workflow creates an empty playlist, searches every track on Spotify, and adds the ones it finds\n\n\nBuilt to respect Spotify API rate limits (1-second delay between adds).\n\n## Setup steps\n\n1. Connect your Telegram bot (use Telegram Trigger node credentials)\n2. Connect your Spotify account (use Spotify node credentials)\n3. (Optional) Change the AI prompt or model in the \"AI Agent\" node if you want a different music style\n4. Activate the workflow\n\nThat\u2019s it \u2014 send a message to your bot and get a playlist in <60 seconds!"
      },
      "typeVersion": 1
    },
    {
      "id": "2b951cfd-2ae5-48e9-9897-e124bf922845",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        448,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 624,
        "content": "## 2. AI Curation\nAI agent acts as a pro DJ and outputs 30\u201350 track suggestions in structured format"
      },
      "typeVersion": 1
    },
    {
      "id": "3c743c52-fbbe-4fdc-8a3c-726c654c6e90",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1008,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 1200,
        "height": 624,
        "content": "## 3. Fulfillment Loop\nSplits the list \u2192 searches each track on Spotify \u2192 adds found tracks with 1-second delay"
      },
      "typeVersion": 1
    },
    {
      "id": "d3fe4095-2606-459d-b4ca-3b9b32a04ef1",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -352,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 272,
        "height": 624,
        "content": "## 1. Receive & Initialize\nTriggers on Telegram message \u2192 creates empty Spotify playlist \u2192 sends \"wait for it\" reply"
      },
      "typeVersion": 1
    },
    {
      "id": "5c8ffb82-3d65-4857-a457-1fdfaa7971fa",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 464,
        "height": 624,
        "content": "## 1 -1  Create play list first\nand send back play list url to usr"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Add an Item to a playlist",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Split Out Array",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 1 Sec": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Search tracks by keyword",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Array": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Create a playlist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a playlist": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a text message": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Search tracks by keyword": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Add an Item to a playlist": {
      "main": [
        [
          {
            "node": "Wait 1 Sec",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}