{
  "name": "CONTENT-FACTORY-V3",
  "nodes": [
    {
      "parameters": {},
      "id": "trigger-manual",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        200,
        300
      ]
    },
    {
      "parameters": {
        "path": "content-factory-v3",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "trigger-webhook",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        200,
        460
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "input_text",
              "value": "={{ $json.body.text || '\u041d\u043e\u0432\u0430\u044f \u0438\u0434\u0435\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u043e \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0418\u0418 \u0432 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u0435' }}"
            },
            {
              "name": "project_id",
              "value": "={{ $json.body.project_id || 'default_project' }}"
            }
          ]
        },
        "options": {}
      },
      "id": "set-input",
      "name": "Set Input Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 2,
      "position": [
        420,
        380
      ]
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "\u0422\u044b - \u044d\u043a\u0441\u043f\u0435\u0440\u0442 \u043f\u043e SMM \u0432 Telegram. \u0422\u0432\u043e\u044f \u0437\u0430\u0434\u0430\u0447\u0430 - \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0442\u0435\u043a\u0441\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043f\u043e\u0441\u0442\u0430 \u0434\u043b\u044f Telegram \u043a\u0430\u043d\u0430\u043b\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u044d\u043c\u043e\u0434\u0437\u0438, \u0440\u0430\u0437\u0431\u0438\u0432\u043a\u0443 \u043d\u0430 \u0430\u0431\u0437\u0430\u0446\u044b \u0438 \u043f\u0440\u0438\u0437\u044b\u0432 \u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044e."
            },
            {
              "content": "={{ $json.input_text }}"
            }
          ]
        }
      },
      "id": "llm-telegram",
      "name": "LLM Rewrite: Telegram",
      "type": "@n8n/n8n-nodes-langchain.openAiChat",
      "typeVersion": 1,
      "position": [
        700,
        100
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "\u0422\u044b - \u044d\u043a\u0441\u043f\u0435\u0440\u0442 \u043f\u043e Threads. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0438 \u0442\u0435\u043a\u0441\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0442\u0440\u0435\u0434\u0430 (\u0441\u0435\u0440\u0438\u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439). \u041f\u0435\u0440\u0432\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0446\u0435\u043f\u043b\u044f\u044e\u0449\u0438\u043c \u0445\u0443\u043a\u043e\u043c."
            },
            {
              "content": "={{ $json.input_text }}"
            }
          ]
        }
      },
      "id": "llm-threads",
      "name": "LLM Rewrite: Threads",
      "type": "@n8n/n8n-nodes-langchain.openAiChat",
      "typeVersion": 1,
      "position": [
        700,
        250
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "\u0422\u044b - \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u0431\u043b\u043e\u0433\u0430. \u041d\u0430\u043f\u0438\u0448\u0438 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 H2, H3 \u0438 \u043c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u043f\u0438\u0441\u043a\u0438."
            },
            {
              "content": "={{ $json.input_text }}"
            }
          ]
        }
      },
      "id": "llm-article",
      "name": "LLM Rewrite: Article",
      "type": "@n8n/n8n-nodes-langchain.openAiChat",
      "typeVersion": 1,
      "position": [
        700,
        400
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.heygen.com/v1/video/generate",
        "authentication": "headerAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "text",
              "value": "={{ $json.input_text }}"
            },
            {
              "name": "avatar_id",
              "value": "default_avatar"
            }
          ]
        },
        "options": {}
      },
      "id": "api-heygen",
      "name": "API: HeyGen Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        700,
        550
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/sora/generations",
        "authentication": "headerAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "prompt",
              "value": "={{ $json.input_text }}"
            },
            {
              "name": "size",
              "value": "1080x1920"
            }
          ]
        },
        "options": {}
      },
      "id": "api-sora",
      "name": "API: Sora Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        700,
        700
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "\u0422\u044b - SMM \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 Instagram. \u041d\u0430\u043f\u0438\u0448\u0438 \u043f\u0440\u043e\u0434\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u0441\u0442 \u0434\u043b\u044f Instagram \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438 \u0438\u0434\u0435\u044e \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0430 (Reels \u0438\u043b\u0438 \u043a\u0430\u0440\u0443\u0441\u0435\u043b\u044c) \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0435\u043a\u0441\u0442\u0430."
            },
            {
              "content": "={{ $json.input_text }}"
            }
          ]
        }
      },
      "id": "llm-instagram",
      "name": "LLM Rewrite: Instagram",
      "type": "@n8n/n8n-nodes-langchain.openAiChat",
      "typeVersion": 1,
      "position": [
        700,
        850
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "tableName": "content_tasks",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "title": "Telegram Post Generated",
            "description": "={{ $json.content }}",
            "status": "completed",
            "project_id": "={{ $('Set Input Data').item.json.project_id }}",
            "platform": "telegram"
          },
          "matchingColumns": [],
          "schemaId": "public"
        }
      },
      "id": "save-telegram",
      "name": "Save Telegram",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        1000,
        100
      ],
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "tableName": "content_tasks",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "title": "Threads Post Generated",
            "description": "={{ $json.content }}",
            "status": "completed",
            "project_id": "={{ $('Set Input Data').item.json.project_id }}",
            "platform": "threads"
          },
          "matchingColumns": [],
          "schemaId": "public"
        }
      },
      "id": "save-threads",
      "name": "Save Threads",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        1000,
        250
      ],
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "tableName": "content_tasks",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "title": "Article Generated",
            "description": "={{ $json.content }}",
            "status": "completed",
            "project_id": "={{ $('Set Input Data').item.json.project_id }}",
            "platform": "article"
          },
          "matchingColumns": [],
          "schemaId": "public"
        }
      },
      "id": "save-article",
      "name": "Save Article",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        1000,
        400
      ],
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "tableName": "content_tasks",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "title": "HeyGen Video Task",
            "description": "Video generation started via API",
            "status": "pending",
            "project_id": "={{ $('Set Input Data').item.json.project_id }}",
            "platform": "heygen",
            "meta_data": "={{ JSON.stringify($json) }}"
          },
          "matchingColumns": [],
          "schemaId": "public"
        }
      },
      "id": "save-heygen",
      "name": "Save HeyGen Task",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        1000,
        550
      ],
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "tableName": "content_tasks",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "title": "Sora Video Task",
            "description": "Sora video generation requested",
            "status": "pending",
            "project_id": "={{ $('Set Input Data').item.json.project_id }}",
            "platform": "sora",
            "meta_data": "={{ JSON.stringify($json) }}"
          },
          "matchingColumns": [],
          "schemaId": "public"
        }
      },
      "id": "save-sora",
      "name": "Save Sora Task",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        1000,
        700
      ],
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "tableName": "content_tasks",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "title": "Instagram Post Generated",
            "description": "={{ $json.content }}",
            "status": "completed",
            "project_id": "={{ $('Set Input Data').item.json.project_id }}",
            "platform": "instagram"
          },
          "matchingColumns": [],
          "schemaId": "public"
        }
      },
      "id": "save-instagram",
      "name": "Save Instagram",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        1000,
        850
      ],
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Set Input Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Set Input Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Input Data": {
      "main": [
        [
          {
            "node": "LLM Rewrite: Telegram",
            "type": "main",
            "index": 0
          },
          {
            "node": "LLM Rewrite: Threads",
            "type": "main",
            "index": 0
          },
          {
            "node": "LLM Rewrite: Article",
            "type": "main",
            "index": 0
          },
          {
            "node": "API: HeyGen Video",
            "type": "main",
            "index": 0
          },
          {
            "node": "API: Sora Video",
            "type": "main",
            "index": 0
          },
          {
            "node": "LLM Rewrite: Instagram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LLM Rewrite: Telegram": {
      "main": [
        [
          {
            "node": "Save Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LLM Rewrite: Threads": {
      "main": [
        [
          {
            "node": "Save Threads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LLM Rewrite: Article": {
      "main": [
        [
          {
            "node": "Save Article",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "API: HeyGen Video": {
      "main": [
        [
          {
            "node": "Save HeyGen Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "API: Sora Video": {
      "main": [
        [
          {
            "node": "Save Sora Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LLM Rewrite: Instagram": {
      "main": [
        [
          {
            "node": "Save Instagram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}