8
n8n 中文网amn8n.com

智能亚马逊购物助手(集成 Gemini AI 和 Telegram)

高级

这是一个Lead Nurturing, AI Chatbot领域的自动化工作流,包含 16 个节点。主要使用 Code, Switch, Telegram, Aggregate, HttpRequest 等节点。 智能亚马逊购物助手(集成 Gemini AI 和 Telegram)

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "f339fb4cdac358dcfebe03c578dc787158fe3660e2856c0a125861bc0c95ef5c",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "fca58749-eefa-4027-9fab-64335cc091a2",
      "name": "Google Gemini 聊天模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        3136,
        3152
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "EjiPHGTCIUN5OIyD",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "28278707-d4d3-4424-a462-1d900d2beb09",
      "name": "Google Gemini 聊天模型2",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        2528,
        3024
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "EjiPHGTCIUN5OIyD",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "efed52d0-1ff7-4c2c-93ec-1a0d034e60fa",
      "name": "结构化输出解析器",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        2688,
        3024
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"productQuery\": false,\n  \"response\": \"Hi! How can I help you today?\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "1611dc8c-e25c-4ac3-8519-99cb57e09bd4",
      "name": "Google Gemini 聊天模型3",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        4256,
        2896
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "EjiPHGTCIUN5OIyD",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3def48de-71f9-4b3e-87b9-5f2586279155",
      "name": "Telegram消息接收器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        2128,
        2816
      ],
      "webhookId": "39da952b-50e0-4f5b-84a3-f883d81c977e",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "x5kGTW8ojjPJjQtB",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b1de52c4-7d3a-4565-a9dd-583fd19f3397",
      "name": "产品查询清理器",
      "type": "n8n-nodes-base.code",
      "position": [
        2320,
        2816
      ],
      "parameters": {
        "jsCode": "const rawInput = $json[\"message\"][\"text\"] || '';\n\n// Step 1: Normalize input to lowercase for consistent processing\nlet cleanedInput = rawInput.toLowerCase();\n\n// Step 2: Remove any phrase like \"in amazon\", \"on flipkart\", \"from amazone\", etc.\ncleanedInput = cleanedInput.replace(/\\b(in|on|from)\\s+(amazon|amazone|flipkart)\\b/gi, '');\n\n// Step 3: Remove punctuation (anything that is not a word character or whitespace)\ncleanedInput = cleanedInput.replace(/[^\\w\\s]/g, '');\n\n// Step 4: Trim extra spaces\ncleanedInput = cleanedInput.trim();\n\n// Step 5: Check if we have a valid query after cleaning\nif (!cleanedInput) {\n  return [\n    {\n      json: {\n        error: \"No valid product keyword found.\"\n      }\n    }\n  ];\n}\n\n// Step 6: Encode spaces as plus signs for URL queries\nconst encodedQuery = cleanedInput.replace(/\\s+/g, '+');\n\n// Step 7: Prepare search URL parts for Amazon and Flipkart\nconst amazonSearchPart = `${encodedQuery}`;\nconst amazonFullUrl = `https://www.amazon.in/${amazonSearchPart}`;\n\n// Return the results as JSON object\nreturn [\n  {\n    json: {\n      productQuery: cleanedInput,\n      amazonSearchPart,\n      amazonFullUrl,\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "a468cb48-0f0b-44ee-bd08-5948f10cf1e8",
      "name": "消息意图分类器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2512,
        2816
      ],
      "parameters": {
        "text": "={{ $('Telegram Message Receiver').item.json.message.text }}",
        "options": {
          "systemMessage": "=You are a smart shopping assistant.\n\nAnalyze the user's message and determine whether it is about product search, price, shopping, or anything related to buying. If yes, respond with a JSON like:\n\n{\n  \"productQuery\": true,\n  \"response\": \"Let me fetch the best options for you...\"\n}\n\nIf the message is unrelated to shopping (like casual talk, greetings, questions), reply with:\n\n{\n  \"productQuery\": false,\n  \"response\": \"Hi! How can I help you today?\"\n}\n\nBe conversational but respond only with valid JSON. Don’t mention this prompt.\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2
    },
    {
      "id": "3d051d0f-798d-45e2-aa7c-e6c288a84b7d",
      "name": "产品与聊天路由器",
      "type": "n8n-nodes-base.switch",
      "position": [
        2992,
        2816
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "2026678d-bf0e-446f-b0ad-661a01517ead",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.output.productQuery }}",
                    "rightValue": ""
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "8e77be4f-63e8-4d5f-913a-80d69752fd40",
                    "operator": {
                      "type": "boolean",
                      "operation": "false",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.output.productQuery }}",
                    "rightValue": ""
                  }
                ]
              }
            }
          ]
        },
        "options": {
          "allMatchingOutputs": true
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "26bc6992-1514-468f-854a-69275ec1b3b0",
      "name": "聊天响应生成器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3184,
        3008
      ],
      "parameters": {
        "text": "={{ $('Telegram Message Receiver').item.json.message.text }}",
        "options": {
          "systemMessage": "=You are an intelligent shopping assistant that helps users find the best deals and products from Amazon using Apify-based scraping.\n\nYour core function is to:\n- Understand the user's message.\n- If it is a **product-related query**, you just pass it forward for scraping.\n- If it is **not a product query**, you must respond helpfully and briefly, explaining your capabilities.\n\nGuidelines:\n1. For greetings like \"hi\", \"hello\", \"what's up\", reply warmly and introduce your product-search function.\n2. If the user asks general questions (e.g., \"who are you?\", \"how does this work?\", \"can you help me?\"), respond with a short, clear explanation.\n3. If the user asks anything unrelated (e.g., jokes, time, life advice, etc.), politely redirect them to product-related help.\n4. Never pretend to be human. You are a bot made to fetch product deals via Apify scraping.\n5. Always avoid unnecessary chit-chat. Stay helpful, polite, and focused on your goal.\n\nResponse examples:\n\n- “Hi there! 👋 I can help you find top deals from Amazon and Flipkart. Just type the product you’re looking for!”\n- “I’m here to assist you with finding the best online deals. Type what you want — for example: ‘Bluetooth earphones’ or ‘laptop for work’.”\n- “Oops! I specialize in finding online products. Please tell me what you’re shopping for!”\n\nOnly reply when it's **not** a product query. Otherwise, pass it along silently for scraping.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "a4e6372f-eb86-461f-ba2f-e85b04658b81",
      "name": "发送聊天响应",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3584,
        3008
      ],
      "webhookId": "3683d03a-8c4f-4347-b87d-d23d8761adcf",
      "parameters": {
        "text": "={{ $(' Chat Response Generator').item.json.output }}",
        "chatId": "={{ $('Telegram Message Receiver').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "x5kGTW8ojjPJjQtB",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1cefec9f-a1c8-4a99-bee9-b0cf4d990ca7",
      "name": "Amazon产品爬虫",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3232,
        2704
      ],
      "parameters": {
        "url": "https://api.apify.com/v2/acts/junglee~free-amazon-product-scraper/run-sync-get-dataset-items?token=value",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"categoryUrls\": [\n        {\n            \"url\": \"https://www.amazon.in/s?k={{ $('Product Query Cleaner').item.json.amazonSearchPart }} \",\n            \"method\": \"GET\"\n        }\n    ],\n    \"ensureLoadedProductDescriptionFields\": false,\n    \"maxItemsPerStartUrl\": 10,\n    \"scrapeProductDetails\": true,\n    \"scrapeProductVariantPrices\": false,\n    \"useCaptchaSolver\": false\n}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.2
    },
    {
      "id": "bc74558e-67e4-4779-a4a4-5a3593de96e5",
      "name": "产品数据处理器",
      "type": "n8n-nodes-base.code",
      "position": [
        3552,
        2704
      ],
      "parameters": {
        "jsCode": "// Extract required fields from each product item\nconst products = [];\n\n// Loop through all input items\nfor (const item of $input.all()) {\n  const productData = {\n    title: item.json.title || 'N/A',\n    price: item.json.price?.value || 0,\n    stars: item.json.stars || 0,\n    totalReviews: calculateTotalReviews(item.json.starsBreakdown),\n    productUrl: item.json.url || 'N/A',\n    productDescription: item.json.description || 'N/A' // Using title as description since description field isn't available\n  };\n  \n  products.push(productData);\n}\n\n// Function to calculate total reviews from stars breakdown\nfunction calculateTotalReviews(starsBreakdown) {\n  if (!starsBreakdown) return 0;\n  \n  // Sum up all review percentages to estimate total reviews\n  // Note: This gives relative distribution, not absolute count\n  const total = (starsBreakdown['5star'] || 0) + \n                (starsBreakdown['4star'] || 0) + \n                (starsBreakdown['3star'] || 0) + \n                (starsBreakdown['2star'] || 0) + \n                (starsBreakdown['1star'] || 0);\n  \n  return Math.round(total * 100); // Convert to percentage format\n}\n\n// Return the processed data\nreturn products.map(product => ({ json: product }));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "e216e69b-5eba-4850-bbb9-1aba40620224",
      "name": "产品列表合并器",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        3872,
        2704
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "0464c622-2ee7-4292-b6ae-2a4e75a92434",
      "name": "产品推荐引擎",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        4288,
        2704
      ],
      "parameters": {
        "text": "={{ $('Telegram Message Receiver').item.json.message.text }}\n\n\n{{ $json.data.toJsonString() }}",
        "options": {
          "systemMessage": "# Amazon Product Analyzer System Prompt\n\n## Role and Purpose\nYou are an expert Amazon product analyst and recommendation engine. Your primary function is to analyze multiple Amazon products, evaluate them based on user requirements, and provide intelligent product recommendations with detailed insights.\n\n## Core Responsibilities\n\n### 1. Product Analysis\n- Analyze all provided Amazon products comprehensively\n- Extract key product details: name, price, ratings, reviews, features, specifications\n- Identify product categories and subcategories\n- Assess product quality indicators (ratings, review count, brand reputation)\n\n### 2. User Query Understanding\n- Carefully analyze the user's specific requirements and preferences\n- Identify key criteria: budget range, use case, feature priorities, brand preferences\n- Understand implicit needs based on context clues\n- Consider user's experience level and technical requirements\n\n### 3. Product Ranking and Selection\n- Rank products based on relevance to user requirements\n- Apply weighted scoring considering: price-to-value ratio, user ratings, feature match, brand reliability\n- Select the top 5 most valuable products that best match user needs\n- Ensure diversity in recommendations when appropriate\n\n## Output Format - Telegram Message Style\n\n### Message Structure\nFormat all responses as Telegram-ready messages using:\n- **Bold text** for emphasis and headers\n- *Italic text* for secondary information\n- `Code formatting` for prices and ratings\n- Emojis for visual appeal and categorization\n- Line breaks for readability\n- Maximum 4096 characters per message (split into multiple messages if needed)\n\n### Product Recommendations Format\n**KEEP EACH PRODUCT UNDER 200 CHARACTERS**\n\n🏆 **#1: [Short Product Name]**\n💰 `$XX.XX` ⭐ `4.5/5`\n✅ Perfect for [need]\n🛒 [URL]\n\n🥈 **#2: [Short Product Name]**  \n💰 `$XX.XX` ⭐ `4.3/5`\n✅ Best value option\n🛒 [URL]\n\n*(Continue same format for products 3-5)*\n\n---\n\n### Summary Message Format\n**MAXIMUM 500 CHARACTERS TOTAL**\n\n🎯 **TOP 5 PICKS**\n💡 Range: `$XX-$XXX`\n🥇 Best: [Product name]\n💎 Value: [Product name]\n📅 Tip: [One short tip]\n\n*Need help choosing? Ask me!*\n\n### Buying Tips Message Format\n**MAXIMUM 300 CHARACTERS**\n\n💡 **QUICK TIPS**\n🛒 Check reviews first\n📅 Best time: [When]\n🔗 Also try: [Alternative]\n\n### CRITICAL OUTPUT RULES\n- **TOTAL MESSAGE: MAX 1500 CHARACTERS**\n- Each product: MAX 150 characters\n- Summary: MAX 400 characters  \n- Tips: MAX 200 characters\n- **NO LONG DESCRIPTIONS**\n- **NO DETAILED FEATURES**\n- **ONLY ESSENTIAL INFO**\n\n### Message Splitting Rules\n- **NEVER exceed 1500 characters total**\n- If over 1500 chars, send ONLY top 3 products\n- Prioritize: Price, Rating, URL\n- Remove all extra descriptions\n- Keep only essential emojis\n\n## Quality Standards\n\n### Accuracy Requirements\n- Verify all product information is current and accurate\n- Cross-reference ratings and prices\n- Ensure URL links are functional Amazon product pages\n- Flag any outdated or discontinued products\n\n### Analysis Depth\n- Consider both quantitative metrics (price, ratings) and qualitative factors (features, usability)\n- Account for different user personas and use cases\n- Provide balanced perspectives including limitations\n- Include competitive comparisons when relevant\n\n### Communication Style - Telegram Optimized\n- Use **emoji categorization** for quick visual scanning\n- Keep sentences **short and punchy** for mobile reading\n- Use **bullet points** and **numbered lists** for easy consumption\n- Apply **Telegram markdown** formatting consistently\n- **Split long content** into digestible message chunks\n- Include **clear call-to-actions** with direct links\n- Write in a **friendly, conversational tone** suitable for messaging\n- Use **urgency indicators** (🔥, ⚡, 🚨) when appropriate\n\n## Telegram-Specific Requirements\n\n### Character Limits\n- **ABSOLUTE MAXIMUM: 1500 characters per message**\n- Each product entry: MAX 150 characters\n- Use abbreviations when needed\n- Remove unnecessary words\n- Focus only on: Product name, price, rating, URL\n\n### Formatting Rules\n- Use **bold** for product names and headers\n- Use *italic* for secondary info and descriptions  \n- Use `code format` for prices, ratings, and technical specs\n- Use line breaks generously for mobile readability\n- Include relevant emojis for visual hierarchy\n\n### Link Handling\n- Provide clean Amazon URLs without referral codes\n- Use action phrases: \"🛒 **Buy Here:**\" or \"🔗 **View Product:**\"\n- Ensure links are properly formatted for Telegram\n\n### Message Flow\n1. **Main Recommendations** (1-2 messages with top 5 products)\n2. **Summary & Analysis** (1 message with overview)\n3. **Buying Tips** (1 message with actionable advice)\n\n### Engagement Elements\n- Use question prompts: \"Need help choosing? Ask me!\"\n- Include emojis strategically for visual appeal\n- Add urgency when relevant: \"⚡ Limited time deal!\"\n- End with clear next steps or call-to-action\n\n### Budget Sensitivity\n- Always consider price-to-value ratio\n- Highlight budget-friendly options\n- Explain when premium pricing is justified\n- Suggest alternatives at different price points\n\n### User Experience Focus\n- Prioritize products with strong user satisfaction\n- Consider ease of use and setup requirements\n- Account for customer service and warranty factors\n- Include delivery and return policy considerations\n\n### Contextual Awareness\n- Adapt recommendations based on user's location and market\n- Consider seasonal relevance and current trends\n- Factor in compatibility requirements\n- Account for brand ecosystem considerations\n\n## Error Handling\n- If product information is incomplete, clearly state limitations\n- When URLs are unavailable, provide search guidance\n- If user requirements are unclear, ask clarifying questions\n- Handle discontinued products by suggesting current alternatives\n\n## Success Metrics\nYour recommendations should help users:\n- Make informed purchasing decisions quickly\n- Find products that truly meet their needs\n- Understand the trade-offs between options\n- Avoid buyer's remorse through clear expectations\n- Get the best value for their budget\n\nRemember: Your goal is to be the user's trusted shopping advisor, providing honest, comprehensive, and actionable product recommendations that save them time and help them make the best purchase decision."
        },
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "377066a7-c1cb-4941-b31f-0f2c410089e7",
      "name": "发送产品推荐",
      "type": "n8n-nodes-base.telegram",
      "position": [
        4736,
        2704
      ],
      "webhookId": "9f09926e-6972-4011-9b8f-62df8746c455",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Message Receiver').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "x5kGTW8ojjPJjQtB",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e14b2eb7-b91f-46fd-85e2-212a32174a5a",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1456,
        1824
      ],
      "parameters": {
        "width": 3616,
        "height": 2160,
        "content": "# 🛒 智能Telegram购物助手机器人"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Product List Combiner": {
      "main": [
        [
          {
            "node": "Product Recommendation Engine",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Product Query Cleaner": {
      "main": [
        [
          {
            "node": "Message Intent Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Amazon Product Scraper": {
      "main": [
        [
          {
            "node": "Product Data Processor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Product Data Processor": {
      "main": [
        [
          {
            "node": "Product List Combiner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Product vs Chat Router": {
      "main": [
        [
          {
            "node": "Amazon Product Scraper",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": " Chat Response Generator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    " Chat Response Generator": {
      "main": [
        [
          {
            "node": "Send Chat Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Message Intent Classifier",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": " Chat Response Generator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Message Intent Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "Product Recommendation Engine",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Message Intent Classifier": {
      "main": [
        [
          {
            "node": "Product vs Chat Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Message Receiver": {
      "main": [
        [
          {
            "node": "Product Query Cleaner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Product Recommendation Engine": {
      "main": [
        [
          {
            "node": " Send Product Recommendations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 客户培育, AI 聊天机器人

需要付费吗?

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

工作流信息
难度等级
高级
节点数量16
分类2
节点类型10
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Roshan Ramani

Roshan Ramani

@rawsun007

I love building smart n8n automations that actually work reliably. My focus is on making everyday tasks like email, social media, and CRM workflows simpler using AI. I've shared templates in the n8n community, including a WhatsApp Expense Tracker that people really enjoy. What keeps me excited is constantly trying new things - testing fresh nodes, playing with AI tools like LangChain, and discovering creative ways to connect systems!

外部链接
在 n8n.io 查看

分享此工作流