Cấp độ: intermediate45 phútminMiễn phíFreeBuilder & EntrepreneurBuilder & Entrepreneur

AI Workflow với n8nAI workflow with n8n

Workflow tự động phân loại email với AIAn automated email classification workflow with AI

Bạn sẽ học gìWhat you will learn

  • Tạo workflow cơ bản với n8nCreate basic workflows with n8n
  • Kết nối AI model vào workflowConnect AI model to workflow
  • Xây pipeline xử lý data tự độngBuild automated data processing pipeline

Bạn sẽ tạo gìWhat you will build

Workflow tự động phân loại email với AIAn automated email classification workflow with AI

Nội dung bài họcLesson content

n8n là gì?What is n8n?

n8n là công cụ automation workflow mã nguồn mở. Kéo thả nodes (webhook, HTTP, AI, database, email) thành pipeline. Tự động hóa: khi có email → AI phân loại → lưu database → gửi notification. n8n tự host hoặc dùng cloud n8n.io.n8n is an open-source automation workflow tool. Drag and drop nodes (webhook, HTTP, AI, database, email) into a pipeline. Automate: when email arrives → AI classifies → save to database → send notification. Self-host or use n8n.io cloud.

Workflow: Webhook → AI → DatabaseWorkflow: Webhook → AI → Database

Pipeline điển hình: (1) Webhook node nhận POST request. (2) OpenAI node phân tích nội dung. (3) Postgres/SQLite node lưu kết quả. (4) Email node gửi thông báo. Mỗi node nhận output từ node trước, xử lý, gửi cho node sau.A typical pipeline: (1) Webhook node receives POST request. (2) OpenAI node analyzes content. (3) Postgres/SQLite node saves result. (4) Email node sends notification. Each node takes the previous node's output, processes it, sends to the next.

Webhook node: nhận triggerWebhook node: receiving triggers

Webhook node tạo URL endpoint. Khi có HTTP request đến, workflow chạy. Cấu hình: method (GET/POST), path, auth. Webhook URL: https://your-n8n.com/webhook/abc123. Test bằng curl hoặc Postman. Webhook là điểm bắt đầu phổ biến nhất cho workflow.A Webhook node creates a URL endpoint. When an HTTP request arrives, the workflow runs. Configure: method (GET/POST), path, auth. Webhook URL: https://your-n8n.com/webhook/abc123. Test with curl or Postman. Webhooks are the most common workflow starting point.

bash
                      
                        # Test webhook bằng curl
curl -X POST https://your-n8n.com/webhook/abc123 \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "subject": "Hỏi về sản phẩm",
    "body": "Cho tôi hỏi giá sản phẩm X"
  }'

# Workflow:
# 1. Webhook nhận request
# 2. OpenAI phân loại: "sales inquiry"
# 3. Database lưu: email, category, timestamp
# 4. Email notify: [email protected]
                      
                    

AI node: tích hợp OpenAIAI node: integrating OpenAI

n8n có OpenAI node tích hợp sẵn. Cấu hình: API key, model (gpt-4o-mini), prompt. Input từ node trước (vd: email body). Output là text AI trả về. Dùng cho: phân loại, tóm tắt, trả lời tự động, trích xuất thông tin.n8n has a built-in OpenAI node. Configure: API key, model (gpt-4o-mini), prompt. Input from the previous node (e.g., email body). Output is the AI's text response. Use for: classification, summarization, auto-reply, information extraction.

Bài tập thực hànhHands-on exercises

1Thiết kế workflow n8n: Webhook nhận email → OpenAI phân loại (sales/support/spam) → Database lưu → Email notify team.Design an n8n workflow: Webhook receives email → OpenAI classifies (sales/support/spam) → Database saves → Email notifies team.

Gợi ýHint

4 nodes: Webhook → OpenAI → Postgres → Email. Mỗi node truyền output cho node sau.4 nodes: Webhook → OpenAI → Postgres → Email. Each node passes output to the next.

Lời giảiSolution
text
                      
                        WORKFLOW: Email Classification Pipeline

Node 1: Webhook
- Method: POST
- Path: /classify-email
- Output: { email, subject, body }

Node 2: OpenAI
- Model: gpt-4o-mini
- Prompt: "Phân loại email thành: sales, support, hoặc spam. Trả về 1 từ."
- Input: $json.body
- Output: { category: "sales" }

Node 3: Postgres
- Query: INSERT INTO emails (email, subject, category, created_at) VALUES (?, ?, ?, NOW())
- Parameters: $json.email, $json.subject, $json.category

Node 4: Email (Resend)
- To: [email protected]
- Subject: "Email mới: {{ $json.category }}"
- Body: "{{ $json.email }} - {{ $json.subject }}"
                      
                    

Kiểm traQuiz

Chọn đáp án đúng cho mỗi câu. Nhấn để xem giải thích.Choose the correct answer for each question. Click to see explanation.

Câu 1: n8n là công cụ gì?Q1: What is n8n?

Câu 2: Webhook node trong n8n dùng để làm gì?Q2: What is the Webhook node in n8n used for?

Câu 3: Trong workflow n8n, dữ liệu truyền giữa các node thế nào?Q3: How does data flow between nodes in an n8n workflow?