Nutritional Analysis from iMessage Photos using GPT-4 Vision and Database Memory - n8n Workflow

Automate nutritional tracking with this advanced n8n workflow. It analyzes food photos sent via iMessage using GPT-4 Vision, maintains history in a Postgres database, and replies with detailed, conversational summaries. Leverage this n8n template today.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Health enthusiasts or nutrition coaches needing automated food tracking.

  • Developers looking for advanced examples of multimodal AI within an n8n template.

  • Users of Blooio seeking to integrate iMessage/SMS communication with intelligent services.

  • Anyone who wants to build sophisticated, stateful AI agents using n8n node integrations.

Overview

Keeping a reliable food log can be tedious. This sophisticated n8n workflow solves this by turning a simple iMessage photo into a detailed nutritional report, instantly. It leverages the multimodal capabilities of GPT-4 Vision to visually analyze food images, estimate portions, and calculate caloric and nutrient totals. Critically, it utilizes a Postgres database for memory, allowing the AI to generate not just a single meal analysis, but also comprehensive daily, weekly, and monthly reports based on past submissions. This n8n automation serves as an excellent example of combining communication services, cloud storage operations, and powerful AI within a single, seamless n8n workflow. This particular n8n template streamlines the entire tracking process, making nutritional analysis as easy as sending a text message.

How it Works

This powerful n8n workflow begins when the Receive Message (From Blooio) webhook n8n trigger captures an incoming message (e.g., an iMessage containing a photo).


  1. Incoming Message: The n8n trigger receives the message data from the Blooio platform.

  2. Self-Message Check: An initial 'If' n8n node (Don't respond to yourself) ensures the automation doesn't loop by responding to its own messages.

  3. Attachment Check: The If has images, download them n8n node checks if the message includes attachments (photos).

  4. Image Preparation (If Photo Exists): If an image is present, a 'Code' n8n node extracts the attachment URLs. The Loop Over Items n8n node then iterates through these URLs, and an HTTP Request n8n node downloads the binary image data into the n8n workflow context, ready for AI analysis.

  5. AI Analysis (GPT-4 Vision with Memory): The core AI Agent n8n node takes the user's text and the binary image data. It utilizes the OpenAI Chat Model (GPT-4.1-mini) for multimodal analysis. Crucially, the Postgres Chat Memory n8n node provides historical context by fetching past conversation data using the message's conversation ID as the session key, enabling the generation of daily/weekly/monthly reports.

  6. Data Aggregation: The Aggregate n8n node collects the results from the AI analysis, ensuring all generated data is combined into a single item.

  7. Final Summary Generation: A second AI Agent1 n8n node uses its own OpenAI Chat Model1 to take the aggregated nutrition data and format it into a friendly, conversational iMessage-style response, following the specified output protocol.

  8. Response Delivery: Finally, the Send Message n8n node, configured as an HTTP Request to the Blooio API, transmits the final, formatted nutrition summary back to the original sender's phone number.

Installation Guide

To deploy and use this n8n template, follow these steps:


  1. Import the n8n workflow: Copy the provided JSON data and paste it into your n8n canvas using the 'New' -> 'Import from JSON' option.

  2. Configure Blooio Credentials: You must obtain a Blooio API Token. Configure the credential for the 'Send Message' HTTP Request n8n node using the 'HTTP Bearer Auth' type. Replace YOURAPITOKEN in the Authorization header with your actual token.

  3. Configure OpenAI Credentials: Ensure your OpenAI Chat Model and OpenAI Chat Model1 n8n node instances are connected to a valid OpenAI API credential. Note that GPT-4 Vision capabilities require a model like gpt-4-turbo or similar vision-enabled models (the JSON specified gpt-4.1-mini, which must support multimodal input for this n8n workflow to function as intended).

  4. Configure PostgreSQL Credentials: Set up the connection details for the Postgres Chat Memory n8n node, pointing it to your database instance (e.g., Neon or a self-hosted Postgres) where the n8ncalorietracker table will store the memory history.

  5. Set up the Webhook: After activating the n8n workflow, note the full URL provided by the Receive Message (From Blooio) n8n trigger. You must configure this webhook URL within your Blooio account settings to ensure message events are sent to this n8n endpoint.

  6. Test: Send a photo of a meal via iMessage to your Blooio-connected number to test the full n8n automation loop.

Node Details

Receive Message (From Blooio) (Webhook n8n trigger):
Function: Serves as the starting point, listening for incoming iMessage or SMS events from the Blooio platform.
Key Configuration: Path is set to /receive-event; Method is POST.
If has images, download them (If n8n node):
Function: Controls the flow based on the presence of attachments (food photos).
Key Configuration: Checks if the length of the attachments array ($json.body.message.attachments) is greater than 0.
Code (n8n node):
Function: Prepares the data structure by extracting the attachment URLs from the input JSON for download.
Key Configuration: Custom JavaScript to iterate and create new items containing only the url.
HTTP Request (n8n node):
Function: Downloads the image binary data from the extracted URL, essential for the AI Agent to perform visual analysis.
Key Configuration: Uses the dynamic URL ={{ $json.url }}.
AI Agent (n8n node):
Function: The central intelligence unit. It processes the text and downloaded image using GPT-4 Vision to perform detailed nutritional analysis and generates the report.
Key Configuration: Uses the OpenAI Chat Model and includes specific system instructions for nutritional analysis, confidence scoring, health rating, and requesting daily/weekly/monthly reports. It passes binary images through (passthroughBinaryImages: true).
Postgres Chat Memory (n8n node):
Function: Provides statefulness to the conversation by storing historical interactions in a PostgreSQL table (n8ncalorietracker), allowing the AI Agent to provide cumulative reports.
Key Configuration: Session Key is dynamically set using the Blooio conversation ID (={{ $('Receive Message (From Blooio)').item.json.body.message.conversation.id }}).
Send Message (HTTP Request n8n node):
Function: The final action, sending the AI-generated nutritional summary back to the user via the Blooio API.
* Key Configuration: Uses the recipient identifier (={{ $('Receive Message (From Blooio)').item.json.body.message.sender }}) and the AI output (={{ $json.output }}) in the request body.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by

Featured*