Build an AI Second Brain in Telegram with n8n and Supabase
A complete walkthrough of the AI Second Brain I use daily — a Telegram bot that captures anything I send it, searches my memories semantically instead of by keyword, and resurfaces important items using spaced repetition. Two n8n workflows, one Supabase table, and around $2-5 a month in OpenAI credits.
What you'll learn
Learning outcomes
n8n workflow implementation & automation
supabase workflow implementation & automation
telegram-bot workflow implementation & automation
ai-automation workflow implementation & automation
openai workflow implementation & automation
second-brain workflow implementation & automation
spaced-repetition workflow implementation & automation
no-code workflow implementation & automation
tutorial workflow implementation & automation
I learn something new almost every day, and I forget almost all of it. A tool I found on Monday, an idea I had in the shower, a link a friend sent me — by Friday it's gone.
I've tried every notes app you can name. The problem was never the app. The problem is that I never go back and look. Capturing was easy; retrieving was the part that never happened.
So I stopped taking notes and built a second brain that lives inside Telegram instead. I text it anything — a link, a random thought, a voice note at 2 in the morning — and it remembers all of it. Not by keywords, but by meaning. Weeks later I can ask a vague, half-remembered question and it pulls the exact thing back.
This post walks through the entire build. Two n8n workflows, one Supabase table, and around $2-5 a month in OpenAI credits.
What the system actually does
The bot handles four intents, and it figures out which one you mean automatically — you never type a command.
Save. Send it anything. It generates a summary, auto-tags it, creates a vector embedding, and stores everything in Supabase. It replies with the summary so you can confirm it understood.
Search. Ask a question in plain language. It embeds your query, runs a similarity search against everything you've saved, and writes a natural-language answer from the results. "That video editing tool I found" finds a note about a specific product, because the embeddings are semantically close even though no words overlap.
Remind. Tell it to remind you about something. It saves the memory like normal but flags it for the reminder engine, which uses spaced repetition — the interval doubles each time so important things resurface without becoming noise.
Dismiss. Tell it to stop reminding you. It uses the same semantic search to figure out which reminder you mean, so you don't need to remember exact wording.
Architecture
Four components, and only one of them costs money.
Telegram Bot → n8n (self-hosted) → OpenAI (intent + embeddings) → Supabase (pgvector)
↓
Cron Trigger → Reminder EngineTelegram is just the interface. You could swap it for WhatsApp, Slack, or Discord without changing anything else. I picked Telegram because bots are free and take about ninety seconds to create.
n8n is the orchestration layer. Two workflows: a main one that handles every message sent to the bot, and a cron-triggered one that fires reminders twice a day.
OpenAI does two jobs. gpt-4o-mini handles intent detection, summarization, and response formatting. text-embedding-3-small generates the 1536-dimension vectors that power semantic search. Both are cheap enough that heavy daily use lands around $2-5/month.
Supabase is the memory. PostgreSQL with the pgvector extension enabled, so every memory is stored alongside its embedding and can be searched by meaning.
Total cost: Supabase free tier, n8n self-hosted on a VPS, and a small OpenAI bill.
Step 1 — Create the Telegram bot
Open Telegram and message @BotFather. Send /newbot, pick a display name, then pick a username ending in bot.
BotFather gives you an API token. Save it — you'll need it in n8n, and it's the only credential that lets anything talk to your bot.
Send your new bot a message so the chat exists. n8n needs an active conversation to receive updates.
Step 2 — Set up Supabase
Create a free Supabase project. Pick a region close to you and set a database password.
Enable pgvector
Go to Database → Extensions, search for vector, and enable it. This is what lets Postgres store embeddings and run similarity searches.
Create the memories table
Open the SQL editor and run this:
create table memories (
id uuid default gen_random_uuid() primary key,
content text not null,
summary text,
tags text[],
embedding vector(1536),
remind boolean default false,
remind_interval integer default 1,
last_reminded_at timestamptz,
next_remind_at timestamptz,
dismissed boolean default false,
created_at timestamptz default now()
);What each column does:
content— the raw text you sent the botsummary— the condensed version OpenAI generatestags— auto-generated categories, stored as a text arrayembedding— a 1536-dimension vector, matching the output size oftext-embedding-3-smallremind/remind_interval/next_remind_at/last_reminded_at/dismissed— the spaced repetition state
The reminder interval starts at 1 day and doubles each cycle: 1, 2, 4, 8. If something's genuinely important you'll act on it early. If you keep ignoring it, the gaps widen so it never turns into notification spam.
Create the similarity search function
Semantic search needs a database function that takes a query embedding and returns the closest matches by cosine distance:
create or replace function match_memories (
query_embedding vector(1536),
match_threshold float,
match_count int
)
returns table (
id uuid,
content text,
summary text,
tags text[],
created_at timestamptz,
similarity float
)
language sql stable
as $$
select
memories.id,
memories.content,
memories.summary,
memories.tags,
memories.created_at,
1 - (memories.embedding <=> query_embedding) as similarity
from memories
where 1 - (memories.embedding <=> query_embedding) > match_threshold
and memories.dismissed = false
order by memories.embedding <=> query_embedding
limit match_count;
$$;The <=> operator is pgvector's cosine distance. Subtracting from 1 converts it to a similarity score, where higher is better. A threshold around 0.7 works well in practice — lower and you get noise, higher and vague queries stop matching.
Grab your credentials
Go to Project Settings → API and copy the project URL and the anon key. Both go into n8n.
Step 3 — Build the main workflow
This is the 20-node workflow. It looks dense on the canvas, but structurally it's one router feeding four branches.
Telegram Trigger
Add a Telegram Trigger node and connect it with your BotFather token. Every message sent to the bot enters here.
Intent detection
Add an OpenAI node using gpt-4o-mini. The system prompt is deliberately minimal:
You are an intent classifier. Given the user's message, respond with exactly one word: save, search, remind, or dismiss. Return nothing else.
This is the most important design decision in the whole build. The temptation is to make this node do summarization and tagging and classification all at once. Don't. One job, one output, one word. It's more reliable and far easier to debug when something misroutes.
Switch node
Route on the classifier's output — four outputs, one per intent.
The SAVE branch
OpenAI — generate a summary and tags from the message content
OpenAI — generate the embedding with
text-embedding-3-smallSupabase Insert — write content, summary, tags, and embedding to the
memoriestableTelegram Send — confirm back to the user with the summary and tags
Showing the summary in the confirmation matters. It's how you catch a bad interpretation immediately rather than discovering it weeks later when a search fails.
The SEARCH branch
OpenAI — embed the user's question
Supabase RPC — call
match_memorieswith that embeddingOpenAI — take the raw rows and write a natural-language answer
Telegram Send — return it
This is the branch that makes the system feel like magic. You aren't matching keywords — you're matching meaning. The final formatting call is what turns a database result set into something that reads like an answer from a person rather than a query dump.
The REMIND branch
OpenAI — extract what to remind about, generate summary and embedding
Supabase Insert — store it with
remind = trueandnext_remind_atset to three hours from nowTelegram Send — confirm the reminder is set
Identical to the save branch, plus two flags. The reminder engine takes it from there.
The DISMISS branch
OpenAI — embed what the user wants to dismiss
Supabase RPC — find the closest match where
remind = trueSupabase Update — set
dismissed = trueTelegram Send — confirm
Because dismissal runs through the same semantic search, you can say "stop reminding me about that client thing" and it finds the right row without you remembering how you originally phrased it.
Step 4 — Build the reminder engine
Second workflow, seven nodes, runs on a schedule.
Cron Trigger
I run mine twice a day at 3 PM and 7 PM IST. Adjust to whenever you actually check your phone — a reminder that fires while you're asleep is a reminder you'll dismiss without reading.
Supabase Query
Fetch every memory where remind = true, dismissed = false, and next_remind_at is in the past.
Loop and format
For each due row, send the summary to OpenAI and have it write a short, friendly reminder. Something like:
Just a nudge — you wanted to follow up on the client proposal. You saved this 3 days ago.
The age reference matters more than it sounds. Knowing how long something has been sitting there is usually what pushes you to finally deal with it.
Telegram Send
Deliver the formatted message.
Supabase Update
After sending, update two fields: set last_reminded_at to now, and set next_remind_at to now plus the doubled interval. Write the doubled value back to remind_interval so the next cycle continues expanding.
That's the entire spaced repetition mechanism. Five lines of logic.
What I'd change if I built it again
Voice notes. Telegram delivers voice messages as files. Piping them through Whisper before the intent classifier would make 2 AM capture genuinely frictionless. It's the next thing I'm adding.
A weekly digest. Something that surfaces five things you saved and never revisited. The reminder engine handles explicit reminders well, but passively saved memories still go quiet.
Deduplication. Right now, saving the same link twice creates two rows. Checking for a high-similarity match before inserting would fix it in one extra node.
Cost breakdown
Supabase — Free tier
n8n — Self-hosted (VPS you likely already have)
Telegram Bot API — Free
OpenAI (
gpt-4o-mini+text-embedding-3-small) — ~$2-5/month
The OpenAI figure reflects daily personal use. Embeddings are the cheap part; the intent and formatting calls make up most of it, and gpt-4o-mini is inexpensive enough that heavier usage barely moves the number.
Why this one stuck
I've abandoned every knowledge system I've ever set up, and this one is the first that survived past a month. The reason isn't the vector search or the spaced repetition. It's that there's nothing to open.
Telegram is already on my home screen and already open. Saving something costs one message. The system meets me where I already am instead of asking me to visit it — and that turns out to be the only feature that actually matters.
Resources & Downloads
Ready to build this for your business?
I help ambitious founders and businesses build production-ready automation systems. Let's discuss your specific needs.
Book a Strategy CallRelated Tutorials

FREE Claude Code + Claude Desktop Setup With Official Anthropic Models (2026 Guide)
Learn how to set up Claude Code and Claude Desktop for free using official Anthropic models including Claude Fable 5, Sonnet 5, Opus 4.8, and Sonnet 4.6. Full step-by-step tutorial with gateway configuration, API keys, and VS Code integration.

The AI Video Trend Blowing Up Instagram - How to Copy It and Get Brand Deals
Faceless Instagram pages are going viral with AI generated videos and landing brand deals — and most people have no idea how it's done. In this tutorial I break down the exact workflow using Higgsfield, GPT Image 2, and Seedance 2.0 to create these videos from scratch and show you how to turn them into a monetized Instagram page.

FREE + 20,000 OpenArt Credits | The Craziest AI Offer I've Ever Seen
OpenArt is giving away 20,000 free credits to anyone who signs up and in this step by step guide I am showing you exactly how to claim yours without a credit card or any hidden fees.