Minh họa workflow n8n trợ lý AI đa kênh với vector store và xử lý giọng nói

n8n Workflow: Trợ lý AI đa kênh với Vector Store và Voice Processing






n8n Workflow: Trợ lý AI đa kênh (Telegram + Voice + Vector Store)


🤖 n8n Workflow: Trợ lý AI đa kênh với Vector Store và Redis Memory

📅 Cập nhật: 02/04/2026
🏢 Use case: Multi-channel AI Assistant
🛡️ Public-safe: đã ẩn credentials

1) Tổng quan workflow

Workflow Supper AI Telegram là một trợ lý AI thông minh với khả năng:

  • Nhận input từ 4 kênh: Telegram (text + voice), Webhook HTTP, Chat Widget
  • Xử lý voice message bằng Google Gemini Transcription
  • AI Agent với tool thinking bắt buộc (phân tích → lập kế hoạch → thực thi)
  • Tra cứu thông tin từ Google Sheets (cài đặt phần mềm MDT)
  • Tìm kiếm kiến thức từ Qdrant Vector Store
  • Redis Memory để nhớ context hội thoại (50 messages)
  • Trả lời dạng text HTML hoặc audio voice (OpenAI TTS)
  • Gửi email tự động qua workflow con
Điểm nổi bật: Workflow này minh họa kiến trúc AI Agent production-ready với multi-channel input, tool orchestration, và memory management.

2) Sơ đồ luồng xử lý


📱 Telegram Trigger (text/voice)
📞 Webhook (API external)
💬 Chat Widget (web embed)
   ↓
🔀 Merge 4 nguồn → chuẩn hóa format
   ↓
🔀 Switch: phân biệt voice vs text
   ├─ Voice: download → Gemini transcribe → text
   └─ Text: normalize message
   ↓
🤖 Supper AI Agent (LangChain)
   ├─ Tool: Think (bắt buộc gọi đầu tiên)
   ├─ Tool: MDT Google Sheets (tra cứu phần mềm)
   ├─ Tool: Vector Store (RAG kiến thức)
   ├─ Tool: Send Mail Automation (workflow con)
   └─ Memory: Redis Chat (context 50 msg)
   ↓
🔀 Phân biệt output channel
   ├─ Webhook → JSON response
   ├─ Telegram text → HTML format → send message
   └─ Telegram voice → TTS audio → send audio file
      

3) Tính năng nổi bật

3.1 Multi-channel input

Workflow nhận input từ 4 nguồn khác nhau, chuẩn hóa thành cấu trúc chung:

  • Telegram Trigger: text message + voice message
  • Webhook 1: HTTP POST (external API)
  • Webhook 2: ElevenLabs integration
  • Chat Widget: n8n public chat widget

3.2 Voice Processing Pipeline

  1. Download file voice từ Telegram (binary)
  2. Gửi sang Google Gemini 2.5 Flash để transcribe
  3. Convert thành text để AI Agent xử lý
  4. Trả lời bằng audio (OpenAI TTS voice “onyx”)

3.3 AI Agent với Tool Thinking

System prompt bắt buộc AI phải:

LUẬT SỐ 1: Gọi tool `think` TRƯỚC TIÊN
Bước 1 → Think: "Yêu cầu: [X]. Kế hoạch: [1,2,3...]"
Bước 2 → Thực thi theo kế hoạch
Bước 3 → Trả lời ngắn gọn, chỉ kết quả (không kế hoạch)

3.4 RAG với Vector Store

  • Vector DB: Qdrant (collection: my_knowledge_base)
  • Embedding: OpenAI Embeddings
  • Top K: 10 documents
  • LLM cho summarization: GPT-5.4-nano

3.5 Redis Memory

Session key: message_id + chat_id → context window 50 messages → AI nhớ cuộc hội thoại dài.

4) Giải thích node-by-node

