8
n8n 中文网amn8n.com

MS_TRENDS

中级

这是一个Market Research领域的自动化工作流,包含 10 个节点。主要使用 Xml, Code, Telegram, HttpRequest, TelegramTrigger 等节点。 通过Telegram机器人获取特定国家的Google趋势报告

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "9DnO7e6sTnzOsBor",
  "meta": {
    "instanceId": "c92a0c76586da37fb3ac600956b62e842bfa4bd5f52acc7feb4e8a6e75ca1381",
    "templateCredsSetupCompleted": true
  },
  "name": "MS_TRENDS",
  "tags": [],
  "nodes": [
    {
      "id": "b6c68332-9cd6-4b64-b3a4-57c37e665a2f",
      "name": "HTTP 请求",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        260,
        0
      ],
      "parameters": {
        "url": "https://trends.google.com/trending/rss",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "geo",
              "value": "={{ $json.message.text }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "930f0f7d-94bb-48a7-80f4-3948ff830131",
      "name": "XML",
      "type": "n8n-nodes-base.xml",
      "position": [
        620,
        0
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "88867504-b113-495a-ada0-6d7696482af5",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        980,
        0
      ],
      "parameters": {
        "jsCode": "// 1. Safely access the array of trend items from the input data.\nconst trends = $json.rss?.channel?.item || [];\n\n// If there are no trends, return a friendly message.\nif (trends.length === 0) {\n  return [{\n    json: {\n      text: \"Could not fetch Google Trends data at this time.\"\n    }\n  }];\n}\n\n// 2. Create a dynamic header for the report in Arabic.\nconst today = new Date().toLocaleDateString('ar-EG', {\n  day: 'numeric',\n  month: 'long',\n  year: 'numeric'\n});\nconst header = `🔥 *Trends report for $('Telegram Trigger').first().json.message.text *\\n_${today}_\\n\\n`;\n\n\n// 3. Process the top 5 trend items to create formatted blocks.\nconst trendBlocks = trends\n  .slice(0, 5) // We only want the top 5 trends\n  .map((trend, index) => {\n    // Get the main details for the trend.\n    const rank = index + 1;\n    const title = trend.title;\n    const traffic = trend['ht:approx_traffic'] || 'Not available';\n\n    // Get the top 2 related news articles for this trend.\n    const newsItems = (trend['ht:news_item'] || [])\n      .slice(0, 2) // We only want the top 2 news items\n      .map(news => {\n        const newsTitle = news['ht:news_item_title'];\n        const newsUrl = news['ht:news_item_url'];\n        const newsSource = news['ht:news_item_source'];\n        // Format as: \"• [Article Title](url) - _Source_\"\n        return `• [${newsTitle}](${newsUrl}) - _${newsSource}_`;\n      })\n      .join('\\n');\n\n    // Combine everything into a single block, optimized for RTL.\n    // We put the Arabic title first to help with rendering.\n    return `*${title}* (${rank})\\n📈 *Searches:* ${traffic}\\n🗞️ *Related:*\\n${newsItems}`;\n  })\n  .join('\\n\\n---\\n\\n'); // Join all trend blocks with a separator.\n\n\n// 4. Combine the header and the trend blocks into the final report.\nconst finalReport = header + trendBlocks;\n\n// 5. Wrap the output in the format that n8n expects.\nreturn [{\n  json: {\n    text: finalReport,\n    parse_mode: 'Markdown'\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "c8c768d6-f98b-433c-813e-132d650c4f38",
      "name": "发送短信",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1340,
        0
      ],
      "webhookId": "eb03235e-b383-40e8-885e-a57f35bb30e2",
      "parameters": {
        "text": "={{ $json.text }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "OymlVCuTPYhVa2B9",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1de3838b-87e9-47b2-879f-7e7bcfb1b76d",
      "name": "Telegram 触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -80,
        0
      ],
      "webhookId": "6ac6fdc4-a1bc-4346-bfb1-680036eab304",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "chatIds": "={{ $env.chat_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "OymlVCuTPYhVa2B9",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3ed6b167-1d03-43f4-88f3-2a7bff19716e",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        180,
        -100
      ],
      "parameters": {
        "color": 6,
        "width": 260,
        "height": 280,
        "content": "## 获取趋势"
      },
      "typeVersion": 1
    },
    {
      "id": "c08ee391-6aa5-4daf-83e3-6167ad87e6c3",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        540,
        -100
      ],
      "parameters": {
        "color": 3,
        "width": 260,
        "height": 280,
        "content": "## 转换为 json"
      },
      "typeVersion": 1
    },
    {
      "id": "8f675ed7-2a06-497b-87ea-6e2e9755914d",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        900,
        -100
      ],
      "parameters": {
        "color": 7,
        "width": 260,
        "height": 280,
        "content": "## 准备报告"
      },
      "typeVersion": 1
    },
    {
      "id": "74c4d562-f0dc-4c0a-8a08-1b6d22372f51",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1260,
        -100
      ],
      "parameters": {
        "color": 5,
        "width": 260,
        "height": 280,
        "content": "## 发送报告"
      },
      "typeVersion": 1
    },
    {
      "id": "9419f0f0-ed18-4d48-bc8a-cea1a3efff1b",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -100,
        -160
      ],
      "parameters": {
        "width": 260,
        "height": 120,
        "content": "## 发送国家代码"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "22911120-2f7e-4017-b43d-94636740d997",
  "connections": {
    "XML": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "XML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 市场调研

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量10
分类1
节点类型6
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流