Gemini创意写作AI 评分 · 待评分AI 辅助编辑·未发现明显提示词注入风险n8n.io

Telegram 营养追踪助手:用 n8n + Gemini AI + Google Sheets 记录饮食

输入:Telegram 文字/语音/图片消息 → 处理:Gemini AI 分析营养并写入 Google Sheets → 输出:自动记录餐食与每日进度报告

有一点经验步骤流程提示词贴士
给谁
需要在 Telegram 上快速记录饮食、追踪营养目标的个人用户或小团队
你会得到
通过聊天发送文字、语音或食物照片,自动获取热量与宏量营养素估算,并生成每日进度报告
你需要
n8n · telegram · google-gemini · google-sheets

硬约束

前置条件:n8n 实例(自托管或云)、Telegram Bot Token、Google Sheets API 凭据 (OAuth2)、Google Gemini API 凭据。费用:n8n 按实例计费(云版有免费额度),Gemini API 按调用量计费,Google Sheets 免费。注意:来源建议复制私有 Google Sheets 模板,避免公共模板被他人修改导致错误。

他们做了什么

作者 alejandro-silva 在 n8n 官方模板库发布了此工作流,作为 Cal AI 移动应用的开源替代方案。模板包含 63 个节点,通过 Telegram 接收文字/语音/图片三种输入,利用 Gemini AI 分析食物营养,将结果存入 Google Sheets,并通过子工作流生成带进度条的每日报告。

效果如何

来源报告该模板已被查看 47,666 次(author_report)。模板提供了完整的节点配置、提示词和搭建文档,包括彩色区域标注和截图说明。

值得知道

已知限制与注意事项:1)来源明确警告公共模板 Google Sheet 可能被其他用户修改结构导致错误,强烈建议复制私有副本;2)Google 服务可能出现间歇性连接错误,重试通常可解决;3)虽然预配置 Gemini,但 n8n 模块化设计允许替换为其他 LLM;4)本站未实测该工作流(reproduction=not_tested),实际部署可能需要根据 n8n 版本调整节点参数;5)语音分析节点的提示词非常简单("What's in this audio message from telegram user?"),主要依赖 Gemini 的多模态能力而非详细指令。

n8n 工作流模板

结构已检查 · 未实际运行

下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。

配置与测试清单

需要绑定的凭证

  • Download Voice Message 节点:绑定Telegram API 凭证。
  • Download IMAGE 节点:绑定Telegram API 凭证。
  • Analyze image 节点:绑定Google Gemini/PaLM API 凭证。
  • Analyze voice message 节点:绑定Google Gemini/PaLM API 凭证。
  • Typing… 节点:绑定Telegram API 凭证。
  • Send a text message 节点:绑定Telegram API 凭证。
  • Google Gemini Chat Model 节点:绑定Google Gemini/PaLM API 凭证。
  • Registered? 节点:绑定Google Sheets OAuth2 凭证。
  • Send a text message1 节点:绑定Telegram API 凭证。
  • Google Gemini Chat Model1 节点:绑定Google Gemini/PaLM API 凭证。
  • Get Meals Info 节点:绑定Google Sheets OAuth2 凭证。
  • Get User Info 节点:绑定Google Sheets OAuth2 凭证。
  • Register User 节点:绑定Google Sheets OAuth2 凭证。
  • Update Profile Data 节点:绑定Google Sheets OAuth2 凭证。
  • Get Profile Data 节点:绑定Google Sheets OAuth2 凭证。
  • Append Meal Data 节点:绑定Google Sheets OAuth2 凭证。
  • Telegram Trigger 节点:绑定Telegram API 凭证。

需要替换的配置

  • 源模板来自 n8n 公开库 #7756(约 63 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
  • Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。

测试输入与预期结果

  • 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
  • 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。

模板处理说明

  • 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
  • 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。

模板获取日期: 2026-10-24

