{
  "name": "Content Factory Workflow",
  "nodes": [
    {
      "parameters": {
        "path": "content-generator",
        "options": {}
      },
      "id": "content-webhook",
      "name": "Content Generator Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "resource": "completion",
        "prompt": "={{ $json.prompt || 'Generate engaging content about: ' + $json.topic }}",
        "model": "gpt-4",
        "options": {
          "maxTokens": 2000,
          "temperature": 0.7
        }
      },
      "id": "openai-content",
      "name": "OpenAI Content Generation",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [
        460,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "insert",
        "table": "automation_content",
        "columns": "type, title, content, status, metadata, created_at",
        "values": "={{ $json.contentType || 'generated' }}, {{ $json.title || 'AI Generated Content' }}, {{ $('OpenAI Content Generation').item.json.choices[0].message.content }}, published, {{ JSON.stringify($json) }}, {{ new Date().toISOString() }}"
      },
      "id": "save-content",
      "name": "Save to Database",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        680,
        300
      ],
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "auto-publish",
              "leftValue": "={{ $json.autoPublish }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "check-auto-publish",
      "name": "Check Auto Publish",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:5678/webhook/social-media",
        "sendQuery": false,
        "sendHeaders": false,
        "sendBody": true,
        "contentType": "json",
        "body": "={ \"action\": \"publish\", \"content\": {{ $('OpenAI Content Generation').item.json.choices[0].message.content }}, \"platforms\": {{ $json.platforms || [\"twitter\", \"linkedin\"] }} }"
      },
      "id": "trigger-social",
      "name": "Trigger Social Media",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1120,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"status\": \"success\", \"contentId\": {{ $('Save to Database').item.json.id }}, \"content\": {{ $('OpenAI Content Generation').item.json.choices[0].message.content }}, \"autoPublished\": {{ $json.autoPublish || false }} }"
      },
      "id": "content-response",
      "name": "Content Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1340,
        300
      ]
    }
  ],
  "connections": {
    "Content Generator Webhook": {
      "main": [
        [
          {
            "node": "OpenAI Content Generation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Content Generation": {
      "main": [
        [
          {
            "node": "Save to Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Database": {
      "main": [
        [
          {
            "node": "Check Auto Publish",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Auto Publish": {
      "main": [
        [
          {
            "node": "Trigger Social Media",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Content Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger Social Media": {
      "main": [
        [
          {
            "node": "Content Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "automation",
    "content",
    "ai"
  ],
  "triggerCount": 1,
  "updatedAt": "2024-01-15T00:00:00.000Z",
  "versionId": "1"
}