{
 "name": "[미분류] 급식 알리미 — 매일 아침 NEIS 급식 자동 발송",
 "nodes": [
  {
   "id": "7a70316c-8129-4bed-bffc-16d90848b5dc",
   "name": "매일 07:00 트리거",
   "type": "n8n-nodes-base.scheduleTrigger",
   "typeVersion": 1.3,
   "position": [
    240,
    300
   ],
   "parameters": {
    "rule": {
     "interval": [
      {
       "field": "days",
       "daysInterval": 1,
       "triggerAtHour": 7,
       "triggerAtMinute": 0
      }
     ]
    }
   }
  },
  {
   "id": "88aa747b-6bf9-44cb-ad3c-3d0e6d1c009e",
   "name": "급식 조회 설정",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    460,
    300
   ],
   "parameters": {
    "mode": "manual",
    "includeOtherFields": false,
    "assignments": {
     "assignments": [
      {
       "id": "a1",
       "name": "officeCode",
       "value": "B10",
       "type": "string"
      },
      {
       "id": "a2",
       "name": "schoolCode",
       "value": "7010083",
       "type": "string"
      },
      {
       "id": "a3",
       "name": "schoolName",
       "value": "서울고등학교",
       "type": "string"
      },
      {
       "id": "a4",
       "name": "mealCode",
       "value": "2",
       "type": "string"
      },
      {
       "id": "a5",
       "name": "targetDate",
       "value": "={{ $now.setZone(\"Asia/Seoul\").toFormat(\"yyyyLLdd\") }}",
       "type": "string"
      },
      {
       "id": "a6",
       "name": "slackChannel",
       "value": "YOUR_SLACK_CHANNEL_ID",
       "type": "string"
      }
     ]
    }
   }
  },
  {
   "id": "f0cf1a5c-dc7d-40ff-bb96-8efe158aa2ae",
   "name": "NEIS 급식 조회",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.5,
   "position": [
    680,
    300
   ],
   "parameters": {
    "method": "GET",
    "url": "https://open.neis.go.kr/hub/mealServiceDietInfo",
    "sendQuery": true,
    "specifyQuery": "keypair",
    "queryParameters": {
     "parameters": [
      {
       "name": "Type",
       "value": "json"
      },
      {
       "name": "pIndex",
       "value": "1"
      },
      {
       "name": "pSize",
       "value": "100"
      },
      {
       "name": "ATPT_OFCDC_SC_CODE",
       "value": "={{ $json.officeCode }}"
      },
      {
       "name": "SD_SCHUL_CODE",
       "value": "={{ $json.schoolCode }}"
      },
      {
       "name": "MLSV_YMD",
       "value": "={{ $json.targetDate }}"
      },
      {
       "name": "MLSV_SC_CODE",
       "value": "={{ $json.mealCode }}"
      }
     ]
    },
    "options": {
     "response": {
      "response": {
       "responseFormat": "json",
       "neverError": true
      }
     }
    }
   }
  },
  {
   "id": "230d5424-508a-4843-9a2f-26c006f8f37f",
   "name": "메뉴 포맷",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    900,
    300
   ],
   "parameters": {
    "mode": "runOnceForAllItems",
    "language": "javaScript",
    "jsCode": "const res = items[0] && items[0].json ? items[0].json : {};\nconst cfg = $('급식 조회 설정').first().json;\nconst dateStr = String(cfg.targetDate || '');\nlet rows = [];\nconst info = res.mealServiceDietInfo;\nif (Array.isArray(info)) {\n  const rowBlock = info.find(b => Array.isArray(b.row));\n  rows = rowBlock ? rowBlock.row : [];\n}\nconst y = dateStr.slice(0,4), m = dateStr.slice(4,6), d = dateStr.slice(6,8);\nconst dateLabel = y + '년 ' + m + '월 ' + d + '일';\nconst school = cfg.schoolName || '';\nlet text;\nif (rows.length === 0) {\n  text = '🍚 *' + school + ' 급식 (' + dateLabel + ')*\\n오늘은 등록된 급식이 없습니다. (주말·공휴일이거나 아직 미등록)';\n} else {\n  const blocks = rows.map(r => {\n    const meal = r.MMEAL_SC_NM || '급식';\n    const dishes = String(r.DDISH_NM || '')\n      .replace(/<br\\s*\\/?>/gi, '\\n')\n      .split('\\n')\n      .map(s => s.replace(/\\s*\\([0-9.]+\\)\\s*$/, '').trim())\n      .filter(Boolean)\n      .map(s => '• ' + s)\n      .join('\\n');\n    const cal = r.CAL_INFO ? '\\n_열량: ' + r.CAL_INFO + '_' : '';\n    return '*[' + meal + ']*\\n' + dishes + cal;\n  });\n  text = '🍚 *' + school + ' 급식 (' + dateLabel + ')*\\n\\n' + blocks.join('\\n\\n');\n}\nreturn [{ json: { text: text, dateLabel: dateLabel, mealCount: rows.length, date: dateStr, school: school } }];"
   }
  },
  {
   "id": "ab59b102-f639-4bc7-bd74-d0ea2b58b349",
   "name": "Slack 발송",
   "type": "n8n-nodes-base.slack",
   "typeVersion": 2.6,
   "position": [
    1120,
    300
   ],
   "parameters": {
    "resource": "message",
    "operation": "post",
    "authentication": "accessToken",
    "select": "channel",
    "channelId": {
     "__rl": true,
     "mode": "id",
     "value": "={{ $(\"급식 조회 설정\").first().json.slackChannel }}"
    },
    "messageType": "text",
    "text": "={{ $json.text }}",
    "otherOptions": {
     "includeLinkToWorkflow": false,
     "mrkdwn": true
    }
   }
  }
 ],
 "connections": {
  "매일 07:00 트리거": {
   "main": [
    [
     {
      "node": "급식 조회 설정",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "급식 조회 설정": {
   "main": [
    [
     {
      "node": "NEIS 급식 조회",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "NEIS 급식 조회": {
   "main": [
    [
     {
      "node": "메뉴 포맷",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "메뉴 포맷": {
   "main": [
    [
     {
      "node": "Slack 발송",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1",
  "timezone": "Asia/Seoul"
 }
}