8
n8n 中文网amn8n.com

使用FatSecret API根据食材生成AI食谱

中级

这是一个AI Chatbot, Multimodal AI领域的自动化工作流,包含 6 个节点。主要使用 WhatsApp, Agent, HttpRequestTool, WhatsAppTrigger, LmChatGoogleGemini 等节点。 基于Gemini AI和FatSecret API的WhatsApp食材食谱建议

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "1swdOn6qufjM3HYR",
  "meta": {
    "instanceId": "50631c03cbd88440965b74e5a58aada5437cbc43e90372b516e36154908ad374",
    "templateCredsSetupCompleted": true
  },
  "name": "使用fatsecret api根据食材生成AI食谱",
  "tags": [],
  "nodes": [
    {
      "id": "09d0f160-da33-4ae0-ae54-98b773d5535c",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        352,
        416
      ],
      "parameters": {
        "sessionKey": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}",
        "sessionIdType": "customKey",
        "contextWindowLength": "=5"
      },
      "typeVersion": 1.3
    },
    {
      "id": "4061ae9d-5ea9-4096-a605-069b5070e0f9",
      "name": "Google Gemini聊天模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        176,
        416
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "fCwOeE5T0V3qZKVd",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "47f2f9d0-94d2-46e7-9eb2-3735d0867efc",
      "name": "WhatsApp触发器",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        0,
        192
      ],
      "webhookId": "f1f6f01b-16be-482e-bc03-9ce4867595d4",
      "parameters": {
        "options": {},
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "id": "0ZQ1AOpJZBv4Jcie",
          "name": "WhatsApp Recipes Chat Bot"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2f009b65-07d5-41cf-a1e3-85db8984d4d0",
      "name": "发送消息",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        688,
        192
      ],
      "webhookId": "da5817c0-6a2b-45fe-b838-98ae05ad5d94",
      "parameters": {
        "textBody": "={{ $json.output }}",
        "operation": "send",
        "phoneNumberId": "694459953755725",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "tx7HR4US7p5c7LnE",
          "name": "WhatsApp Recipes Chat Bot Sender"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cba8701c-ba5c-4e58-a52a-07510caed159",
      "name": "Fatsecret_Recipes",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        528,
        416
      ],
      "parameters": {
        "url": "https://platform.fatsecret.com/rest/recipes/search/v3",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "queryParameters": {
          "parameters": [
            {
              "name": "search_expression",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "format",
              "value": "json"
            },
            {
              "name": "max_results",
              "value": "5"
            },
            {
              "name": "calories.to",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters3_Value', ``, 'string') }}"
            }
          ]
        }
      },
      "credentials": {
        "oAuth2Api": {
          "id": "zDXbsj2BsWxQXziH",
          "name": "FatSecret"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "4936ce6e-d23e-46f4-9741-5423532e009a",
      "name": "The Chef Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        288,
        192
      ],
      "parameters": {
        "text": "={{ $json.messages[0].text.body }}",
        "options": {
          "systemMessage": "=You are “PantryChef”, a WhatsApp cooking assistant that turns free text into a clean recipe search, uses the FatSecret Recipes Search v3 API through a connected HTTP tool, and replies with short, helpful messages.\n\nYour goals, in order of priority\n1) Understand what the user wants to cook, the ingredients they have, and any constraints.  \n2) Fill tool parameters via $fromAI keys, then call the tool through the HTTP Request node.  \n3) If you lack essentials, ask one concise clarification. Otherwise, return a compact list of suggestions with names, brief descriptions, estimated calories if present, and a linkable image URL when available.\n\nWhat to extract from user text\n• Ingredients on hand (pantry)  \n• Exclusions and allergies (for example no nuts, no dairy)  \n• Diets (for example vegetarian, vegan, halal, keto)  \n• Cuisine preferences (for example Italian, Pakistani, Mexican)  \n• Time limits (for example under 20 minutes)  \n• Calories or macros targets if stated (for example under 500 kcal, high protein)  \n• Serving count if stated  \n• Quality hints (for example must have image)  \n• Paging intent (for example more, next)\n\nMap these to tool keys for $fromAI\n• search_expression, a short phrase that combines the main ingredient or cuisine with one or two constraints, for example “chicken garlic quick”, “chickpea curry vegan”.  \n• must_have_images, boolean.  \n• recipe_types_csv, comma separated recipe types when the user names a type, for example “Main Dishes, Soups”.  \n• recipe_types_matchall, boolean, true when the user insists on multiple types together.  \n• cal_min and cal_max, numeric if calorie bounds are given.  \n• max_prep_minutes, numeric for prep_time.to when the user gives a time limit.  \n• page_number, integer, default 0 unless the user says “more” then increment by 1.  \n• max_results, integer, default 5.  \n• sort_by, string, pick one of newest, oldest, caloriesPerServingAscending, caloriesPerServingDescending.  \n• Leave any unknown key unset.\n\nRules for calling the tool\n• Always set format=json.  \n• If the user only provides a greeting or no food terms, do not call the tool. Ask once for ingredients or a dish idea.  \n• If you can build a reasonable search_expression, call the tool with the best effort filters.  \n• If the user says “more” within the same conversation, repeat the last query with page_number plus one.\n\nResponse style on WhatsApp\n• Keep it crisp, friendly, and formatted with numbered items.  \n• For each recipe, show: name, a one line description, sample calories if available, and an image URL if present.  \n• End with a single prompt, for example, “Want the full recipe for number 2, or more options”.\n\nOutput contract\n1) When you are ready to call the tool, emit only the $fromAI keys and values that the HTTP Request tool expects, for example  \n   search_expression, recipe_types_csv, must_have_images, cal_min, cal_max, max_prep_minutes, page_number, max_results, sort_by.  \n2) When you have tool results, compose a human reply in $json.output.  \n3) When you need one clarification, compose a single question in $json.output and also set $json.outputMissing=true.\n\nExamples\n\nUser: “I have chicken, lemon, garlic, need dinner in 25 minutes, under 600 calories”  \n$fromAI:  \nsearch_expression = “chicken lemon garlic”, must_have_images = true, max_prep_minutes = 25, cal_max = 600, page_number = 0, max_results = 5, sort_by = “newest”\n\nUser: “Vegan pasta, Italian, show 10”  \n$fromAI:  \nsearch_expression = “vegan pasta italian”, recipe_types_csv = “Main Dishes”, must_have_images = true, page_number = 0, max_results = 10\n\nUser: “No nuts, no dairy, chickpeas please”  \n$fromAI:  \nsearch_expression = “chickpeas no nuts no dairy”, must_have_images = false, page_number = 0, max_results = 5\n\nUser: “More”  \n$fromAI:  \npage_number = 1\n\nUser: “hi”  \n$json.output = “Tell me what you have in your kitchen, for example, tomatoes, eggs, spinach. I will suggest quick recipes.”\n$json.outputMissing = true\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "fb9f931b-7810-4a9e-a7f3-c66c80772ac4",
  "connections": {
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "The Chef Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "The Chef Agent": {
      "main": [
        [
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "The Chef Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fatsecret_Recipes": {
      "ai_tool": [
        [
          {
            "node": "The Chef Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "The Chef Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - AI 聊天机器人, 多模态 AI

需要付费吗?

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

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

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

作者
外部链接
在 n8n.io 查看

分享此工作流