ChatGPTLife adminHealthAI score · PendingAI-assisted edit · no obvious prompt-injection riskn8n.io

Track nutrition and fitness via webhook with OpenAI, Google Sheets and Slack alerts

Webhook receives user input → AI analyzes food/activity → Google Sheets updates → Slack alerts on limits/risks → daily scheduled reset

Some experienceStepsWorkflowPromptTip
Who
Fitness app developers, health platform operators, personal trainers, nutritionists, automation engineers who need automated diet and activity tracking
You get
After a user sends a food or activity description, the system automatically estimates calories and protein, updates the daily summary in Google Sheets, sends Slack alerts when thresholds are exceeded or health risks are detected, and resets statistics daily via schedule trigger
You need
n8n · google-sheets · slack

Constraints

Prerequisites: n8n instance (self-hosted or cloud), structured Google Sheets with 9 columns (Name, Phone, Goal, Daily_Calorie_Target, Consumed_Calories, Protein, Last_Meal, Status, Risk_Count), OpenAI API credentials, Slack workspace API access. After importing the workflow JSON into n8n, replace document ID, Sheet ID, Slack channel IDs, and credentials per node instructions.

What they did

Template author weblineindia built a workflow in n8n that receives food or activity descriptions via Webhook, pulls user profiles from Google Sheets and validates existence, uses an OpenAI model to analyze input type and estimate nutrition data, accumulates statistics through a Code node, checks calorie thresholds and health risks to send tiered Slack alerts, writes updated data back to Google Sheets, and returns a JSON response to the user. A separate Schedule Trigger branch resets all users' daily statistics automatically.

How it went

The author reports the template enables real-time nutrition tracking, automated alerts, and daily resets (author_report). No specific runtime data or ROI is provided.

Worth knowing

1) AI-returned calories and protein are estimates, not medically precise data—human review is advised; 2) The Google Sheets document ID, Sheet ID, and Slack channel IDs in the template are the author's private values and must be replaced; 3) The Code node includes JSON.parse fallback: non-standard JSON from AI degrades to UNKNOWN type; 4) The daily reset branch runs independently from the main flow; 5) This site has not tested the workflow; test end-to-end with sample Webhook data after setup.

n8n workflow template

Structure checked · Not run-tested

Use “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.

Setup and test checklist

Credentials to connect

  • Fetch User Data node: connect Google Sheets OAuth2 credentials.
  • AI Model (GPT) node: connect OpenAI API credentials.
  • Alert: Calorie Limit Exceeded node: connect Slack API credentials.
  • Alert: Health Risk node: connect Slack API credentials.
  • Alert: Critical Health Issue node: connect Slack API credentials.
  • Update User Data node: connect Google Sheets OAuth2 credentials.
  • Fetch All Users node: connect Google Sheets OAuth2 credentials.
  • Reset Daily Stats node: connect Google Sheets OAuth2 credentials.

Configuration to replace

  • Source template is n8n public workflow #14858 (~25 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
  • Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.

Test input and expected output

  • Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
  • Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.

Template changes

  • Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
  • No business-logic edits; verify keys, quotas and privacy compliance before use.

Template retrieved: 2026-10-25

