Giới Thiệu

Trong bối cảnh công nghệ AI ngày càng phát triển, việc tự động hóa quy trình tổng hợp và chuyển đổi tin tức trở nên quan trọng đối với người làm nội dung và marketing. Trong bài viết này, chúng ta sẽ tạo workflow sử dụng n8n để:

  • Thu thập tin tức từ VNExpress
  • Tóm tắt bằng Gemi AI
  • Chuyển thành giọng nói bằng Zalo TTS
  • Sẵn sàng dữ liệu để đăng lên các nền tảng như Telegram hoặc Zalo

Yêu Cầu Chuẩn Bị

  • n8n: Cài đặt n8n trên server hoặc local
  • Gemi AI API: Tài khoản và API key
  • Zalo TTS API: Link JSON để request chuyển đổi văn bản thành giọng nói

Code toàn bộ Json tại đây

{
  "name": "Tổng hợp tin tức thành audio",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -220,
        120
      ],
      "id": "e72622c4-95d6-488e-98bc-9c1f9a2a62a5",
      "name": "When clicking ‘Test workflow’"
    },
    {
      "parameters": {
        "url": "https://vnexpress.net/rss/khoa-hoc.rss",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        120,
        220
      ],
      "id": "5bceef19-f36c-42a4-a2ba-93299a862093",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.xml",
      "typeVersion": 1,
      "position": [
        320,
        220
      ],
      "id": "b9d6e1a5-c3ec-4625-8d0f-0b6348aa8929",
      "name": "XML"
    },
    {
      "parameters": {
        "fieldToSplitOut": "rss.channel.item",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        500,
        220
      ],
      "id": "5a39ab0a-20fd-4a58-8790-d4d43f7a92b5",
      "name": "Split Out"
    },
    {
      "parameters": {
        "maxItems": 10
      },
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        360,
        20
      ],
      "id": "be36da39-bef5-4881-9aa3-de4aaf5a823d",
      "name": "Limit"
    },
    {
      "parameters": {
        "url": "={{ $json.link }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        620,
        20
      ],
      "id": "fc6e9a2c-91c8-494e-91db-d9a9b36939b1",
      "name": "HTTP Request1"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "data",
              "cssSelector": "p.Normal",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        840,
        20
      ],
      "id": "17776304-e249-4a51-8bbc-5a1d5f455a06",
      "name": "HTML"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "3ec2e23f-9b6c-4379-b4b5-2b98af1d6aa7",
              "name": "data",
              "value": "={{ $json.data }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1040,
        20
      ],
      "id": "1d9d2ff9-4945-4f80-aa55-c16063363b5c",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Tôi có một bài báo này. Hãy tóm tắt bài báo trong 5-7 câu với ngôn ngữ tự nhiên hết sức có thể, giọng văn đời thường. Ngoài tóm tắt ra, không nói gì thêm!\n {{ $json.data }}",
        "hasOutputParser": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        1020,
        260
      ],
      "id": "bd2a141a-0ac0-4516-9cd3-89983c0ef324",
      "name": "AI Agent",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "modelName": "models/gemini-2.0-flash-001",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        1020,
        440
      ],
      "id": "afb6d56b-5b82-43fb-ba02-1805db79a6a7",
      "name": "Google Gemini Chat Model",
      "credentials": {
        "googlePalmApi": {
          "id": "9y1Hs7W3mKVqHW0J",
          "name": "Google Gemini(PaLM) Api account"
        }
      }
    },
    {
      "parameters": {
        "chatId": "484621843",
        "text": "=<b>Tin mới: {{ $('Limit').item.json.title }}</b>\n\n<i>{{ $json.data.url }}</i>\n\nChi tiết: {{ $('Limit').item.json.link }}",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1720,
        180
      ],
      "id": "85d8f793-9a75-4a25-8c55-561076d953a9",
      "name": "Telegram",
      "webhookId": "06d6847b-7135-462e-87d9-ba067d1982c6",
      "credentials": {
        "telegramApi": {
          "id": "P2tatm0Zyo452Fy8",
          "name": "PhoAiAudioMeetingBot"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -80,
        220
      ],
      "id": "8039cdc6-a8b8-41ef-b680-f14086278dd7",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "url": "https://vnexpress.net/rss/cong-nghe.rss",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        120,
        20
      ],
      "id": "1d21f5da-e500-443d-bf6b-5fada36e070f",
      "name": "HTTP Request2"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "triggerAtMinute": 1
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -80,
        20
      ],
      "id": "0d7e5769-cfb3-42e0-9f89-77279f483c58",
      "name": "Schedule Trigger1"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "ec829a04-50aa-497c-87c1-3e6ef34a92ed",
              "leftValue": "={{ $json.pubDate }}",
              "rightValue": "={{ $now.minus({ hours: 1 }) }}",
              "operator": {
                "type": "dateTime",
                "operation": "after"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        680,
        220
      ],
      "id": "f5fd2dd5-744b-47f5-aaab-5b92d1c6946c",
      "name": "If"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.zalo.ai/v1/tts/synthesize",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey"
            }
          ]
        },
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "input",
              "value": "={{ $json.chatInput }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1420,
        20
      ],
      "id": "d8dc3a58-d44d-4c4c-9967-189d83a5fa86",
      "name": "HTTP Request3"
    },
    {
      "parameters": {
        "rate": "1.1",
        "text": "={{ $json.output }}",
        "requestOptions": {}
      },
      "type": "CUSTOM.ZaloTTS",
      "typeVersion": 1,
      "position": [
        1420,
        380
      ],
      "id": "3cda2cb2-ca04-4bc5-9480-198fdfdff47f",
      "name": "ZaloTTS",
      "credentials": {
        "zaloTTSApi": {
          "id": "GnI9DX3PH4H99FqR",
          "name": "ZaloTTS accountProd"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "XML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "XML": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "HTTP Request3",
            "type": "main",
            "index": 0
          },
          {
            "node": "ZaloTTS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request2": {
      "main": [
        [
          {
            "node": "XML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram": {
      "main": [
        []
      ]
    },
    "HTTP Request3": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ZaloTTS": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a66b8f89-7495-427e-b54c-508972d4d009",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "558d88703fb65b2d0e44613bc35916258b0f0bf983c5d4730c00c424b77ca36a"
  },
  "id": "Z2beUIzxKE9ul07l",
  "tags": []
}

Xây Dựng Workflow

1. Thu Thập Tin Tức Từ VNExpress

Dùng node HTTP Request trong n8n để lấy tin tức từ API hoặc parse HTML từ trang VNExpress:

  • Method: GET
  • URL: https://vnexpress.net/rss/tin-moi-nhat.rss
  • Output: Dữ liệu dạng XML hoặc JSON
  • Xử lý dữ liệu: Dùng node “RSS Extractor” hoặc “Function” để chuyển đổi dữ liệu thành danh sách bài viết

2. Tóm Tắt Bài Viết Bằng Gemi AI

Sau khi có danh sách bài viết, ta dùng node HTTP Request để gửi nội dung bài viết đến Gemi AI nhờ tóm tắt:

  • Method: POST
  • URL: API Gemi AI
  • Headers: Authorization (API Key), Content-Type: application/json
  • Body:
{
  "text": "Nội dung bài viết cần tóm tắt",
  "length": "short"
}
  • Output: Nhận văn bản tóm tắt từ Gemi AI

3. Chuyển Đổi Văn Bản Thành Giọng Nói (Zalo TTS)

Tiếp theo, ta sử dụng HTTP Request để request sang Zalo TTS API:

  • Method: POST
  • URL: Link JSON Zalo TTS API
  • Headers: Content-Type: application/json
  • Body:
{
  "text": "Văn bản tóm tắt",
  "voice": "female",
  "speed": 1.0
}
  • Output: File audio hoặc link MP3

4. Lưu Kết Quả Hoặc Gửi Tự Động

Cuối cùng, có thể:

  • Lưu audio và bài viết tóm tắt vào database
  • Gửi tin nhắn hoặc tải file MP3 lên Telegram/Zalo

Kết Luận

Workflow trên giúp tự động hóa quy trình lấy tin tức, tóm tắt và chuyển đổi thành giọng nói một cách hiệu quả. Nó có thể ứng dụng trong việc làm tin tức tự động hoặc tạo podcast nhanh chóng.

Categorized in:

Templates N8N,