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

광고 리드 폼 → CRM 자동 등록 + 담당자 배정

  • ▸Google Sheets에서 특정 컬럼 기준으로 중복 행을 탐지할 수 있다
  • ▸중복 행을 자동으로 제거하고 원본 시트를 업데이트할 수 있다
  • ▸제거된 중복 데이터를 별도 시트에 아카이빙할 수 있다

✅사전 준비

  • □Google Sheets 자격증명 연결 완료
  • □중복 제거 기준 컬럼 확정 (예: 이메일, 주문번호)
  • □Sheets에 '아카이브' 시트 생성
  • □Schedule Trigger: 매일 자정 (Cron: 0 0 * * *)

중복 탐지 및 분리 — Code 노드

const items = $input.all().map(i => i.json);
const seen = new Map();
const unique = [];
const duplicates = [];

items.forEach(item => {
  const key = item['이메일']; // 중복 기준 컬럼
  if (seen.has(key)) {
    duplicates.push(item);
  } else {
    seen.set(key, true);
    unique.push(item);
  }
});

return [
  ...unique.map(j => ({ json: { ...j, _type: 'unique' } })),
  ...duplicates.map(j => ({ json: { ...j, _type: 'duplicate' } })),
];

원본 시트 전체 교체 — Sheets 설정

중복 제거 후 원본 시트 업데이트 방법:
1. Sheets 노드: Operation → Clear
   → 기존 데이터 전체 삭제
2. Sheets 노드: Operation → Append
   → unique 데이터만 다시 쓰기

※ 헤더 행은 삭제되지 않도록 범위를 A2:Z 로 지정
💡 TIP데이터가 많을 경우 Clear 후 재작성보다 행 번호를 추적해 Delete Row를 개별 호출하는 방식이 더 안전합니다. 하지만 API 호출이 많아지므로 SplitInBatches와 함께 쓰세요.
⚡

워크플로우 JSON

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

📥 n8n 임포트 방법
n8n 화면 우측 상단 메뉴 (⋮) → Import from JSON → 아래 JSON 전체 복사 후 붙여넣기 → Import 클릭
{
  "recipeId": "recipe026",
  "title": "광고 리드 폼 → CRM 자동 등록 + 담당자 배정",
  "chapter": 3,
  "category": "영업 & 리드 관리 자동화",
  "difficulty": "⭐⭐",
  "estimatedTime": "35분",
  "description": "Facebook Lead Ads 리드 폼 제출 시 HubSpot에 Contact와 Deal을 자동 생성하고, 지역·업종 조건에 따라 담당 영업사원 Slack DM으로 즉시 알림을 보냅니다.",
  "apps": [
    "Facebook Lead Ads",
    "HubSpot",
    "Slack"
  ],
  "nodes": [
    {
      "id": "trigger_fb_lead",
      "type": "trigger",
      "name": "Facebook Lead Ads Trigger",
      "service": "facebookLeadAds",
      "config": {
        "event": "newLead"
      }
    },
    {
      "id": "hubspot_create",
      "type": "action",
      "name": "HubSpot Contact & Deal 생성",
      "service": "hubspot",
      "config": {
        "operation": "upsert",
        "contactFields": {
          "firstname": "={{ $json[\"first_name\"] }}",
          "lastname": "={{ $json[\"last_name\"] }}",
          "email": "={{ $json[\"email\"] }}",
          "phone": "={{ $json[\"phone_number\"] }}",
          "company": "={{ $json[\"company_name\"] }}"
        },
        "dealFields": {
          "dealname": "={{ $json[\"company_name\"] }} - 신규 리드",
          "pipeline": "default",
          "dealstage": "appointmentscheduled",
          "lead_source": "={{ $json[\"ad_name\"] }}"
        }
      }
    },
    {
      "id": "if_region",
      "type": "condition",
      "name": "지역 조건 분기",
      "config": {
        "conditions": [
          {
            "field": "={{ $json[\"region\"] }}",
            "operator": "contains",
            "value": "서울|경기|인천"
          }
        ]
      }
    },
    {
      "id": "slack_team_a",
      "type": "action",
      "name": "Slack - A팀 담당자 알림",
      "service": "slack",
      "config": {
        "channel": "={{ $env.SLACK_TEAM_A_DM }}",
        "message": "🔔 새 리드 배정됨!\n이름: {{ $json[\"first_name\"] }} {{ $json[\"last_name\"] }}\n회사: {{ $json[\"company_name\"] }}\n연락처: {{ $json[\"phone_number\"] }}\n광고: {{ $json[\"ad_name\"] }}\n→ 지금 바로 연락해보세요!"
      }
    },
    {
      "id": "slack_team_b",
      "type": "action",
      "name": "Slack - B팀 담당자 알림",
      "service": "slack",
      "config": {
        "channel": "={{ $env.SLACK_TEAM_B_DM }}",
        "message": "🔔 새 리드 배정됨!\n이름: {{ $json[\"first_name\"] }} {{ $json[\"last_name\"] }}\n회사: {{ $json[\"company_name\"] }}\n연락처: {{ $json[\"phone_number\"] }}\n광고: {{ $json[\"ad_name\"] }}\n→ 지금 바로 연락해보세요!"
      }
    }
  ],
  "connections": [
    {
      "from": "trigger_fb_lead",
      "to": "hubspot_create"
    },
    {
      "from": "hubspot_create",
      "to": "if_region"
    },
    {
      "from": "if_region",
      "to": "slack_team_a",
      "branch": "true"
    },
    {
      "from": "if_region",
      "to": "slack_team_b",
      "branch": "false"
    }
  ],
  "envVars": [
    {
      "key": "SLACK_TEAM_A_DM",
      "description": "서울·경기·인천 담당 영업사원 Slack DM 채널 ID"
    },
    {
      "key": "SLACK_TEAM_B_DM",
      "description": "지방 담당 영업사원 Slack DM 채널 ID"
    }
  ],
  "qrCodeUrl": "https://www.koreaaitimes.com/books/n8n-vol2/recipe026"
}
← 이전 레시피☰ 목차다음 레시피 →