Auto Marketing — Multi-Agent Architecture với n8n
Bài 7/21Thực hành

Bài 7 — Telegram Trigger đa dạng: Text, Voice, Ảnh, Video

Cấu hình Telegram Trigger trên n8n Cloud nhận mọi loại tin nhắn từ marketer.

28 min
Mục tiêu bài học
  • Phân biệt message.type: text, voice, photo, video, document
  • Download file Telegram qua node Telegram Get File
  • Chuẩn hóa payload JSON thống nhất cho Manager Agent
Webhook Production URL — Telegram Trigger trên n8n Cloud tự đăng ký webhook
Publish workflow → gửi text/voice/ảnh tới bot → Executions tab ghi nhậndocs.n8n.io

Tư duy Lớp Nhập liệu (Input Layer)

Mọi hệ Auto Marketing bắt đầu bằng Trigger — "tai nghe" 24/7. Marketer không mở dashboard để nhập liệu; họ gửi qua Telegram: gõ /product, gửi voice mô tả sản phẩm, hoặc chụp ảnh sản phẩm kèm caption.

Các loại input cần xử lý

  • Text — lệnh /product, /generate hoặc mô tả tự do
  • Voice — file .ogg từ Telegram; transcribe bằng OpenAI Whisper node (Bước 2)
  • Photo — ảnh sản phẩm; lưu Drive (Bước 3) + vision AI mô tả sản phẩm
  • Video — clip ngắn Reels/Shorts raw; upload Drive → publish MXH (Bước 4)
  • Document — PDF catalogue; parse text hoặc lưu Drive

Workflow wf-input-normalizer

[Telegram Trigger]
  → [Switch: $json.message] theo loại tin
       text     → [Code: parse /command hoặc free text]
       voice    → [Telegram Get File] → [Set: input_type=voice, file_id=...]
       photo    → [Telegram Get File] → [Set: input_type=photo]
       video    → [Telegram Get File] → [Set: input_type=video]
  → [Set: unified payload]
       { input_type, raw_text, file_id, file_mime, chat_id, user_name }
  → [Execute Workflow: wf-manager-agent]

Code node — detect message type

const msg = $input.first().json.message;
let inputType = 'text';
let rawText = msg.text || '';
let fileId = null;
if (msg.voice) { inputType = 'voice'; fileId = msg.voice.file_id; }
else if (msg.photo) { inputType = 'photo'; fileId = msg.photo.at(-1).file_id; }
else if (msg.video) { inputType = 'video'; fileId = msg.video.file_id; }
else if (msg.document) { inputType = 'document'; fileId = msg.document.file_id; }
return [{ json: { input_type: inputType, raw_text: rawText, file_id: fileId, chat_id: msg.chat.id } }];

Bài tập thực hành

  1. Tạo wf-input-normalizer trên n8n Cloud + Publish
  2. Gửi bot: (1) text /product, (2) ảnh sản phẩm, (3) voice 10 giây
  3. Verify Executions: 3 loại input_type khác nhau trong JSON output
  4. Thêm Telegram reply: "✅ Đã nhận {input_type}"

Tiếp tục lộ trình

Hoàn thành từng bài thực hành để xây hệ Auto Marketing Multi-Agent của riêng bạn.

Bài 7 — Telegram Trigger đa dạng: Text, Voice, Ảnh, Video — Auto Marketing — Multi-Agent Architecture với n8n | Sage Marketing