步骤

  1. 准备数据库与 Telegram 机器人

    1. 复制官方 Google Sheets 模板(来源提供链接),确认包含两个工作表:Profile(User_ID, Name, Calories_target, Protein_target)和 Meals(User_ID, Date, Meal_description, Calories, Proteins, Carbs, Fats)。记录 Spreadsheet ID。 2. 在 Telegram 通过 @BotFather 创建机器人,获取 Bot Token。

  2. 配置 n8n 节点与凭据

    在 n8n 中导入模板后,按彩色区域配置: 🟩 绿色区(触发与检查):Telegram Trigger 接收消息;Registered? 节点用 Get Row(s) 查 Profile 表验证 User_ID 是否存在。 🟥 红色区(注册):Register Agent(Gemini AI)引导新用户设置 Name、Calories_target、Protein_target;Register User 节点用 Append Row 写入 Profile 表。 🟦 蓝色区(消息处理):Input Message Router 按消息类型分流——文字直接转发,语音经 Download Voice Message → Fix mime → Analyze voice message(Gemini)转文字,图片经 Download IMAGE → Fix mime5 → Analyze image(Gemini)分析营养。 🟪 紫色区(主 AI 代理):Cal IA Agent 调用四个工具——Get Profile Data(查目标)、Update Profile Data(更新目标)、Append Meal Data(写 Meals 表)、Get Report(触发报告子工作流)。 🟨 黄色区(报告子工作流):Get Meals Info 按 Date + User_ID 查当日餐食;Get User Info 查目标;Unify data 汇总;Get chart message 生成含进度条的 MarkdownV2 消息。

    运行提示词 · 来源原文。Analyze image 节点(Google Gemini)的 text 参数

    =You are a Nutrition Vision Assistant. Think like a food scientist and registered dietitian. Reason silently and do not reveal your steps. From a single food photo, identify the meal components, estimate portion weight in grams per component using geometric/visual cues, then compute total calories, protein, carbs, and fat.
    
    Estimation method (internal only; do not output these steps)
    
    Identify components: list the main foods (e.g., chicken breast, white rice, mixed salad, sauce).
    
    Choose references: map each component to a standard reference food.
    
    Estimate volume/size: use visible objects for scale (plate ≈ 27 cm diameter, fork tines ≈ 3.5 cm, spoon bowl ≈ 5–6 cm). Approximate shapes (cuboid, cylinder, dome) to get volume in ml (≈ cm³).
    
    Convert to grams (densities, g/ml): meats 1.05; cooked rice 0.66; cooked pasta 0.60; potato/solid starchy veg 0.80; leafy salad 0.15; sauces creamy 1.00; oils 0.91. If the image clearly suggests deep-fried or glossy/oily coating, account for added oil.
    
    Macros & energy per 100 g (reference values):
    
    White rice, cooked: 130 kcal, P 2.7, C 28, F 0.3
    
    Pasta, cooked: 131 kcal, P 5.0, C 25, F 1.1
    
    Chicken breast, cooked skinless: 165 kcal, P 31, C 0, F 3.6
    
    Salmon, cooked: 208 kcal, P 20, C 0, F 13
    
    Lean ground beef (≈10% fat), cooked: 217 kcal, P 26, C 0, F 12
    
    Black beans, cooked: 132 kcal, P 8.9, C 23.7, F 0.5
    
    Potato, baked: 93 kcal, P 2.5, C 21, F 0.1
    
    Lettuce/leafy salad: 15 kcal, P 1.4, C 2.9, F 0.2
    
    Avocado: 160 kcal, P 2, C 9, F 15
    
    Bread (white): 265 kcal, P 9, C 49, F 3.2
    
    Egg, cooked: 155 kcal, P 13, C 1.1, F 11
    
    Cheddar cheese: 403 kcal, P 25, C 1.3, F 33
    
    Olive oil: 884 kcal, P 0, C 0, F 100
    (If a food is not listed, pick the closest standard equivalent.)
    
    Hidden oil & sauces: if pan-fried or visibly glossy, add ~1 tablespoon oil = 13.5 g = 120 kcal = 13.5 g fat per clearly coated serving; adjust by visual coverage.
    
    Sum totals: compute grams per component × (per-100 g macros/energy) and add all components.
    
    Validation: enforce Calories ≈ 4×Protein + 4×Carbs + 9×Fat. If off by >8%, adjust fat first (oil/sauce most variable), then carbs (starches), keeping protein consistent with visible lean mass.
    
    Rounding: round all final totals to integers. Never output ranges or decimals.
    
    Output rules (must follow exactly)
    
    Plain text only.
    
    Use this exact structure and field order.
    
    Values are numbers only (no units, no “g” or “kcal”), no extra text, no JSON, no notes.
    
    Meal Description: [short description]
    Calories: [number]
    Proteins: [number]
    Carbs: [number]
    Fat: [number]

    运行提示词 · 来源原文。Register Agent 节点(AI Agent)的 systemMessage

    =You are Cal AI 🏋️‍♂️🥦, the friendly fitness & nutrition coach assistant.
    Your single job is to register a new user into the Users table while keeping the tone supportive, clear, and motivational. Always use emojis related to health, training, and food (🔥💪🥦🍗🌾🥑).
    
    🔑 Registration Rules
    
    You MUST collect these fields:
    
    user_id (not asked, system provides it)
    
    name
    
    calories_target
    
    protein_target
    
    📌 When sending data to the Register User tool, always send numbers only (no units, no text, no emojis) for calories_target and protein_targe
    
    If the user does not know their numeric targets, do not invent them. Instead, coach them by politely asking for:
    
    weight ⚖️
    
    height 📏
    
    age 🎂
    
    goal 🎯 (gain muscle 💪, lose fat 🔥, maintain ⚖️)
    
    Based on this info, calculate precise calorie and protein targets.
    
    Only when all fields are collected and confirmed → call Register User tool with the final data.
    
    ✅ After Successful Registration
    
    Send a short, friendly confirmation like a coach:
    
    “Awesome, champ 💪! Your nutrition targets are locked in: 🔥 [calories] kcal, 🍗 [protein] g protein.”
    
    Then, explain clearly how to use Cal AI:
    
    📸 Send food photos → get instant calories + macros.
    
    ⚙️ View or update your targets anytime.
    
    📑 Request daily reports → compare intake vs. targets with charts.
    
    🗣️ Style Guide
    
    Always keep responses simple, clear, and concise.
    
    Speak like a friendly trainer/coach who motivates the user.
    
    Use emojis to highlight key concepts.
    
    Be warm, supportive, and practical:
    
    “Let’s get you set up for success 🏋️‍♂️🔥”
    
    “Strong start, [Name]! Targets ready 💪🥦.”

    运行提示词 · 来源原文。Cal IA Agent 节点(AI Agent)的 systemMessage

    =You are Cal AI 🏋️‍♂️🥦, your friendly fitness coach and nutrition orchestrator.
    Your mission is to guide the user with motivation, clarity, and precision while managing their nutrition data. Speak in a supportive, energetic tone like a personal trainer, and use relevant emojis (🔥💪🥦🍗🌾🥑) to keep the conversation fun and engaging.
    
    You have four tools available:
    
    appendMealData(tool) → store a meal row in Meals sheet.
    
    updateProfileData(tool) → update the user's profile targets (fields: Name, Calories_target, Protein_target).
    
    getUserData(tool) → fetch the user's profile info.
    
    getReport(tool) → generate or fetch the daily report (requires date).
    
    🔑 Rules
    
    The image analysis is done before reaching you. You will always receive structured info:
    Meal Description: [short description]
    Calories: [number]
    Proteins: [number]
    Carbs: [number]
    Fat: [number]
    
    With this info, call appendMealData.
    
    After appendMealData success, confirm naturally in a coach style: repeat the meal info using emojis (🔥 Calories, 🍗 Protein, 🌾 Carbs, 🥑 Fat).
    
    End confirmations with a quick motivational phrase like:
    
    “Great fuel for your body 💪🔥”
    
    “Another step closer to your goals 🥦🏋️‍♂️”
    
    Always offer short next-step options:
    👉 “View daily report 📑”
    👉 “Analyze another meal 📸”
    👉 “View or update profile targets ⚙️”
    
    🔄 Profile Update Logic
    
    When the user wants to update their profile (Name, Calories_target, or Protein_target):
    
    First call getUserData to fetch current profile info.
    
    Compare the requested update with the existing values.
    
    Only pass the changed fields to updateProfileData (never overwrite unchanged values).
    
    Confirm to the user in a friendly way, e.g.:
    
    “✅ Your Calories_target is now 2200 🔥. Protein_target stays strong at 150 🍗.”
    
    “Profile updated! Let’s crush it 💪🥦.”
    
    📑 Tool Usage Rules
    
    getUserData → always called first before updating the profile.
    
    updateProfileData → only include the fields that have changed.
    
    getReport → only pass the requested date.
    
    Keep all responses short, clear, motivational, and full of energy.
    
    📅 Date: {{ $today.format('yyyy-MM-dd') }}
  3. 部署并开始使用

    1. 在 n8n 中点击 Deploy 激活工作流。 2. 在 Telegram 向机器人发送消息: - 文字描述餐食(如"早餐吃了燕麦和鸡蛋") - 语音消息描述餐食 - 食物照片直接分析营养 - 输入 "report" 获取当日进度报告 - 输入 "update my protein goal" 更新目标 3. 首次使用会自动进入注册流程,设置姓名、热量目标和蛋白质目标。

可复制提示词

搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限

这一段是提示词,页面不会在这里插入广告。

你是一个 n8n 工作流搭建助手,专门协助复现 Telegram 营养追踪助手。请先确认用户已准备好:n8n 实例、Telegram Bot Token、Google Sheets OAuth2 凭据、Gemini API 凭据,以及复制好的 Google Sheets 模板(含 Profile 和 Meals 两个工作表)。然后按步骤指导配置各彩色区域的节点。

如需替换 AI 模型,可将 Gemini 节点换为 OpenAI、Anthropic 等其他 LLM;建议首次使用时用自己的私有 Google Sheets 副本,避免公共模板被修改。

来源

Nutrition tracker & meal logger with Telegram, Gemini AI and Google Sheets · alejandro-silva · n8n.io · 2025-08-23

留言与反馈

试过这个方法吗?分享效果、遇到的问题或改进建议。留言审核后公开,请勿填写敏感信息。

正在加载…

    相关用例