Steps

  1. Configure Webhook to receive user input

    Add a Webhook node (Receive User Input) in n8n, set path to e.g. /diet-input, and set responseMode to responseNode. This endpoint will receive POST requests containing phone and message.

  2. Connect Google Sheets and map user data

    Add a Google Sheets node (Fetch User Data), select Search operation, match the Phone column against incoming body.phone. Enter your document ID and sheet name, ensuring column names match the template.

  3. Validate user exists

    Add an If node (Validate User Exists), check whether the previous output object exists ($json exists). Only continue if the user is found in the sheet, avoiding unnecessary AI processing for unregistered users.

  4. Configure AI Nutrition Analyzer

    Add an AI Agent node (AI Nutrition Analyzer), set promptType to define, and paste the following prompt into the Text field. This node must be connected to an OpenAI Chat Model sub-node.

    Execution prompt · Source text。AI Nutrition Analyzer node Text field (promptType=define)

    =You are an advanced nutrition and fitness AI.
    
    User Goal: {{ $json.Goal }}
    Daily Calorie Target: {{ $json.Daily_Calorie_Target }}
    
    User Input:
    "{{ $('Receive User Input').item.json.body.message }}"
    
    Tasks:
    1. Detect type:
       - FOOD
       - ACTIVITY
       - UNKNOWN
    
    2. If FOOD:
       - Estimate calories
       - Estimate protein
       - Detect meal type (breakfast/lunch/dinner/snack)
    
    3. If ACTIVITY:
       - Estimate calories burned
    
    4. Detect risk:
       - OVER_EATING
       - LOW_PROTEIN
       - UNHEALTHY
       - NONE
    
    Return STRICT JSON:
    
    {
      "type": "FOOD | ACTIVITY | UNKNOWN",
      "calories": number,
      "protein": number,
      "calories_burned": number,
      "meal_type": "breakfast | lunch | dinner | snack",
      "risk": "NONE | OVER_EATING | LOW_PROTEIN | UNHEALTHY",
      "suggestion": "short advice",
      "reply": "friendly message"
    }
  5. Configure AI model and credentials

    Add an OpenAI Chat Model sub-node (AI Model (GPT)), select gpt-4.1-mini (or gpt-4.1 / gpt-4), and connect OpenAI API credentials. Ensure the credential is active and has available quota.

  6. Process nutrition data

    Add a Code node (Process Nutrition Data), and run the following JavaScript to merge AI-returned JSON with existing user data, calculating cumulative calories, protein, and risk count.

    Execution prompt · Source text。Process Nutrition Data node JS Code field

    const raw = $input.first().json.output;
    
    let parsed;
    
    try {
      parsed = JSON.parse(raw);
    } catch (e) {
      parsed = {
        type: "UNKNOWN",
        calories: 0,
        protein: 0,
        calories_burned: 0,
        risk: "NONE",
        suggestion: "AI parsing failed",
        reply: "Sorry, I couldn't understand. Try again."
      };
    }
    
    // Get user data
    let user = $('Fetch User Data').first().json;
    
    let totalCalories = parseInt(user.Consumed_Calories || 0);
    let protein = parseInt(user.Protein || 0);
    let riskCount = parseInt(user.Risk_Count || 0);
    
    // FOOD
    if (parsed.type === "FOOD") {
      totalCalories += parsed.calories;
      protein += parsed.protein;
    }
    
    // ACTIVITY
    if (parsed.type === "ACTIVITY") {
      totalCalories -= parsed.calories_burned;
    }
    
    // Risk tracking
    if (parsed.risk !== "NONE") {
      riskCount += 1;
    }
    
    return [{
      json: {
        ...user,
        ...parsed,
        Consumed_Calories: totalCalories,
        Protein: protein,
        Risk_Count: riskCount,
        message: $('Receive User Input').first().json.body.message
      }
    }];
  7. Check calorie threshold and alert

    Add an If node (Check Calorie Threshold), checking if Consumed_Calories > Daily_Calorie_Target. If exceeded, trigger a Slack node (Alert: Calorie Limit Exceeded) to send an alert.

    Execution prompt · Source text。Alert: Calorie Limit Exceeded node Text field

    =You have exceeded your daily calorie limit.  Consumed: {{ $('Process Nutrition Data').item.json.Consumed_Calories }} Target: {{ $('Process Nutrition Data').item.json.Daily_Calorie_Target }}
    {{ $('Process Nutrition Data').item.json.suggestion }}
    
    
    
    Calorie Limit Exceeded
    
    User: {{$json.Name}}
    Consumed: {{$json.Consumed_Calories}}
    Target: {{$json.Daily_Calorie_Target}}
    
    {{$json.suggestion}}
  8. Detect health risks and escalate alerts

    Add an If node (Check Health Risk) checking if risk != 'NONE', triggering a Slack node (Alert: Health Risk). Then add an If node (Check Critical Risk) checking if Risk_Count >= 3, triggering a Slack node (Alert: Critical Health Issue) for critical escalation.

    Execution prompt · Source text。Alert: Health Risk node Text field

    =Health Risk Detected  User: {{ $('Process Nutrition Data').item.json.Name }} Risk: {{ $('Process Nutrition Data').item.json.risk }}  
    {{ $('Process Nutrition Data').item.json.suggestion }}

    Execution prompt · Source text。Alert: Critical Health Issue node Text field

    =CRITICAL ALERT  User: {{ $('Process Nutrition Data').item.json.Name }} Multiple unhealthy patterns detected.  Immediate attention required.
  9. Return API response and update user data

    Add a Respond to Webhook node (Send API Response), returning JSON with the AI reply, this meal's calories, and today's total. Then add a Google Sheets node (Update User Data), select Update operation, match by Phone column, and write back Consumed_Calories, Protein, Risk_Count, Status, and Last_Meal.

  10. Configure daily scheduled reset

    Add a Schedule Trigger node (Daily Reset Trigger), set the daily execution time. Connect to a Google Sheets node (Fetch All Users) to read all users, then to a Google Sheets node (Reset Daily Stats) with Update operation, matching by Phone, resetting Consumed_Calories, Protein, Risk_Count to 0 and Status to NEW_DAY.

Prompt you can copy

Setup guidance · Editorial suggestion。Hand to setup assistant to confirm inputs and permissions before step-by-step reproduction

This block is the prompt. Ads are never placed here.

You are setting up an n8n AI nutrition tracking workflow. First confirm you have: 1) an n8n instance; 2) a Google Sheets with correct column names; 3) OpenAI API credentials; 4) Slack API credentials. Then import the workflow JSON or create nodes manually, replacing all document IDs, Sheet IDs, channel IDs, and credential references.

Verify Google Sheets column names match the template exactly before connecting credentials

Source

Track nutrition and fitness via webhook with OpenAI, Google Sheets and Slack alerts · weblineindia · n8n.io · 2026-04-07

Comments & feedback

Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.

Loading…

    Related