RECIPE 041
이메일 문의 → 티켓 자동 생성 & 담당자 배정
- ▸Gmail Trigger로 수신 이메일을 자동으로 감지할 수 있다
- ▸OpenAI로 이메일 내용을 분석해 카테고리와 우선순위를 자동 태깅할 수 있다
- ▸분류 결과를 Gmail 레이블과 Sheets에 동시에 반영할 수 있다
✅사전 준비
- □Gmail 자격증명 연결 완료
- □OpenAI API 자격증명 연결 완료
- □Gmail에 분류 레이블 생성 (긴급/일반/뉴스레터/광고/스팸의심)
- □Google Sheets에 분류 이력 저장용 시트 생성
이메일 분류 — OpenAI 프롬프트
Model: gpt-4o-mini
System: 너는 이메일 분류 전문가야. 반드시 JSON만 응답해.
User:
다음 이메일을 분석해서 아래 JSON 형식으로만 응답해.
{
"category": "긴급|일반|뉴스레터|광고|스팸의심",
"priority": "high|medium|low",
"summary": "한 줄 요약",
"action_required": true또는false
}
발신자: {{ $json.from }}
제목: {{ $json.subject }}
본문(앞 500자): {{ $json.text?.slice(0, 500) }}분류 결과 파싱 — Code 노드
const raw = $input.first().json.message.content;
const cleaned = raw.replace(/```json|```/g, '').trim();
const result = JSON.parse(cleaned);
return [{ json: {
...result,
emailId: $('Gmail Trigger').first().json.id,
subject: $('Gmail Trigger').first().json.subject,
from: $('Gmail Trigger').first().json.from,
receivedAt: new Date().toISOString(),
} }];Gmail 레이블 적용 — Gmail 노드
Resource: Message
Operation: Add Label
Message ID: {{ $json.emailId }}
Label: {{ $json.category }} (Gmail에 미리 만들어둔 레이블명과 일치해야 함)💡 TIPGmail 레이블 ID는 이름이 아닌 고유 ID가 필요합니다. Gmail 노드의 'Get Labels' 작업으로 먼저 레이블 목록을 조회해 이름-ID 매핑을 만들어두세요.
⚡
워크플로우 JSON
아래 JSON을 복사해 n8n에 바로 임포트하세요
📥 n8n 임포트 방법
n8n 화면 우측 상단 메뉴 (⋮) → Import from JSON → 아래 JSON 전체 복사 후 붙여넣기 → Import 클릭
n8n 화면 우측 상단 메뉴 (⋮) → Import from JSON → 아래 JSON 전체 복사 후 붙여넣기 → Import 클릭
{
"recipeId": "recipe041",
"title": "이메일 문의 → 티켓 자동 생성 & 담당자 배정",
"chapter": 4,
"category": "고객 응대 자동화",
"difficulty": "⭐⭐",
"estimatedTime": "35분",
"description": "고객 응대 전용 이메일에 새 메일이 오면 OpenAI로 문의 유형을 분류하고 Zendesk 티켓을 자동 생성하여 담당 팀에 Slack 알림을 보냅니다.",
"apps": [
"Gmail",
"OpenAI",
"Zendesk",
"Slack"
],
"nodes": [
{
"id": "trigger_gmail",
"type": "trigger",
"name": "Gmail Trigger - 고객 문의 이메일 감지",
"service": "gmail",
"config": {
"event": "newEmail",
"filter": {
"to": "{{ $env.SUPPORT_EMAIL }}"
}
}
},
{
"id": "openai_classify",
"type": "action",
"name": "OpenAI - 문의 유형 분류",
"service": "openai",
"config": {
"model": "gpt-4o-mini",
"prompt": "다음 이메일 내용을 분석해서 문의 유형을 '배송 문의', '환불 요청', '기술 지원', '기타' 중 하나로만 답해줘.\n\n이메일: {{ $json[\"text\"] }}"
}
},
{
"id": "zendesk_ticket",
"type": "action",
"name": "Zendesk - 티켓 자동 생성",
"service": "zendesk",
"config": {
"operation": "createTicket",
"subject": "={{ $json[\"subject\"] }}",
"description": "={{ $json[\"text\"] }}",
"requesterEmail": "={{ $json[\"from\"] }}",
"tags": [
"={{ $json[\"category\"] }}"
]
}
},
{
"id": "if_category",
"type": "condition",
"name": "문의 유형 분기",
"config": {
"conditions": [
{
"field": "={{ $json[\"category\"] }}",
"operator": "equals",
"value": "기술 지원"
}
]
}
},
{
"id": "slack_tech",
"type": "action",
"name": "Slack - 기술팀 알림",
"service": "slack",
"config": {
"channel": "={{ $env.SLACK_TECH_CHANNEL }}",
"message": "🎫 새 티켓 배정됨! [기술 지원]\n발신: {{ $json[\"from\"] }}\n제목: {{ $json[\"subject\"] }}\n→ Zendesk에서 확인하세요."
}
},
{
"id": "slack_cs",
"type": "action",
"name": "Slack - CS팀 알림",
"service": "slack",
"config": {
"channel": "={{ $env.SLACK_CS_CHANNEL }}",
"message": "🎫 새 티켓 배정됨! [{{ $json[\"category\"] }}]\n발신: {{ $json[\"from\"] }}\n제목: {{ $json[\"subject\"] }}\n→ Zendesk에서 확인하세요."
}
}
],
"connections": [
{
"from": "trigger_gmail",
"to": "openai_classify"
},
{
"from": "openai_classify",
"to": "zendesk_ticket"
},
{
"from": "zendesk_ticket",
"to": "if_category"
},
{
"from": "if_category",
"to": "slack_tech",
"branch": "true"
},
{
"from": "if_category",
"to": "slack_cs",
"branch": "false"
}
],
"envVars": [
{
"key": "SUPPORT_EMAIL",
"description": "고객 응대 전용 이메일 주소"
},
{
"key": "SLACK_TECH_CHANNEL",
"description": "기술팀 Slack 채널 ID"
},
{
"key": "SLACK_CS_CHANNEL",
"description": "CS팀 Slack 채널 ID"
}
],
"qrCodeUrl": "https://www.koreaaitimes.com/books/n8n-vol2/recipe041"
}