{
  "name": "SlideAI \u2014 09 Content Ingestion",
  "active": false,
  "nodes": [
    {
      "parameters": {},
      "id": "ewt-ing",
      "name": "When Called by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "url": "=https://yqpvjtwldnkoersgqoti.supabase.co/rest/v1/projects?id=eq.{{ $json.project_id }}&select=id,topic,audience,complexity,duration_mins,template_url",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "supabaseApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Prefer",
              "value": "return=representation"
            }
          ]
        },
        "options": {}
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "id": "get-proj-ing",
      "name": "Get Project Files",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        288,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "\nconst p = items[0].json;\nconst url = p.template_url || '';\nlet contentType = 'none';\nif (url.endsWith('.pdf'))  contentType='pdf';\nelse if (url.endsWith('.docx')) contentType='docx';\nelse if (url.endsWith('.txt'))  contentType='text';\nelse if (url.endsWith('.pptx')) contentType='pptx_template';\nelse if (url.startsWith('http')) contentType='url';\nreturn [{ json:{...p, contentType, hasContent: contentType!=='none'} }];\n"
      },
      "id": "detect-type",
      "name": "Detect Content Type",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.hasContent }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "if-has-content-ing",
      "name": "Has User Content?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        848,
        0
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.template_url }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "SlideAI/1.0"
            }
          ]
        },
        "options": {}
      },
      "id": "fetch-content",
      "name": "Fetch User Content",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1120,
        -128
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "groqApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "string",
        "body": "={{ JSON.stringify({ model: 'llama-3.3-70b-versatile', temperature: 0.7, max_tokens: 4096, messages: [{ role: 'system', content: \"You are a document content extractor. Return JSON only: {\\\"key_points\\\":[],\\\"data\\\":[],\\\"structure_suggestions\\\":[]}\" }, { role: 'user', content: `Extract key presentation content from this document:\\n${$json.data ?? $json.body ?? 'No content'}` }] }) }}",
        "options": {}
      },
      "credentials": {
        "groqApi": {
          "name": "<your credential>"
        }
      },
      "id": "parse-content",
      "name": "Parse & Extract Content \u2014 Groq",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1408,
        -128
      ]
    },
    {
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "project_id"
            },
            {
              "name": "topic"
            },
            {
              "name": "audience"
            },
            {
              "name": "complexity"
            },
            {
              "name": "duration_mins"
            },
            {
              "name": "research"
            }
          ]
        },
        "options": {}
      },
      "id": "pass-through-ing",
      "name": "Pass Through \u2014 No Content",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [
        1120,
        128
      ]
    },
    {
      "parameters": {
        "jsCode": "\nlet content = { key_points:[], data:[], structure_suggestions:[] };\ntry {\n  const raw = items[0].json.choices?.[0]?.message?.content ?? '{}';\n  const parsed = JSON.parse(raw.replace(/```json?\\n?/g,'').replace(/```/g,'').trim());\n  Object.assign(content, parsed);\n} catch(e){}\nconst input = $('When Called by Another Workflow').first().json;\nconst proj  = $('Get Project Files').first().json;\nreturn [{ json:{\n  project_id: proj.id ?? input.project_id,\n  topic:      proj.topic,\n  domain:     input.domain ?? '',\n  subdomain:  input.subdomain ?? '',\n  audience:   proj.audience,\n  complexity: proj.complexity,\n  duration_mins: proj.duration_mins,\n  research: {\n    facts:    content.key_points ?? [],\n    concepts: content.structure_suggestions ?? [],\n    examples: content.data ?? [],\n    trends:   []\n  }\n}}];\n"
      },
      "id": "merge-ingested",
      "name": "Format Ingested Content",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1680,
        0
      ]
    }
  ],
  "connections": {
    "When Called by Another Workflow": {
      "main": [
        [
          {
            "node": "Get Project Files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Project Files": {
      "main": [
        [
          {
            "node": "Detect Content Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Detect Content Type": {
      "main": [
        [
          {
            "node": "Has User Content?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has User Content?": {
      "main": [
        [
          {
            "node": "Fetch User Content",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Pass Through \u2014 No Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch User Content": {
      "main": [
        [
          {
            "node": "Parse & Extract Content \u2014 Groq",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse & Extract Content \u2014 Groq": {
      "main": [
        [
          {
            "node": "Format Ingested Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pass Through \u2014 No Content": {
      "main": [
        [
          {
            "node": "Format Ingested Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  }
}