Node Loại Vai trò
Telegram Trigger Trigger Nhận message từ Telegram bot
Webhook / Webhook1 / Chat Widget Trigger Nhận từ HTTP API hoặc widget
Merge (4 inputs) Logic Gộp 4 nguồn input thành 1 flow
Switch (voice/text) Logic Rẽ nhánh voice vs text message
download file voice HTTP Download audio binary từ Telegram
Transcribe a recording AI Google Gemini 2.5 Flash transcribe voice→text
Edit Fields (chat/voice/webhook/widget) Transform Chuẩn hóa format message
Supper AI Agent AI Agent Core LangChain agent với tools + memory
OpenAI Chat Model (GPT-5-nano) LLM Model chính cho AI Agent
Redis Chat Memory Memory Lưu context hội thoại (50 msg)
Think Tool Tool Tool bắt buộc gọi đầu tiên (planning)
Tool-MDT (Google Sheets) Tool Tra cứu phần mềm trong sheet MDT
Answer with Vector Store Tool RAG search trong Qdrant
Call Send Mail Automation Tool Gọi workflow con để gửi email
Phân biệt (output switch) Logic Rẽ theo channel (webhook/telegram/widget)
If (text or voice reply) Logic Kiểm tra input ban đầu là text hay voice
Message a model2 (HTML format) AI Convert output sang HTML Telegram-safe
Send a text message HTTP Gửi text HTML sang Telegram
Message a model3 (summarize) AI Tóm tắt ngắn gọn cho audio TTS
Generate audio (OpenAI TTS) AI Text-to-speech voice “onyx”
Send an audio file HTTP Gửi audio file về Telegram
Respond to Webhook / Webhook1 HTTP Trả JSON response cho webhook

5) Các AI Tools tích hợp

5.1 Tool: Think (mandatory first call)

Description:
"BƯỚC ĐẦU TIÊN BẮT BUỘC - Gọi tool này trước mọi tool khác.
Nhiệm vụ: Phân tích yêu cầu → chọn đúng tool → thực thi ít bước nhất.

PHÂN LOẠI YÊU CẦU:
- Có từ 'cài đặt', 'silent', 'MDT' → dùng Tool-MDT
- Còn lại (câu hỏi kỹ thuật...) → dùng Vector Store
- Gửi mail → dùng Send Mail

Input bắt buộc: 'Yêu cầu: [X] → Tool: [Y] → Lý do: [Z]'"

5.2 Tool: MDT (Google Sheets)

  • Sheet: Data_MinhThoai / tab MDT
  • Dữ liệu: Tên phần mềm, lệnh cài đặt, lệnh gỡ, CMD, ghi chú
  • Use case: IT support tra cứu silent install commands

5.3 Tool: Vector Store (RAG)

- Tìm kiếm và tóm tắt câu trả lời
- Trả lời súc tích vào thẳng vấn đề
- Top 10 documents
- Backend: Qdrant + OpenAI Embeddings

5.4 Tool: Send Mail Automation

Gọi workflow con (ID: <WORKFLOW_ID>) với input chatInput và sessionId.

6) Hướng dẫn setup

6.1 Requirements

  • n8n instance (self-hosted hoặc cloud)
  • Telegram Bot Token (via BotFather)
  • OpenAI API Key (GPT-5-nano + TTS)
  • Google Gemini API Key (transcription)
  • Google Sheets OAuth (cho Tool-MDT)
  • Qdrant instance (vector store)
  • Redis instance (chat memory)

6.2 Credentials cần setup

Service Credential Type Scope
Telegram Bot Token Send/receive messages, files
OpenAI API Key GPT-5-nano, TTS, Embeddings
Google Gemini API Key Audio transcription
Google Sheets OAuth2 Read specific spreadsheet
Qdrant API Key + URL Vector search
Redis Host + Port (+ password) Chat memory

6.3 Bước deploy

  1. Import workflow JSON vào n8n
  2. Cấu hình credentials cho 6 services trên
  3. Tạo Google Sheet với cấu trúc MDT (nếu dùng Tool-MDT)
  4. Tạo Qdrant collection my_knowledge_base và ingest documents
  5. Test webhook URL: https://<n8n-domain>/webhook/<UUID>
  6. Active workflow và test qua Telegram bot

6.4 Test flow

# Test text message
Telegram: "lệnh cài đặt Chrome"
→ AI gọi Think → gọi Tool-MDT → trả lệnh silent install

# Test voice message
Telegram: [gửi voice note]
→ Download → Gemini transcribe → AI agent xử lý
→ Summarize → TTS → gửi audio reply

# Test webhook
curl -X POST https://n8n-domain/webhook/UUID \
  -H "Content-Type: application/json" \
  -d '{"chatInput": "giải thích LDAP"}'
→ AI gọi Vector Store → trả JSON response
Lưu ý bảo mật: Bài viết đã loại bỏ toàn bộ credential IDs, webhook URLs nội bộ, Google Sheet IDs thật, và thông tin nhạy cảm khác. Khi triển khai thực tế, hãy bảo vệ các endpoint và credentials theo best practices.


Để lại một bình luận

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *