通过WhatsApp使用Google Gemini的产品成分安全分析器
这是一个Content Creation, Multimodal AI领域的自动化工作流,包含 15 个节点。主要使用 Switch, WhatsApp, HttpRequest, Agent, ExtractFromFile 等节点。 通过WhatsApp使用Google Gemini的产品成分安全分析器
- •可能需要目标 API 的认证凭证
- •Google Gemini API Key
使用的节点 (15)
{
"meta": {
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "0e96888f-f71c-4e0e-8550-919c1fa4d40a",
"name": "WhatsApp触发器",
"type": "n8n-nodes-base.whatsAppTrigger",
"position": [
-1216,
-288
],
"webhookId": "12cc76d5-837e-4d3f-83d3-0c2e6fb9a6b4",
"parameters": {
"options": {},
"updates": [
"messages"
]
},
"credentials": {
"whatsAppTriggerApi": {
"id": "WHATSAPP_TRIGGER_CRED_ID",
"name": "WhatsApp Trigger Credentials"
}
},
"typeVersion": 1
},
{
"id": "1c9439dd-6cd0-4455-895f-bb6b26e9f8e6",
"name": "按消息类型路由",
"type": "n8n-nodes-base.switch",
"position": [
-1008,
-288
],
"parameters": {
"rules": {
"values": [
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "85e50000-c740-43e4-a519-d1de10c9bc82",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.messages[0].type }}",
"rightValue": "image"
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "91ee10e4-fc37-4de7-9360-2060a9ec16dd",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.messages[0].type }}",
"rightValue": "text"
}
]
}
}
]
},
"options": {},
"looseTypeValidation": true
},
"typeVersion": 3.3
},
{
"id": "ac24a055-4e1c-4b0c-9046-1a3b63ce609a",
"name": "获取图片媒体URL",
"type": "n8n-nodes-base.whatsApp",
"position": [
-800,
-304
],
"webhookId": "248f7c42-00d5-45e7-8336-874b0e4a395e",
"parameters": {
"resource": "media",
"operation": "mediaUrlGet",
"mediaGetId": "={{ $json.messages[0].image.id }}"
},
"credentials": {
"whatsAppApi": {
"id": "WHATSAPP_API_CRED_ID",
"name": "WhatsApp API Credentials"
}
},
"typeVersion": 1
},
{
"id": "56476b24-aa22-458f-a911-2b764e08e5d0",
"name": "下载图片文件",
"type": "n8n-nodes-base.httpRequest",
"position": [
-608,
-304
],
"parameters": {
"url": "={{ $json.url }}",
"options": {
"response": {
"response": {
"responseFormat": "file"
}
}
},
"authentication": "predefinedCredentialType",
"nodeCredentialType": "whatsAppApi"
},
"credentials": {
"whatsAppApi": {
"id": "WHATSAPP_API_CRED_ID",
"name": "WhatsApp API Credentials"
}
},
"typeVersion": 4.2
},
{
"id": "04d8e4e2-dd23-40b3-a7c6-e9c70ce78a86",
"name": "将图片转换为Base64",
"type": "n8n-nodes-base.extractFromFile",
"position": [
-384,
-304
],
"parameters": {
"options": {
"encoding": "base64"
},
"operation": "binaryToPropery",
"destinationKey": "data1",
"binaryPropertyName": "=data"
},
"typeVersion": 1
},
{
"id": "430083cc-2990-4e7e-aec2-d007a1a00f03",
"name": "通过OCR提取文本",
"type": "n8n-nodes-base.httpRequest",
"position": [
-144,
-304
],
"parameters": {
"url": "=https://us-documentai.googleapis.com/v1/projects/YOUR_GOOGLE_PROJECT_ID/locations/us/processors/YOUR_PROCESSOR_ID:process",
"method": "POST",
"options": {},
"jsonBody": "={\n \"rawDocument\": {\n \"content\": \"{{ $('Convert Image to Base64').item.json.data1 }}\",\n \"mimeType\": \"{{ $('WhatsApp Trigger').item.json.messages[0].image.mime_type }}\"\n }\n}\n",
"sendBody": true,
"specifyBody": "json",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "googleApi"
},
"credentials": {
"googleApi": {
"id": "GOOGLE_SERVICE_ACCOUNT_CRED_ID",
"name": "Google Service Account Credentials"
}
},
"executeOnce": false,
"typeVersion": 4.2
},
{
"id": "073c2503-dd47-441d-ae55-5abecd83e325",
"name": "分析图片成分",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
96,
-304
],
"parameters": {
"text": "=user message :- {{ $('WhatsApp Trigger').item.json.messages[0].image.caption || \"null\" }}\n\nocr :- {{ $json.document.text }}",
"options": {
"systemMessage": "You are a professional product ingredient analyzer AI. Your task is to analyze OCR text extracted from ANY product images (food, cosmetics, personal care, hair care, etc.) and determine if the ingredients are safe or harmful for the user.\n\n**CRITICAL INSTRUCTIONS:**\n1. You will receive: user_message + ocr_text from a product image\n2. You MUST respond with ONLY valid JSON in this exact format:\n{\n\"is_ingredients\": 0 or 1,\n\"message\": \"your response message here\"\n}\n\n**Response Logic:**\n- Set \"is_ingredients\": 0 if:\n - OCR text doesn't contain ingredient information\n - Image is unclear/unreadable\n - No product information found\n\n- Set \"is_ingredients\": 1 if:\n - OCR text contains identifiable ingredients list\n - Product information is readable\n\n**For is_ingredients: 0:**\n- Message should ask for clearer image\n- Keep message brief and WhatsApp-friendly\n- Use emojis appropriately\n\n**For is_ingredients: 1:**\n- First identify the product type (food, cosmetic, hair care, skincare, etc.)\n- Analyze ingredients based on product category\n- Identify harmful ingredients specific to that product type\n- Identify beneficial ingredients\n- Provide clear recommendation: ✅ SAFE TO USE or ⚠️ USE WITH CAUTION or ❌ AVOID\n- Keep message concise but informative\n- Use WhatsApp formatting (* for bold, _ for italic)\n- Include key points in bullet format if needed\n\n**Product-Specific Analysis Criteria:**\n\n**FOOD PRODUCTS:**\n- Red flags: Trans fats, high sodium (>600mg), artificial colors (Red 40, Yellow 5), MSG, high fructose corn syrup, excessive preservatives\n- Caution: High sugar content, saturated fats, artificial sweeteners\n- Positive: Natural ingredients, fiber, vitamins, minerals, organic certification\n\n**COSMETICS & PERSONAL CARE:**\n- Red flags: Parabens, phthalates, formaldehyde, synthetic fragrances, triclosan, coal tar, BHA\n- Caution: Alcohol (drying types), synthetic colors, strong preservatives\n- Positive: Natural oils, plant extracts, gentle preservatives, fragrance-free\n\n**HAIR CARE PRODUCTS:**\n- Red flags: Mineral oil, silicones (dimethicone), parabens, sulfates (SLS/SLES), formaldehyde, synthetic fragrances with phthalates\n- Caution: Alcohol (drying types), methylisothiazolinone (MIT)\n- Positive: Natural oils (argan, coconut, jojoba), plant extracts, sulfate-free formulas\n\n**SKINCARE PRODUCTS:**\n- Red flags: Hydroquinone, formaldehyde releasers, parabens, synthetic fragrances, alcohol denat\n- Caution: Strong acids without proper formulation, essential oils (for sensitive skin)\n- Positive: Hyaluronic acid, ceramides, niacinamide, natural moisturizers\n\n**General Safety Concerns Across All Products:**\n- Endocrine disruptors (parabens, phthalates)\n- Known carcinogens (formaldehyde, coal tar)\n- Strong allergens and irritants\n- Environmental toxins\n\n**Message Style:**\n- Conversational and friendly\n- WhatsApp appropriate (short paragraphs)\n- Use relevant emojis\n- Clear verdict at the end\n- Mention product type in analysis"
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 2.2
},
{
"id": "972151e6-0d99-4f79-abdb-4b7297fc346d",
"name": "Gemini模型(图片分支)",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
96,
-96
],
"parameters": {
"options": {}
},
"credentials": {
"googlePalmApi": {
"id": "GOOGLE_GEMINI_API_CRED_ID",
"name": "Google Gemini API Credentials"
}
},
"typeVersion": 1
},
{
"id": "98007634-ddde-4e51-8988-68859c6f894c",
"name": "JSON解析器(图片)",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
272,
-96
],
"parameters": {
"jsonSchemaExample": "{\n \"is_ingredients\": 0 ,\n \"message\": \"your response message here\"\n }"
},
"typeVersion": 1.3
},
{
"id": "b3373a4e-901f-4bfa-be3c-5b3ef206e55c",
"name": "发送图片分析结果",
"type": "n8n-nodes-base.whatsApp",
"position": [
480,
-304
],
"webhookId": "26322377-3dde-4da3-b2aa-117f66db36f4",
"parameters": {
"textBody": "={{ $json.output.message }}",
"operation": "send",
"phoneNumberId": "YOUR_WHATSAPP_PHONE_NUMBER_ID",
"additionalFields": {},
"recipientPhoneNumber": "=+{{ $('WhatsApp Trigger').item.json.contacts[0].wa_id }}"
},
"credentials": {
"whatsAppApi": {
"id": "WHATSAPP_API_CRED_ID",
"name": "WhatsApp API Credentials"
}
},
"typeVersion": 1
},
{
"id": "208414de-bb89-494e-91e1-ac6fd871acab",
"name": "分析文本查询",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-784,
-16
],
"parameters": {
"text": "={{ $json.messages[0].text.body }}",
"options": {
"systemMessage": "# Professional Product Safety Analyzer AI\n\nYou are a WhatsApp-based product safety analyzer specializing in instant health and safety assessments for ANY product type (food, cosmetics, pharmaceuticals, household items, personal care, supplements).\n\n## CRITICAL: JSON Response Format\nYou MUST ALWAYS respond with ONLY valid JSON in this exact format:\n{\n \"is_ingredients\": 0,\n \"message\": \"your response message here\"\n}\n\n## Core Tasks\n\n### Task 1: Product Safety Analysis\nAnalyze product names, brands, ingredient lists (text or from images processed separately) and provide safety recommendations.\n\n### Task 2: Conversational Support\nHandle greetings, help requests, and unclear queries. Guide users on how to properly submit products for analysis.\n\n## Response Logic Rules\n\n### Set \"is_ingredients\": 1 (Perform Analysis) When:\n- Specific product name with brand provided (e.g., \"Coca Cola\", \"Dove soap\", \"Paracetamol 500mg\")\n- Complete or partial ingredient list provided in text\n- Clear product category identifiable (e.g., \"chocolate bar\", \"face cream\", \"dish soap\")\n- Sufficient information exists to provide meaningful safety assessment\n- User asks about specific product effects or safety concerns\n\n### Set \"is_ingredients\": 0 (Request More Info) When:\n- Greeting only: \"hi\", \"hello\", \"hey\", \"namaste\"\n- Vague queries: \"some cream\", \"a medicine\", \"that food\"\n- Help requests: \"how does this work?\", \"what can you do?\"\n- Insufficient information to identify product\n- User asks about general topics unrelated to product safety\n\n## Analysis Framework by Category\n\n### 🍜 FOOD PRODUCTS\n**❌ Red Flags:** Trans fats, high sodium (>600mg/serving), artificial colors (Red 40, Yellow 5, Tartrazine), MSG, high fructose corn syrup, BHA/BHT preservatives, hydrogenated oils\n**⚠️ Caution:** High sugar (>25g/serving), saturated fats (>5g), artificial sweeteners (aspartame, sucralose), excessive preservatives, refined carbs\n**✅ Positive:** Natural ingredients, fiber (>3g), vitamins, minerals, organic certification, whole grains, low sodium (<200mg)\n\n### 💄 COSMETICS/PERSONAL CARE\n**❌ Red Flags:** Parabens (methylparaben, propylparaben), sulfates (SLS/SLES), phthalates, formaldehyde/releasers, mercury compounds, lead acetate, hydroquinone\n**⚠️ Caution:** Denatured alcohol, synthetic fragrances, mineral oil (for sensitive skin), silicones (long-term buildup)\n**✅ Positive:** Natural oils (argan, jojoba, coconut), hyaluronic acid, ceramides, niacinamide, dermatologist-tested, fragrance-free, paraben-free\n\n### 💊 PHARMACEUTICALS/SUPPLEMENTS\n**Focus Areas:** Active ingredients, appropriate dosage, known side effects, drug interactions, contraindications\n**⚠️ Check For:** Allergens, age restrictions, pregnancy/breastfeeding warnings, overdose risks, expiration concerns\n**✅ Positive:** FDA/regulatory approved, third-party tested, clear dosing guidelines, established safety profile\n\n### 🧽 HOUSEHOLD/CLEANING\n**❌ Red Flags:** Ammonia + bleach combinations, phosphates, VOCs, triclosan, chlorine bleach, artificial musks\n**⚠️ Caution:** Strong synthetic fragrances, aerosol propellants, strong acids/bases\n**✅ Positive:** Biodegradable, eco-certified, plant-based, phosphate-free, non-toxic\n\n## Message Style Guidelines\n\n**Be Concise:** Keep responses under 150 words for WhatsApp readability\n**Be Practical:** Give actionable advice and alternatives\n**Be Accurate:** Only analyze what you have information about\n**Be Encouraging:** Maintain friendly, supportive tone\n**Be Clear:** Use simple language, avoid technical jargon unless necessary"
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 2.2
},
{
"id": "c73438f1-cb8c-4b75-a139-e0606f91a076",
"name": "Gemini模型(文本分支)",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
-784,
192
],
"parameters": {
"options": {}
},
"credentials": {
"googlePalmApi": {
"id": "GOOGLE_GEMINI_API_CRED_ID",
"name": "Google Gemini API Credentials"
}
},
"typeVersion": 1
},
{
"id": "fd20d4af-4a92-4564-b486-9d14f6523afd",
"name": "JSON解析器(文本)",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
-608,
192
],
"parameters": {
"jsonSchemaExample": "{\n \"is_ingredients\": 0 ,\n \"message\": \"your response message here\"\n }"
},
"typeVersion": 1.3
},
{
"id": "8fd57b7f-8ba0-4c3e-bd59-219ac62e6522",
"name": "发送文本分析结果",
"type": "n8n-nodes-base.whatsApp",
"position": [
-480,
-16
],
"webhookId": "51fcf1a0-a152-4237-8e3a-a5a859e4d2e3",
"parameters": {
"textBody": "={{ $json.output.message }}",
"operation": "send",
"phoneNumberId": "YOUR_WHATSAPP_PHONE_NUMBER_ID",
"additionalFields": {},
"recipientPhoneNumber": "=+{{ $('WhatsApp Trigger').item.json.contacts[0].wa_id }}"
},
"credentials": {
"whatsAppApi": {
"id": "WHATSAPP_API_CRED_ID",
"name": "WhatsApp API Credentials"
}
},
"typeVersion": 1
},
{
"id": "06222313-1c77-48bf-8246-3ba4551bbbe3",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1808,
-672
],
"parameters": {
"width": 2560,
"height": 1056,
"content": "# 📋 通过WhatsApp的AI产品成分安全分析器"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"WhatsApp Trigger": {
"main": [
[
{
"node": "Route By Message Type",
"type": "main",
"index": 0
}
]
]
},
"Analyze Text Query": {
"main": [
[
{
"node": "Send Analysis of Text",
"type": "main",
"index": 0
}
]
]
},
"JSON Parser (Text)": {
"ai_outputParser": [
[
{
"node": "Analyze Text Query",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Download Image File": {
"main": [
[
{
"node": "Convert Image to Base64",
"type": "main",
"index": 0
}
]
]
},
"Get Image Media URL": {
"main": [
[
{
"node": "Download Image File",
"type": "main",
"index": 0
}
]
]
},
"JSON Parser (Image)": {
"ai_outputParser": [
[
{
"node": "Analyze Image Ingredients",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Extract Text via OCR": {
"main": [
[
{
"node": "Analyze Image Ingredients",
"type": "main",
"index": 0
}
]
]
},
"Route By Message Type": {
"main": [
[
{
"node": "Get Image Media URL",
"type": "main",
"index": 0
}
],
[
{
"node": "Analyze Text Query",
"type": "main",
"index": 0
}
]
]
},
"Convert Image to Base64": {
"main": [
[
{
"node": "Extract Text via OCR",
"type": "main",
"index": 0
}
]
]
},
"Analyze Image Ingredients": {
"main": [
[
{
"node": "Send Analysis of Image",
"type": "main",
"index": 0
}
]
]
},
"Gemini Model (Text Branch)": {
"ai_languageModel": [
[
{
"node": "Analyze Text Query",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Gemini Model (Image Branch)": {
"ai_languageModel": [
[
{
"node": "Analyze Image Ingredients",
"type": "ai_languageModel",
"index": 0
}
]
]
}
}
}如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 内容创作, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
Roshan Ramani
@rawsun007I 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!
分享此工作流