{
  "name": "\ud30c\uc774\ud504\ub77c\uc778 \u2460 CS \ub9e4\ub274\uc5bc \ucd08\uc548 \uc0dd\uc131",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "event": "pagedUpdatedInDatabase",
        "databaseId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $env.NOTION_PRODUCT_DB_ID }}"
        },
        "simple": false
      },
      "id": "notion-trigger",
      "name": "Notion \uc0c1\ud488 \uc0c1\ud0dc \ubcc0\uacbd \uac10\uc9c0",
      "type": "n8n-nodes-base.notionTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.properties['\uc0c1\ud0dc'].select.name }}",
              "rightValue": "\ub7f0\uce6d\ub300\uae30",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "if-status-ready",
      "name": "\uc0c1\ud0dc = \ub7f0\uce6d\ub300\uae30 \uccb4\ud06c",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.notion.com/v1/databases/{{ $env.NOTION_RESEARCH_DB_ID }}/query",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "notionApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Notion-Version",
              "value": "2022-06-28"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"filter\": {\n    \"property\": \"\uc0c1\ud488\",\n    \"relation\": {\n      \"contains\": \"{{ $json.id }}\"\n    }\n  }\n}"
      },
      "id": "notion-get-research",
      "name": "\uc2dc\uc7a5\uc870\uc0ac \ubcf4\uace0\uc11c \uc870\ud68c",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        -100
      ]
    },
    {
      "parameters": {
        "jsCode": "// \uc0c1\ud488 \uc815\ubcf4\uc640 \uc2dc\uc7a5\uc870\uc0ac \ub370\uc774\ud130 \ud1b5\ud569\nconst product = $('\uc0c1\ud0dc = \ub7f0\uce6d\ub300\uae30 \uccb4\ud06c').first().json;\nconst research = $input.first().json;\n\n// \uc2dc\uc7a5\uc870\uc0ac \ub370\uc774\ud130 \ucd94\ucd9c\nlet researchData = {};\nif (research.results && research.results.length > 0) {\n  const r = research.results[0];\n  researchData = {\n    competitors: r.properties['\uacbd\uc7c1\uc0ac \ubd84\uc11d']?.rich_text?.[0]?.text?.content || '',\n    target: r.properties['\ud0c0\uac9f \uace0\uac1d']?.rich_text?.[0]?.text?.content || '',\n    usp: r.properties['USP']?.rich_text?.[0]?.text?.content || '',\n    cautions: r.properties['\uc8fc\uc758\uc0ac\ud56d']?.rich_text?.[0]?.text?.content || ''\n  };\n}\n\nreturn [{\n  json: {\n    product_id: product.id,\n    product_name: product.properties['\uc0c1\ud488\uba85']?.title?.[0]?.text?.content || '',\n    category: product.properties['\uce74\ud14c\uace0\ub9ac']?.select?.name || '',\n    detail_page_url: product.properties['\ud53c\uadf8\ub9c8URL']?.url || '',\n    market_research: researchData\n  }\n}];"
      },
      "id": "merge-data",
      "name": "\ub370\uc774\ud130 \ud1b5\ud569",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"contents\": [{\n    \"parts\": [{\n      \"text\": \"\ub2f9\uc2e0\uc740 \uc774\ucee4\uba38\uc2a4 CS \uc804\ubb38\uac00\uc785\ub2c8\ub2e4. \uc544\ub798 \uc790\ub8cc\ub97c \ubd84\uc11d\ud558\uc5ec CS \ub9e4\ub274\uc5bc\uc744 \uc791\uc131\ud558\uc138\uc694.\\n\\n[\uc0c1\ud488 \uc815\ubcf4]\\n- \uc0c1\ud488\uba85: {{ $json.product_name }}\\n- \uce74\ud14c\uace0\ub9ac: {{ $json.category }}\\n\\n[\uc2dc\uc7a5\uc870\uc0ac \ub370\uc774\ud130]\\n- \uacbd\uc7c1\uc0ac: {{ $json.market_research.competitors }}\\n- \ud0c0\uac9f \uace0\uac1d: {{ $json.market_research.target }}\\n- USP: {{ $json.market_research.usp }}\\n- \uc8fc\uc758\uc0ac\ud56d: {{ $json.market_research.cautions }}\\n\\n[\ucd9c\ub825 \ud615\uc2dd - JSON\uc73c\ub85c \uc751\ub2f5]\\n{\\n  \\\"usp\\\": [\\\"\uac15\uc8101\\\", \\\"\uac15\uc8102\\\", \\\"\uac15\uc8103\\\"],\\n  \\\"specs\\\": \\\"\uc8fc\uc694 \uc2a4\ud399 \uc815\ub9ac\\\",\\n  \\\"cautions\\\": \\\"\uc0ac\uc6a9 \uc2dc \uc8fc\uc758\uc0ac\ud56d\\\",\\n  \\\"faq\\\": [\\n    {\\\"q\\\": \\\"\uc608\uc0c1 \uc9c8\ubb381\\\", \\\"a\\\": \\\"\ub2f5\ubcc01\\\"},\\n    {\\\"q\\\": \\\"\uc608\uc0c1 \uc9c8\ubb382\\\", \\\"a\\\": \\\"\ub2f5\ubcc02\\\"}\\n  ],\\n  \\\"key_phrases\\\": \\\"\uace0\uac1d \uc751\ub300 \uc2dc \ud575\uc2ec \uba58\ud2b8\\\"\\n}\"\n    }]\n  }],\n  \"generationConfig\": {\n    \"temperature\": 0.7,\n    \"maxOutputTokens\": 2048\n  }\n}"
      },
      "id": "gemini-generate",
      "name": "Gemini \ub9e4\ub274\uc5bc \uc0dd\uc131",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Gemini \uc751\ub2f5 \ud30c\uc2f1\nconst response = $input.first().json;\nconst productData = $('\ub370\uc774\ud130 \ud1b5\ud569').first().json;\n\nlet manualContent = {};\ntry {\n  const text = response.candidates[0].content.parts[0].text;\n  // JSON \ubd80\ubd84\ub9cc \ucd94\ucd9c (```json ... ``` \ud615\uc2dd \ucc98\ub9ac)\n  const jsonMatch = text.match(/\\{[\\s\\S]*\\}/);\n  if (jsonMatch) {\n    manualContent = JSON.parse(jsonMatch[0]);\n  }\n} catch (e) {\n  manualContent = {\n    usp: ['\ud30c\uc2f1 \uc2e4\ud328'],\n    specs: '',\n    cautions: '',\n    faq: [],\n    key_phrases: ''\n  };\n}\n\nreturn [{\n  json: {\n    product_id: productData.product_id,\n    product_name: productData.product_name,\n    category: productData.category,\n    ...manualContent,\n    generated_at: new Date().toISOString()\n  }\n}];"
      },
      "id": "parse-response",
      "name": "\uc751\ub2f5 \ud30c\uc2f1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.notion.com/v1/pages",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "notionApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Notion-Version",
              "value": "2022-06-28"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"parent\": { \"database_id\": \"{{ $env.NOTION_MANUAL_DB_ID }}\" },\n  \"properties\": {\n    \"\uc0c1\ud488\uba85\": { \"title\": [{ \"text\": { \"content\": \"{{ $json.product_name }}\" } }] },\n    \"\uce74\ud14c\uace0\ub9ac\": { \"select\": { \"name\": \"{{ $json.category }}\" } },\n    \"USP\": { \"rich_text\": [{ \"text\": { \"content\": \"{{ $json.usp.join(', ') }}\" } }] },\n    \"\uc2a4\ud399\": { \"rich_text\": [{ \"text\": { \"content\": \"{{ $json.specs }}\" } }] },\n    \"FAQ\": { \"rich_text\": [{ \"text\": { \"content\": \"{{ JSON.stringify($json.faq) }}\" } }] },\n    \"\uc0dd\uc131\uc77c\": { \"date\": { \"start\": \"{{ $json.generated_at.split('T')[0] }}\" } },\n    \"\uc0c1\ud0dc\": { \"select\": { \"name\": \"\ucd08\uc548\" } }\n  }\n}"
      },
      "id": "notion-create-manual",
      "name": "Notion \ub9e4\ub274\uc5bc DB \ub4f1\ub85d",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.JANDI_WEBHOOK_URL }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"body\": \"[CS \ub9e4\ub274\uc5bc] \ucd08\uc548 \uc0dd\uc131 \uc644\ub8cc\",\n  \"connectColor\": \"#00C73C\",\n  \"connectInfo\": [\n    {\n      \"title\": \"\uc0c1\ud488\",\n      \"description\": \"{{ $('\uc751\ub2f5 \ud30c\uc2f1').first().json.product_name }}\"\n    },\n    {\n      \"title\": \"\uc0c1\ud0dc\",\n      \"description\": \"\uac80\ud1a0 \uc694\uccad\"\n    }\n  ]\n}"
      },
      "id": "jandi-notify",
      "name": "\uc794\ub514 \uc54c\ub9bc",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1540,
        0
      ]
    }
  ],
  "connections": {
    "Notion \uc0c1\ud488 \uc0c1\ud0dc \ubcc0\uacbd \uac10\uc9c0": {
      "main": [
        [
          {
            "node": "\uc0c1\ud0dc = \ub7f0\uce6d\ub300\uae30 \uccb4\ud06c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\uc0c1\ud0dc = \ub7f0\uce6d\ub300\uae30 \uccb4\ud06c": {
      "main": [
        [
          {
            "node": "\uc2dc\uc7a5\uc870\uc0ac \ubcf4\uace0\uc11c \uc870\ud68c",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "\uc2dc\uc7a5\uc870\uc0ac \ubcf4\uace0\uc11c \uc870\ud68c": {
      "main": [
        [
          {
            "node": "\ub370\uc774\ud130 \ud1b5\ud569",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ub370\uc774\ud130 \ud1b5\ud569": {
      "main": [
        [
          {
            "node": "Gemini \ub9e4\ub274\uc5bc \uc0dd\uc131",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini \ub9e4\ub274\uc5bc \uc0dd\uc131": {
      "main": [
        [
          {
            "node": "\uc751\ub2f5 \ud30c\uc2f1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\uc751\ub2f5 \ud30c\uc2f1": {
      "main": [
        [
          {
            "node": "Notion \ub9e4\ub274\uc5bc DB \ub4f1\ub85d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion \ub9e4\ub274\uc5bc DB \ub4f1\ub85d": {
      "main": [
        [
          {
            "node": "\uc794\ub514 \uc54c\ub9bc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}