{
 "name": "[커머스] 이커머스 재고 부족 알림 자동화",
 "nodes": [
  {
   "id": "fa650061-f45e-42a5-b0fc-5c312b43fc6b",
   "name": "Schedule Trigger",
   "type": "n8n-nodes-base.scheduleTrigger",
   "typeVersion": 1.2,
   "position": [
    -272,
    1216
   ],
   "parameters": {
    "rule": {
     "interval": [
      {
       "field": "hours"
      }
     ]
    }
   }
  },
  {
   "id": "cadb6ef9-aa91-4f5f-8474-1b526c22972b",
   "name": "현재재고<10",
   "type": "n8n-nodes-base.filter",
   "typeVersion": 2.2,
   "position": [
    400,
    1216
   ],
   "parameters": {
    "conditions": {
     "options": {
      "caseSensitive": true,
      "leftValue": "",
      "typeValidation": "strict",
      "version": 2
     },
     "conditions": [
      {
       "id": "b9549332-f288-4fdd-9077-e82f54088fe0",
       "leftValue": "={{ $json['현재재고'] }}",
       "rightValue": 10,
       "operator": {
        "type": "number",
        "operation": "lt"
       }
      }
     ],
     "combinator": "and"
    },
    "options": {}
   }
  },
  {
   "id": "81cc1beb-18a2-41de-82e8-ccc1d11d2e3b",
   "name": "상품명, 현재재고, 일평균 판매량만 추출",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    704,
    1216
   ],
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "bab20fac-4ffc-4a40-a961-4ca70dd61fd7",
       "name": "상품명",
       "value": "={{ $json['상품명'] }}",
       "type": "string"
      },
      {
       "id": "5116665b-57e3-498b-b5cb-8824740fa2c9",
       "name": "현재재고",
       "value": "={{ $json['현재재고'] }}",
       "type": "number"
      },
      {
       "id": "2e7edbcd-a1a5-42cc-90cc-b7316f7e23af",
       "name": "일평균판매량",
       "value": "={{ $json['일평균판매량'] }}",
       "type": "number"
      }
     ]
    },
    "options": {}
   }
  },
  {
   "id": "5eba469c-e460-4744-b38a-1e55c2fd875a",
   "name": "알림 메시지 작성",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    1008,
    1216
   ],
   "parameters": {
    "jsCode": "// 헤더에 총 개수 추가\nlet message = `📣 *10개 미만 재고 알림* (총 ${items.length}개)\\n\\n`;\nmessage += `_일평균판매량은 최근 일주일 평균 판매량입니다._\\n\\n\\n`;\n\n// 각 상품 정보 추가\nmessage += items.map(item => {\n  return `📦 *${item.json.상품명}*\n재고: ${item.json.현재재고}개  |  일평균판매량: ${item.json.일평균판매량}개`;\n}).join('\\n\\n\\n');\n\nreturn [{\n  json: {\n    text: message\n  }\n}];"
   }
  },
  {
   "id": "3e55f1a8-7158-4214-b1e0-16c727116858",
   "name": "Send a message",
   "type": "n8n-nodes-base.slack",
   "typeVersion": 2.3,
   "position": [
    1376,
    1216
   ],
   "parameters": {
    "authentication": "accessToken",
    "select": "channel",
    "channelId": {
     "__rl": true,
     "mode": "id",
     "value": "YOUR_SLACK_CHANNEL_ID"
    },
    "text": "={{ $json.text }}",
    "otherOptions": {
     "includeLinkToWorkflow": false
    }
   }
  },
  {
   "id": "946ec9f3-786e-46e4-926e-d5022cc0571b",
   "name": "Sticky Note2",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    -368,
    960
   ],
   "parameters": {
    "content": "## 1. 스케줄 트리거\n\n- 1시간 간격으로 워크플로우를 실행합니다.\n- 스케줄 트리거를 실행하기 위해서는 n8n 워크플로우 상단의 Inactive 토글을 활성화해 Active 상태로 만듭니다.",
    "height": 432,
    "width": 288,
    "color": 3
   }
  },
  {
   "id": "2844ceeb-531f-4e49-b59e-6f63558ab851",
   "name": "Sticky Note3",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    0,
    960
   ],
   "parameters": {
    "content": "## 2. 구글 시트 읽기\n\n- 구글 시트에서 재고 데이터를 가져옵니다.",
    "height": 432,
    "width": 288
   }
  },
  {
   "id": "6d884853-bcb6-429b-845e-bbe46e8421f9",
   "name": "Sticky Note4",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    304,
    960
   ],
   "parameters": {
    "content": "## 3. 재고 10개 미만 필터링\n\n- '현재재고'컬럼의 값이 10개 미만인 값만 필터링합니다.\n- 재고 10개 미만인 상품이 없을 경우, 워크플로우가 여기서 종료되며 알림이 발송되지 않습니다.",
    "height": 432,
    "width": 288
   }
  },
  {
   "id": "4b58b161-6bcf-4287-8319-75f0ec42f895",
   "name": "Sticky Note5",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    608,
    960
   ],
   "parameters": {
    "content": "## 4. 필요 컬럼 선택\n\n- 알림을 보낼 컬럼만 남깁니다.\n- 상품명, 현재재고, 일평균판매량 컬럼만 가져옵니다.",
    "height": 432,
    "width": 288
   }
  },
  {
   "id": "00a3a033-10d8-4b28-bd37-8c7343b0fbb7",
   "name": "Sticky Note6",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    912,
    960
   ],
   "parameters": {
    "content": "## 5. 하나의 메시지로 합치기\n\n- 1시간에 1개의 메시지를 발송하도록 재고 10개 미만인 상품 정보를 하나의 텍스트로 합칩니다. \n- 맨 위에 현재재고가 10개 미만인 상품 수를 표출합니다.\n- 슬랙 알림이 너무 많이 울리는 상황을 방지합니다.",
    "height": 432,
    "width": 288
   }
  },
  {
   "id": "5142bbdf-f7d7-40aa-9b2f-3906e8f507a2",
   "name": "Sticky Note7",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    1280,
    960
   ],
   "parameters": {
    "content": "## 6. 슬랙 메시지 보내기\n\n- 슬랙 채널에 메시지를 보냅니다.",
    "height": 432,
    "width": 288,
    "color": 6
   }
  },
  {
   "id": "e8d87e85-bff4-4ad8-84f2-f87bd47fcdeb",
   "name": "Sticky Note8",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    -48,
    832
   ],
   "parameters": {
    "content": "# TASK",
    "height": 608,
    "width": 1296,
    "color": 4
   }
  },
  {
   "id": "sample-stock",
   "name": "샘플 재고 시트 (가상 데이터)",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    96,
    1216
   ],
   "parameters": {
    "jsCode": "// 샘플 데이터 (실제 매장 재고 아님)\nconst rows = [{\"상품명\": \"무선 이어폰 케이스\", \"현재재고\": 4, \"일평균판매량\": 3}, {\"상품명\": \"텀블러 500ml\", \"현재재고\": 23, \"일평균판매량\": 2}, {\"상품명\": \"USB-C 충전 케이블\", \"현재재고\": 7, \"일평균판매량\": 5}, {\"상품명\": \"노트북 파우치\", \"현재재고\": 31, \"일평균판매량\": 1}, {\"상품명\": \"스마트폰 거치대\", \"현재재고\": 2, \"일평균판매량\": 4}, {\"상품명\": \"데스크 매트\", \"현재재고\": 15, \"일평균판매량\": 2}, {\"상품명\": \"보조배터리 10000mAh\", \"현재재고\": 9, \"일평균판매량\": 6}, {\"상품명\": \"키보드 손목 받침\", \"현재재고\": 18, \"일평균판매량\": 1}];\nreturn rows.map(r => ({ json: r }));"
   }
  },
  {
   "id": "manual",
   "name": "Run manually",
   "type": "n8n-nodes-base.manualTrigger",
   "typeVersion": 1,
   "position": [
    -272,
    1396
   ],
   "parameters": {}
  }
 ],
 "connections": {
  "Schedule Trigger": {
   "main": [
    [
     {
      "node": "샘플 재고 시트 (가상 데이터)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Run manually": {
   "main": [
    [
     {
      "node": "샘플 재고 시트 (가상 데이터)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "샘플 재고 시트 (가상 데이터)": {
   "main": [
    [
     {
      "node": "현재재고<10",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "현재재고<10": {
   "main": [
    [
     {
      "node": "상품명, 현재재고, 일평균 판매량만 추출",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "상품명, 현재재고, 일평균 판매량만 추출": {
   "main": [
    [
     {
      "node": "알림 메시지 작성",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "알림 메시지 작성": {
   "main": [
    [
     {
      "node": "Send a message",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1",
  "timezone": "Asia/Seoul"
 },
 "meta": {
  "source": "datapopcorn.ai/workflow"
 }
}