발행일: 2026-10-06(화) 11:44
← 목차로 돌아가기|하루 30분 n8n 시리즈 ② 실무 자동화 레시피 100
RECIPE 024

유튜브 채널 구독자 이정표 달성 → 팀 축하 알림

  • ▸Google Drive Trigger로 특정 폴더에 파일이 추가되는 것을 감지할 수 있다
  • ▸파일 이름 규칙에 따라 자동으로 하위 폴더에 분류할 수 있다
  • ▸파일 이름을 날짜/프로젝트명 기준으로 일관되게 변경할 수 있다

✅사전 준비

  • □Google Drive 자격증명 연결 완료
  • □분류 기준 폴더 구조 생성 및 각 폴더 ID 확인
  • □파일 이름 규칙 정의 (예: YYYYMMDD_프로젝트명_파일종류.확장자)
  • □Schedule Trigger 또는 Drive Trigger 선택

파일 확장자 기반 분류 — Code 노드

const fileName = $json.name ?? '';
const ext = fileName.split('.').pop().toLowerCase();

const folderMap = {
  pdf:  'PDF_FOLDER_ID',
  xlsx: 'EXCEL_FOLDER_ID',
  xls:  'EXCEL_FOLDER_ID',
  jpg:  'IMAGE_FOLDER_ID',
  jpeg: 'IMAGE_FOLDER_ID',
  png:  'IMAGE_FOLDER_ID',
  docx: 'WORD_FOLDER_ID',
  doc:  'WORD_FOLDER_ID',
};

const targetFolderId = folderMap[ext] ?? 'DEFAULT_FOLDER_ID';
return [{ json: { ...$json, targetFolderId, ext } }];

파일 이름 자동 변경 — Code 노드

const original = $json.name ?? '';
const ext = original.split('.').pop();
const base = original.replace(`.${ext}`, '');
const date = new Date().toISOString().slice(0, 10).replace(/-/g, '');

// 이미 날짜 prefix가 있으면 그대로, 없으면 추가
const newName = /^\d{8}_/.test(base)
  ? original
  : `${date}_${original}`;

return [{ json: { ...$json, newName } }];

Google Drive — 파일 이동 설정

Resource:   File
Operation:  Move
File ID:    {{ $json.id }}
Folder ID:  {{ $json.targetFolderId }}
💡 TIPDrive Trigger는 폴링 방식이라 실시간이 아닙니다. 즉시 처리가 필요하다면 Google Apps Script에서 Drive 변경 이벤트를 감지해 n8n Webhook을 호출하는 방식을 쓰세요.
⚡

워크플로우 JSON

아래 JSON을 복사해 n8n에 바로 임포트하세요

📥 n8n 임포트 방법
n8n 화면 우측 상단 메뉴 (⋮) → Import from JSON → 아래 JSON 전체 복사 후 붙여넣기 → Import 클릭
{
  "name": "recipe024_youtube_subscriber_milestone",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 10 * * *"
            }
          ]
        }
      },
      "id": "schedule-024-01",
      "name": "매일 오전 10시",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        200,
        400
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://www.googleapis.com/youtube/v3/channels?part=statistics&id={{ $env.YOUTUBE_CHANNEL_ID }}&key={{ $env.YOUTUBE_API_KEY }}",
        "options": {}
      },
      "id": "http-024-02",
      "name": "유튜브 구독자 수 가져오기",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        420,
        400
      ]
    },
    {
      "parameters": {
        "jsCode": "const stats = $json.items?.[0]?.statistics || {};\nconst subscribers = parseInt(stats.subscriberCount || 0);\nconst milestones = [1000, 5000, 10000, 50000, 100000];\nconst reached = milestones.filter(m => subscribers >= m);\nconst latestMilestone = reached.length > 0 ? Math.max(...reached) : 0;\nreturn [{ json: { subscribers, latestMilestone, isNewMilestone: latestMilestone > 0 } }];"
      },
      "id": "code-024-03",
      "name": "이정표 달성 여부 확인",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        640,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{ $json.isNewMilestone }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ]
        }
      },
      "id": "if-024-04",
      "name": "이정표 달성 여부",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        860,
        400
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "post",
        "channel": "#content-team",
        "text": "=🎉 유튜브 구독자 이정표 달성!\n현재 구독자: {{ $json.subscribers.toLocaleString() }}명\n달성 이정표: {{ $json.latestMilestone.toLocaleString() }}명 돌파!\n축하해주세요! 🥳"
      },
      "id": "slack-024-05",
      "name": "팀 축하 알림",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        1080,
        300
      ]
    }
  ],
  "connections": {
    "매일 오전 10시": {
      "main": [
        [
          {
            "node": "유튜브 구독자 수 가져오기",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "유튜브 구독자 수 가져오기": {
      "main": [
        [
          {
            "node": "이정표 달성 여부 확인",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "이정표 달성 여부 확인": {
      "main": [
        [
          {
            "node": "이정표 달성 여부",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "이정표 달성 여부": {
      "main": [
        [
          {
            "node": "팀 축하 알림",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "settings": {
    "timezone": "Asia/Seoul"
  },
  "meta": {
    "chapter": 2,
    "recipe": "024",
    "title": "유튜브 채널 구독자 이정표 달성 → 팀 축하 알림",
    "difficulty": "⭐",
    "estimatedTime": "20분",
    "apps": [
      "YouTube Data API",
      "Slack"
    ]
  }
}
← 이전 레시피☰ 목차다음 레시피 →