š¬ Store chat data in Supabase PostgreSQL for WhatsApp/Slack chatbot
ā” 1,166 views Ā· š¬ Support Chatbots
Description
n8n Template: Store Chat Data in Supabase PostgreSQL for WhatsApp/Slack Integration
This n8n template captures chat data (like user ID, name, or address) and saves it to a Supabase PostgreSQL database. Itās built for testing now but designed to work with WhatsApp, Slack, or similar platforms later, where chat inputs arenāt predefined. Guide with images can be found on: https://github.com/JimPresting/Supabase-n8n-Self-Hosted-Integration/
Step 1: Configure Firewall Rules in Your VPC Network
To let your n8n instance talk to Supabase, add a firewall rule in your VPC network settings (e.g., Google Cloud, AWS, etc.).
-
Go to VPC Network settings.
-
Add a new firewall rule:
- Name:
allow-postgres-outbound - Direction: Egress (outbound traffic)
- Destination Filter: IPv4 ranges
- Destination IPv4 Ranges:
0.0.0.0/0(allows all; restrict to Supabase IPs for security) - Source Filter:
- Pick
IPv4 rangesand add the n8n VMās IP range, or - Pick
Noneif any VM can connect
- Pick
- Protocols and Ports:
- Protocol:
TCP - Port:
5432(default PostgreSQL port)
- Protocol:
- Name:
-
Save the rule.
Step 2: Get the Supabase Connection String
-
Log into your Supabase Dashboard.
-
Go to your project, click the Connect button in the header.
-
Copy the PostgreSQL connection string:
postgresql://postgres.fheraruzdahjd:[YOUR-PASSWORD]@aws-0-eu-central-1.pooler.supabase.com:6543/postgres- Replace
[YOUR-PASSWORD]with your Supabase account password (no brackets) and replace the string before that with your actual unique identifier. - Note the port (
6543or5432)āuse whatās in the string.
- Replace
Step 3: Set Up the n8n Workflow
This workflow takes chat data, maps it to variables, and stores it in Supabase. Itās built to handle messy chat inputs from platforms like WhatsApp or Slack in production.
Workflow Steps
-
Trigger Node: āWhen clicking āTest workflowāā (manual trigger).
- For now, itās manual. In production, this will be a WhatsApp or Slack message trigger, which wonāt have a fixed input format.
-
Set Node: āSet sample input variables (manual)ā.
- This node sets variables like
id,name,addressto mimic chat data. - Why? Chat platforms send unstructured data (e.g., a message with a userās name or address). We map it to variables so we can store it properly. The
idwill be something unique like a phone number, account ID, or account number.
- This node sets variables like
-
Sample Agent Node: Uses a model (e.g., GeminiFlash2.0 but doesnāt matter).
- This is a placeholder to process data (e.g., clean or validate it) before saving. You can skip or customize it.
-
Supabase PostgreSQL Node: āSupabase PostgreSQL Databaseā.
- Connects to Supabase using the connection string from Step 2.
- Saves the variables (
id,name,address) to a table. - Why store extra fields? The
id(like a phone number or account ID) is the key. Extra fields likenameoraddresslet us keep all user info in one place for later use (e.g., analytics or replies).
-
Output Node: āUpdate additional values e.g., name, addressā.
- Confirms the data is saved. In production, this could send a reply to the chat platform.
Why This Design?
- Handles Unstructured Chat Data: WhatsApp or Slack messages donāt have a fixed format. The āSetā node lets us map any incoming data (e.g.,
id,name) to our database fields. - Scales for Production: Using
idas a key (phone number, account ID, etc.) with extra fields likenamemakes this workflow flexible for many use cases, like user profiles or support logs. - Future-Ready: Itās built to swap the manual trigger for a real chat platform trigger without breaking.
Step 4: Configure the Supabase PostgreSQL Node
-
In the n8n workflow, set up the Supabase PostgreSQL node:
- Host:
aws-0-eu-central-1.pooler.supabase.com(from the connection string) - Port:
6543(or whatās in the connection string) - Database:
postgres - User:
postgres.fhspudlibstmpgwqmumo(from the connection string) - Password: Your Supabase password
- SSL: Enable (Supabase usually requires it)
- Host:
-
Set the node to Insert or Update:
- Map
idto a unique column in your Supabase table (e.g., phone number, account ID). - Map fields like
name,addressto their columns.
- Map
-
Test the workflow to confirm data saves correctly.
Security Tips
- Limit Firewall Rules: Donāt use
0.0.0.0/0. Find Supabaseās IP ranges in their docs and use those. - Hide Passwords: Store your Supabase password in n8nās environment variables.
- Use SSL: Enable SSL in the n8n node for secure data transfer.
š Nodes Used
Supabase, AI Agent, Google Gemini Chat Model, Postgres Chat Memory
š„ Import
Download workflow.json and import into n8n:
Workflow menu ā Import from File