{
  "name": "Contents Automation",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -460,
        -140
      ],
      "id": "c870e6cf-5114-45d9-9e25-ff4508d87a47",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "18KOQh7LmkFPSlOfvh0NyYO2qL-nZlLYoH6ZvkpwM9Pc",
          "mode": "list",
          "cachedResultName": "\ucee8\ud150\uce20 \uc790\ub3d9\ud654-\uae00\uac10",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/18KOQh7LmkFPSlOfvh0NyYO2qL-nZlLYoH6ZvkpwM9Pc/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "\uae00\uac10",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/18KOQh7LmkFPSlOfvh0NyYO2qL-nZlLYoH6ZvkpwM9Pc/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        -240,
        -140
      ],
      "id": "9f858cf5-8b6e-4150-9529-db5be84f4525",
      "name": "Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const COL = '\uae00\uac10';\n\n// \ube44\uc5b4\uc788\uc9c0 \uc54a\uc740 \"\uae00\uac10\"\ub9cc \ubaa8\uc544 \ub9c8\uc9c0\ub9c9 \uac12 \ubc18\ud658\nconst nonEmpty = items\n  .map(i => i.json[COL])\n  .filter(v => v !== undefined && String(v).trim() !== '');\n\nconst last = nonEmpty.length ? nonEmpty[nonEmpty.length - 1] : null;\n\nreturn [{ json: { \uae00\uac10: last } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -20,
        -140
      ],
      "id": "5d6106e2-28b0-4f82-84a1-30a4b6dc343b",
      "name": "Code"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "chatgpt-4o-latest",
          "mode": "list",
          "cachedResultName": "CHATGPT-4O-LATEST"
        },
        "messages": {
          "values": [
            {
              "content": "\uc774\uba54\uc77c\ub85c \uc804\uc1a1\ud560 \ucee8\ud150\uce20\ub97c \uc791\uc131\ud574 \uc918. \uc8fc\uc5b4\uc9c4 \uae00\uac10\uc5d0 \ub300\ud574 \uc18c\uc81c\ubaa9 3\uac1c\uc640 \uc18c\uc81c\ubaa9\ub9c8\ub2e4 \uc0ac\uc9c4 1\uac1c\ub97c \uc791\uc131\ud574 \uc918. \uc18c\uc81c\ubaa9 \ud558\ub098 \ub2f9 500\uc790\uc529 \uc368 \uc918.\n\uc0ac\uc9c4\uc740 \uc544\ub798 \uc0ac\uc774\ud2b8\uc5d0\uc11c \ucc3e\uc544 \uc918.\n------\nhttps://www.pexels.com/ko-kr/discover/",
              "role": "system"
            },
            {
              "content": "=\uae00\uac10:  {{ $json['\uae00\uac10'] }}"
            }
          ]
        },
        "jsonOutput": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        200,
        -140
      ],
      "id": "859c4557-35a9-4eab-b278-1a62726c124f",
      "name": "OpenAI",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// n8n Code (JavaScript) \u2014 Run Once for All Items\n// \uc785\ub825: items[*].json.{ output | result | (json \uc790\uccb4) } \uc548\uc5d0 \ub370\uc774\ud130\n// \uad6c\uc870\ub294 \uac19\uc9c0\ub9cc \ud544\ub4dc\uba85\uc774 \ubc14\ub014 \uc218 \uc788\uc74c(\uc608: image \u2194 image_url \u2194 imageUrl)\n\nfunction toArray(raw) {\n  if (raw == null) return [];\n  if (Array.isArray(raw)) return raw;\n  if (typeof raw === 'string') {\n    try { return JSON.parse(raw); }\n    catch (e) { throw new Error('\uc785\ub825\uc774 JSON \ubb38\uc790\uc5f4\uc774 \uc544\ub2d9\ub2c8\ub2e4: ' + e.message); }\n  }\n  return [raw];\n}\n\n// \u2500\u2500 \ud0a4 \uc815\uaddc\ud654 & \ub3d9\uc758\uc5b4 \ucc3e\uae30 \uc720\ud2f8 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nconst normalize = k => String(k || '').toLowerCase().replace(/[^a-z0-9]/g, ''); // \ub300\uc18c\ubb38\uc790/_,-/\uacf5\ubc31 \ubb34\uc2dc\n\nfunction pick(obj, synonyms) {\n  if (!obj || typeof obj !== 'object') return undefined;\n  const normMap = new Map(Object.entries(obj).map(([k, v]) => [normalize(k), v]));\n\n  // 1) \uc815\ud655 \ub9e4\uce6d\n  for (const s of synonyms) {\n    const v = normMap.get(normalize(s));\n    if (v !== undefined) return v;\n  }\n  // 2) \ud3ec\ud568 \ub9e4\uce6d(\uc608: imageUrl, main_image \ub4f1)\n  for (const s of synonyms) {\n    const needle = normalize(s);\n    for (const [nk, v] of normMap.entries()) {\n      if (nk.includes(needle)) return v;\n    }\n  }\n  return undefined;\n}\n\n// \ub3d9\uc758\uc5b4 \uc0ac\uc804(\ud544\uc694\uc2dc \uc5ec\uae30\uc5d0\ub9cc \ucd94\uac00)\nconst SYN = {\n  subject: ['subject', 'title', 'heading', 'topic'],\n  blocks:  ['content', 'blocks', 'items', 'sections', 'list'],\n  subtitle:['subtitle', 'sub_title', 'subheading', 'sub_header', 'heading', 'title2'],\n  text:    ['text', 'body', 'content', 'description', 'desc', 'message'],\n  image:   ['image', 'image_url', 'imageurl', 'img', 'photo', 'picture', 'thumbnail', 'thumb']\n};\n\nfunction getBlocks(root) {\n  let b = pick(root, SYN.blocks);\n  if (Array.isArray(b)) return b;\n  // fallback: root\uc758 \uac12\ub4e4 \uc911 \uccab \ubc88\uc9f8 \ubc30\uc5f4\n  for (const v of Object.values(root || {})) if (Array.isArray(v)) return v;\n  return [];\n}\n\nconst out = [];\n\nfor (const { json } of items) {\n  const raw = json.output ?? json.result ?? json; // \uc785\ub825 \uacbd\ub85c \uc790\ub3d9 \ud0d0\uc0c9\n  const arr = toArray(raw);\n\n  for (const entry of arr) {\n    // \uad6c\uc870\ub294 \ub3d9\uc77c(\uba54\uc2dc\uc9c0\u2192\ucee8\ud150\uce20)\ub77c\uace0 \uac00\uc815\ud558\ub418 \ud0a4\ub294 \uc720\uc5f0\ud558\uac8c\n    const container =\n      pick(entry, ['message'])?.content ??\n      pick(entry, ['content']) ??\n      entry?.message?.content ?? entry?.content ?? entry;\n\n    if (!container) continue;\n\n    // subject: \ub8e8\ud2b8\uc5d0\uc11c, \uc5c6\uc73c\uba74 \uac01 \ube14\ub85d\uc5d0\uc11c fallback\n    const subjectRoot = pick(container, SYN.subject);\n\n    const blocks = getBlocks(container);\n    for (const b of blocks) {\n      const subj = subjectRoot ?? pick(b, SYN.subject) ?? '';\n      const subtitle = pick(b, SYN.subtitle) ?? '';\n      const text = pick(b, SYN.text) ?? '';\n      const image = pick(b, SYN.image) ?? '';\n\n      out.push({ json: { subject: subj, subtitle, text, image } });\n    }\n  }\n}\n\nreturn out;\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        -140
      ],
      "id": "f7b7f830-cd97-4a61-a95f-4d76ed0a1c22",
      "name": "Code1"
    },
    {
      "parameters": {
        "operation": "create",
        "documentId": {
          "__rl": true,
          "value": "1zKUguhfu_RIyoxq-8LT6r0untL9jW6Qk1NX3Zbuzq2w",
          "mode": "list",
          "cachedResultName": "\ucee8\ud150\uce20 \uc790\ub3d9\ud654-\ucd08\uc548",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1zKUguhfu_RIyoxq-8LT6r0untL9jW6Qk1NX3Zbuzq2w/edit?usp=drivesdk"
        },
        "title": "={{ 'n8n-sheet-' + $now.setZone('Asia/Seoul').toFormat('yyyy-LL-dd') }}",
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        760,
        -60
      ],
      "id": "f272a5aa-860c-430f-bbe0-cacb8ebd4607",
      "name": "Google Sheets1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1zKUguhfu_RIyoxq-8LT6r0untL9jW6Qk1NX3Zbuzq2w",
          "mode": "list",
          "cachedResultName": "\ucee8\ud150\uce20 \uc790\ub3d9\ud654-\ucd08\uc548",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1zKUguhfu_RIyoxq-8LT6r0untL9jW6Qk1NX3Zbuzq2w/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ 'n8n-sheet-' + $now.setZone('Asia/Seoul').toFormat('yyyy-LL-dd') }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "cellFormat": "RAW"
        }
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        760,
        -280
      ],
      "id": "d1dea4ae-00b0-4614-99df-e3afa4aa84a9",
      "name": "Google Sheets2",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 12
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -440,
        200
      ],
      "id": "5308a648-8f33-486f-b57f-da667724ca44",
      "name": "Schedule Trigger1"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1zKUguhfu_RIyoxq-8LT6r0untL9jW6Qk1NX3Zbuzq2w",
          "mode": "list",
          "cachedResultName": "\ucee8\ud150\uce20 \uc790\ub3d9\ud654-\ucd08\uc548",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1zKUguhfu_RIyoxq-8LT6r0untL9jW6Qk1NX3Zbuzq2w/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ 'n8n-sheet-' + $now.setZone('Asia/Seoul').toFormat('yyyy-LL-dd') }}",
          "mode": "name"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        -220,
        200
      ],
      "id": "d2f5bbf5-3b2a-4f8b-9120-37805efcfce6",
      "name": "Google Sheets3",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// N8N Code Node - Google Sheets to HTML Email Formatter\n// \uc774\uc804 \ub178\ub4dc\uc5d0\uc11c \ubc1b\uc740 \ub370\uc774\ud130\ub97c items \ubcc0\uc218\ub85c \uc811\uadfc \uac00\ub2a5\n\n// \uc785\ub825 \ub370\uc774\ud130 \uac00\uc838\uc624\uae30\nconst inputItems = $input.all();\n\n// HTML \ud15c\ud50c\ub9bf \uc0dd\uc131 \ud568\uc218\nfunction createEmailHTML(data) {\n  // \uae30\ubcf8 HTML \uc2a4\ud0c0\uc77c \uc815\uc758\n  const htmlStyle = `\n    <style>\n      body {\n        font-family: 'Malgun Gothic', '\ub9d1\uc740 \uace0\ub515', Arial, sans-serif;\n        line-height: 1.6;\n        color: #333;\n        background-color: #f5f5f5;\n        margin: 0;\n        padding: 20px;\n      }\n      .email-container {\n        max-width: 800px;\n        margin: 0 auto;\n        background-color: #ffffff;\n        border-radius: 10px;\n        box-shadow: 0 2px 10px rgba(0,0,0,0.1);\n        overflow: hidden;\n      }\n      .email-header {\n        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n        color: white;\n        padding: 30px;\n        text-align: center;\n      }\n      .email-header h1 {\n        margin: 0;\n        font-size: 28px;\n        font-weight: 600;\n      }\n      .content-section {\n        padding: 30px;\n      }\n      .content-card {\n        border: 1px solid #e0e0e0;\n        border-radius: 8px;\n        padding: 20px;\n        margin-bottom: 20px;\n        background-color: #fafafa;\n      }\n      .content-title {\n        font-size: 20px;\n        font-weight: bold;\n        color: #4a5568;\n        margin-bottom: 10px;\n        padding-bottom: 10px;\n        border-bottom: 2px solid #667eea;\n      }\n      .content-subtitle {\n        font-size: 16px;\n        color: #718096;\n        margin-bottom: 15px;\n        font-weight: 500;\n      }\n      .content-text {\n        font-size: 14px;\n        line-height: 1.8;\n        color: #2d3748;\n        white-space: pre-line;\n        background-color: white;\n        padding: 15px;\n        border-radius: 5px;\n        border-left: 4px solid #667eea;\n      }\n      .content-image {\n        margin-top: 15px;\n        text-align: center;\n      }\n      .content-image img {\n        max-width: 100%;\n        height: auto;\n        border-radius: 8px;\n        box-shadow: 0 4px 6px rgba(0,0,0,0.1);\n        display: block;\n        margin: 0 auto;\n      }\n      .image-fallback {\n        padding: 40px;\n        background-color: #f0f0f0;\n        border-radius: 8px;\n        color: #666;\n        text-align: center;\n      }\n      .email-footer {\n        background-color: #f7fafc;\n        padding: 20px;\n        text-align: center;\n        color: #718096;\n        font-size: 12px;\n        border-top: 1px solid #e2e8f0;\n      }\n      .divider {\n        height: 1px;\n        background: linear-gradient(90deg, transparent, #cbd5e0, transparent);\n        margin: 20px 0;\n      }\n    </style>\n  `;\n\n  // HTML \ubcf8\ubb38 \uc0dd\uc131\n  let htmlBody = `\n    <!DOCTYPE html>\n    <html lang=\"ko\">\n    <head>\n      <meta charset=\"UTF-8\">\n      <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n      <title>Newsletter</title>\n      ${htmlStyle}\n    </head>\n    <body>\n      <div class=\"email-container\">\n        <div class=\"email-header\">\n          <h1>\ud83d\udce7 \ub274\uc2a4\ub808\ud130</h1>\n        </div>\n        <div class=\"content-section\">\n  `;\n\n  // \uac01 \ud56d\ubaa9\uc744 HTML\ub85c \ubcc0\ud658\n  data.forEach((item, index) => {\n    // \ud544\ub4dc \uac12 \uac00\uc838\uc624\uae30 (\ub2e4\uc591\ud55c \uac00\ub2a5\ud55c \ud544\ub4dc\uba85 \ucc98\ub9ac)\n    const subject = item.subject || item.\uc81c\ubaa9 || '';\n    const subtitle = item.subtitle || item.\ubd80\uc81c || '';\n    const text = item.text || item.\ub0b4\uc6a9 || item.\ud14d\uc2a4\ud2b8 || '';\n    let image = item.image || item.\uc774\ubbf8\uc9c0 || '';\n    \n    // \uc774\ubbf8\uc9c0 URL \ucc98\ub9ac\n    if (image) {\n      // URL \ub514\ucf54\ub529 \ucc98\ub9ac\n      try {\n        image = decodeURIComponent(image);\n      } catch (e) {\n        // \ub514\ucf54\ub529 \uc2e4\ud328 \uc2dc \uc6d0\ubcf8 \uc0ac\uc6a9\n      }\n      \n      // Pexels URL \ucc98\ub9ac\n      if (image.includes('pexels.com')) {\n        // \uc774\ubbf8 images.pexels.com URL\uc778 \uacbd\uc6b0 - \ud06c\uae30 \ucd5c\uc801\ud654\n        if (image.includes('images.pexels.com')) {\n          // \uae30\ubcf8 URL \uc720\uc9c0\ud558\uace0 \ud06c\uae30 \ud30c\ub77c\ubbf8\ud130 \ucd94\uac00\n          const baseUrl = image.split('?')[0];\n          image = `${baseUrl}?auto=compress&cs=tinysrgb&w=800&h=600&dpr=1`;\n        } \n        // \uc6f9\ud398\uc774\uc9c0 URL\uc778 \uacbd\uc6b0 - \uc2e4\uc81c \uc774\ubbf8\uc9c0 URL\ub85c \ubcc0\ud658\n        else if (image.includes('pexels.com')) {\n          // Pexels \uc6f9\ud398\uc774\uc9c0 URL\uc5d0\uc11c photo ID \ucd94\ucd9c\n          // \ud328\ud134 1: https://www.pexels.com/photo/[title-text]-[PHOTO_ID]/\n          // \ud328\ud134 2: https://www.pexels.com/ko-kr/photo/[PHOTO_ID]/\n          // \ud328\ud134 3: https://pexels.com/[lang]/photo/[PHOTO_ID]/\n          \n          // URL \ub05d\uc5d0\uc11c \uc22b\uc790 ID \ucd94\ucd9c (\ub354 \uc720\uc5f0\ud55c \uc815\uaddc\uc2dd)\n          const pexelsMatch = image.match(/\\/photo\\/(?:[^\\/]*-)?(\\d+)\\/?$/);\n          \n          if (pexelsMatch && pexelsMatch[1]) {\n            const photoId = pexelsMatch[1];\n            // Pexels \uc774\ubbf8\uc9c0 \uc9c1\uc811 URL \uad6c\uc131\n            image = `https://images.pexels.com/photos/${photoId}/pexels-photo-${photoId}.jpeg?auto=compress&cs=tinysrgb&w=800&h=600&dpr=1`;\n          } else {\n            // ID\ub97c \ucc3e\uc744 \uc218 \uc5c6\ub294 \uacbd\uc6b0 - \uae30\ubcf8 \ud50c\ub808\uc774\uc2a4\ud640\ub354\n            console.log('Pexels URL \ud30c\uc2f1 \uc2e4\ud328:', image);\n            image = 'https://via.placeholder.com/800x600.png?text=Image+Not+Available';\n          }\n        }\n      }\n      // \uc774\ubbf8 \uc644\uc804\ud55c \uc774\ubbf8\uc9c0 URL\uc778 \uacbd\uc6b0 \uadf8\ub300\ub85c \uc0ac\uc6a9\n      else if (image.startsWith('http://') || image.startsWith('https://')) {\n        // URL\uc740 \uadf8\ub300\ub85c \uc720\uc9c0\n        image = image;\n      }\n      \n      // \ub514\ubc84\uae45\uc6a9 \ub85c\uadf8\n      console.log('Original URL:', item.image || item.\uc774\ubbf8\uc9c0);\n      console.log('Processed URL:', image);\n    }\n    \n    htmlBody += `\n      <div class=\"content-card\">\n        <div class=\"content-title\">\n          ${subject}\n        </div>\n        ${subtitle ? `<div class=\"content-subtitle\">${subtitle}</div>` : ''}\n        <div class=\"content-text\">\n          ${text.replace(/\\n/g, '<br>')}\n        </div>\n        ${image ? `\n          <div class=\"content-image\">\n            <img src=\"${image}\" alt=\"${subject}\" onerror=\"this.style.display='none'; this.nextElementSibling.style.display='block';\" />\n            <div class=\"image-fallback\" style=\"display:none;\">\n              \ud83d\uddbc\ufe0f \uc774\ubbf8\uc9c0\ub97c \ubd88\ub7ec\uc62c \uc218 \uc5c6\uc2b5\ub2c8\ub2e4<br>\n              <small>\uc6d0\ubcf8 URL: ${item.image || item.\uc774\ubbf8\uc9c0 || ''}</small>\n            </div>\n          </div>\n        ` : ''}\n      </div>\n    `;\n    \n    // \ub9c8\uc9c0\ub9c9 \ud56d\ubaa9\uc774 \uc544\ub2c8\uba74 \uad6c\ubd84\uc120 \ucd94\uac00\n    if (index < data.length - 1) {\n      htmlBody += '<div class=\"divider\"></div>';\n    }\n  });\n\n  // HTML \ub9c8\ubb34\ub9ac\n  htmlBody += `\n        </div>\n        <div class=\"email-footer\">\n          <p>\u00a9 ${new Date().getFullYear()} Newsletter. All rights reserved.</p>\n          <p>\uc774 \uc774\uba54\uc77c\uc740 \uc790\ub3d9\uc73c\ub85c \uc0dd\uc131\ub418\uc5c8\uc2b5\ub2c8\ub2e4.</p>\n        </div>\n      </div>\n    </body>\n    </html>\n  `;\n\n  return htmlBody;\n}\n\n// \ub370\uc774\ud130 \ucc98\ub9ac \ubc0f HTML \uc0dd\uc131\ntry {\n  // \uc785\ub825 \ub370\uc774\ud130 \ud655\uc778\n  if (!inputItems || inputItems.length === 0) {\n    throw new Error('\uc785\ub825 \ub370\uc774\ud130\uac00 \uc5c6\uc2b5\ub2c8\ub2e4.');\n  }\n\n  // Google Sheets \ub370\uc774\ud130 \ucd94\ucd9c\n  let sheetData = [];\n  \n  // N8N\uc758 Google Sheets \ub178\ub4dc \ucd9c\ub825 \ud615\uc2dd\uc5d0 \ub530\ub77c \ucc98\ub9ac\n  inputItems.forEach(item => {\n    // json \uc18d\uc131\uc774 \uc788\ub294 \uacbd\uc6b0\n    if (item.json) {\n      sheetData.push(item.json);\n    }\n    // \uc9c1\uc811 \ub370\uc774\ud130\uac00 \uc788\ub294 \uacbd\uc6b0\n    else if (item.subject || item.\uc81c\ubaa9) {\n      sheetData.push(item);\n    }\n  });\n\n  // HTML \uc0dd\uc131\n  const emailHTML = createEmailHTML(sheetData);\n  \n  // \uacb0\uacfc \ubc18\ud658 (N8N \ud615\uc2dd)\n  return [\n    {\n      json: {\n        html: emailHTML,\n        subject: $input.first().json.subject,\n        processedItems: sheetData.length,\n        timestamp: new Date().toISOString()\n      }\n    }\n  ];\n\n} catch (error) {\n  // \uc5d0\ub7ec \ucc98\ub9ac\n  return [\n    {\n      json: {\n        error: error.message,\n        html: `\n          <html>\n            <body style=\"font-family: Arial, sans-serif; padding: 20px;\">\n              <h2 style=\"color: #e53e3e;\">\ucc98\ub9ac \uc911 \uc624\ub958\uac00 \ubc1c\uc0dd\ud588\uc2b5\ub2c8\ub2e4</h2>\n              <p>\uc624\ub958 \uba54\uc2dc\uc9c0: ${error.message}</p>\n              <p>\uc785\ub825 \ub370\uc774\ud130\ub97c \ud655\uc778\ud574\uc8fc\uc138\uc694.</p>\n            </body>\n          </html>\n        `\n      }\n    }\n  ];\n}"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        40,
        80
      ],
      "id": "9ead6d6b-9287-48b6-81a0-1e05ada21022",
      "name": "Code2"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1FLdrvMdKeIETc-VD1oQSwgJF-KWwEkazb_ib3ilGjCk",
          "mode": "list",
          "cachedResultName": "\uba54\uc77c \uc804\uc1a1 \ub9ac\uc2a4\ud2b8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FLdrvMdKeIETc-VD1oQSwgJF-KWwEkazb_ib3ilGjCk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "mails",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FLdrvMdKeIETc-VD1oQSwgJF-KWwEkazb_ib3ilGjCk/edit#gid=0"
        },
        "options": {
          "dataLocationOnSheet": {
            "values": {
              "rangeDefinition": "specifyRangeA1",
              "range": "A1:A"
            }
          }
        }
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        40,
        280
      ],
      "id": "63a5a578-4341-4995-a821-f79f4f1a892d",
      "name": "Google Sheets4",
      "executeOnce": true,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "53f2b1a0-76b3-4253-904c-e9e4afa1bb7b",
              "name": "html",
              "value": "={{ $json.html }}",
              "type": "string"
            },
            {
              "id": "e97e29bb-50d6-484d-92bc-036a54af5535",
              "name": "subject",
              "value": "={{ $json.subject }}",
              "type": "string"
            },
            {
              "id": "c56100f5-5952-4e32-ac51-13ff7759f5dc",
              "name": "join",
              "value": "email",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        260,
        80
      ],
      "id": "eaf08934-7a35-46b3-b126-87ffaee316b0",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "04011532-56d2-41b8-a18c-22a9ae81ff55",
              "name": "\uba54\uc77c \ub9ac\uc2a4\ud2b8",
              "value": "={{ $json['\uba54\uc77c \ub9ac\uc2a4\ud2b8'] }}",
              "type": "string"
            },
            {
              "id": "6d4c19c9-bff2-4048-a0ce-c28874ec8cfa",
              "name": "join",
              "value": "email",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        260,
        280
      ],
      "id": "86386c40-6203-4bfc-a861-ed3228bb0b35",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "mode": "combine",
        "fieldsToMatchString": "join",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.1,
      "position": [
        520,
        180
      ],
      "id": "675af70a-9331-4471-927d-6913ac9bae17",
      "name": "Merge"
    },
    {
      "parameters": {
        "sendTo": "={{ $json['\uba54\uc77c \ub9ac\uc2a4\ud2b8'] }}",
        "subject": "={{ $json.subject }}",
        "message": "={{ $json.html }}",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        740,
        180
      ],
      "id": "91c6989d-2b40-4968-8436-7116db1686ed",
      "name": "Gmail",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code1": {
      "main": [
        [
          {
            "node": "Google Sheets2",
            "type": "main",
            "index": 0
          },
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets2": {
      "main": [
        []
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "Google Sheets3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets3": {
      "main": [
        [
          {
            "node": "Code2",
            "type": "main",
            "index": 0
          },
          {
            "node": "Google Sheets4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code2": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets4": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b4c6af65-398f-499a-8a11-7ce5c743cef7",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "HDU3fmzn1gZuhBjs",
  "tags": []
}