Live build · Lovable + Supabase + Gemini

Give your business
a 24/7 assistant.

Add a free, bilingual AI chatbot to your landing page — grounded in your business plan.

Rodolfo Capdevilla, Ph.D.  ·  Part 2 — after “Build a Landing Page”
start  ·  back  ·  F fullscreen  ·  S speaker notes
Where we are

You built a landing page.
Now put someone behind the counter.

Follow along with your own business — one step at a time.

The goal

A salesperson that
never sleeps.

Answers only from your business facts — and guides visitors toward contact.

Why bother

What it does for a business.

First, the big idea

The AI doesn’t know
your business.

Those facts are the context. Supplying them is grounding.

How you “teach” it

You don’t train it.
You hand it the facts.

Under the hood

Every question is one big prompt.

System instruction
Rules — who the bot is, what it may and may not do
+ Your business knowledge — strategy report, FAQs, pricing (the context)
Conversation
the chat so far — what the customer asked
↓  Gemini reads all of it  ↓
Reply
A grounded answer — from your facts, not a guess.

Your knowledge base is glued into the system instruction on every request.

The plan

One knowledge base that
mirrors your business.

Your sources · Strategy report· Website· FAQs & pricing· Video notes ✎ Admin page paste · summarize you keep it fresh 📁 Knowledge base Supabase · the context 🔒 Chat function Gemini Website widget the customer reads

Left: you paste (or fetch) your business docs into the knowledge base. Right: the chat reads it to answer every question.

The one rule

Never put your key
in the browser.

✕ Key in the website

Anyone can view source, copy your key, and spend your quota.

✓ Key in the Edge Function

The key lives on the server, hidden from visitors. The site only talks to your safe middleman.

That’s why we add a tiny backend (Supabase) in Step 2.

The parts

What you’re about to build.

Frontend

The widget

The chat bubble your customers type into.

Backend

Chat function

Secure middleman that calls Gemini and hides your key.

Content

Knowledge base

A Supabase table of your business docs — the context, one row per source.

Admin

Knowledge page

Where you paste, summarize, and update those docs.

Model

Gemini 3.5 Flash

The free AI model that writes the answers.

Setup · 2 minutes

Before we start.

1 · Your landing page

Done — the Lovable site from the previous class. ✓

2 · A free Gemini key

aistudio.google.com → “Get API key” → Create → Copy.

Free, no credit card. Keep the key handy for Step 2. Also have your strategy report (from NotebookLM) and any FAQ / pricing text ready to paste in Step 3.

Step 1 / 5

Add the chat widget.

What you’ll see: a chat bubble appears. It opens, but doesn’t answer yet.

Add a floating chat widget to my site.
- Bottom-right: a round 56px button with a chat icon.
- Clicking it opens a panel (~380x560px) anchored bottom-right, with:
  1) a header "Ask [[BUSINESS NAME]]" and a close (X) button,
  2) a scrollable messages area,
  3) a text input with a Send button.
- Match my site's style: white panel, thin border, 14px corners, my accent color for
  the button and Send. User messages right in a light bubble; assistant messages left in gray.
- No backend yet: when the user sends, show a placeholder reply "Connecting soon...".
- Responsive (near full-screen on mobile), focus the input on open, close on Escape.
Step 2 / 5

Add the secure backend.

Lovable will ask to connect Supabase, then to paste your GEMINI_API_KEY.

Connect Supabase, then create an Edge Function named "chat" that securely calls Google Gemini.
- Read the key from a secret named GEMINI_API_KEY (never expose it to the browser).
- Accept POST JSON: { "messages": [ { "role": "user" | "assistant", "text": "..." } ] }.
- Send the conversation to model "gemini-3.5-flash"
  (https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent)
  with a system instruction. For now use a placeholder: "You are a helpful assistant."
- Return JSON: { "reply": "..." }. Add CORS headers and error handling.
Then prompt me to enter the GEMINI_API_KEY secret.
Step 3 / 5 · the heart of it

Build the knowledge base.

A table for your business docs + an admin page to paste and update them. Big step — Lovable may take a couple of tries.

Create a Supabase table "knowledge" (source text primary key, content text,
updated_at timestamptz default now()) - the chatbot's knowledge base, one row per source.

Create a simple admin page at /knowledge (with a small link in the site footer) where I can:
- add or edit a source: a short name plus a large text area to paste the content,
- save it (upsert) and see all sources with their last-updated time,
- protect the page with a simple passcode I set.

Add a "Summarize with AI" button next to the text area: it sends the pasted text to
Gemini (through an edge function, using the GEMINI_API_KEY secret) and replaces it
with a clean, factual summary I can review before saving.

Also add a "Fetch my website" button that downloads the text of my site's pages,
strips the HTML, and saves it as the "website" source.

I will paste sources like: "strategy-report" (my business strategy report from
NotebookLM), "faq", "pricing", and "video-notes" (notes from tutorials and videos).
Step 4 / 5

Feed it to the bot.

Now it answers about your business, grounded in the knowledge base, in English or Spanish.

Two things:
(1) Connect the widget to the "chat" function: keep the full conversation in state and send it
    every message; show a typing indicator; disable Send while waiting; on error show
    "Sorry, something went wrong - please try again."
(2) In the "chat" function, on every request read ALL rows of the "knowledge" table and inject
    them into the system instruction:

"You are the friendly assistant on the website of [[BUSINESS NAME]], [[one line on what it
does, e.g. 'a yacht dealership in Miami']]. Rules: use ONLY the business knowledge below;
never invent prices, availability, or policies; if something isn't covered, say so and invite
the visitor to use the contact form; detect the visitor's language and reply in it (English
or Spanish); keep answers short and friendly; when a visitor shows real interest, guide them
to the contact form.
BUSINESS KNOWLEDGE (source of truth):
[insert every knowledge.content, each labeled with its source]"

If gemini-3.5-flash errors or is rate-limited, retry once with gemini-3.1-flash-lite.
Step 5 / 5

Polish it.

Starter questions, streaming text, clean on phones.

Polish the chat widget:
- When empty, show 3 clickable starter chips ("What do you offer?",
  "How much does it cost?", "¿Hablan español?") that send on click.
- Stream the reply so text appears progressively (Gemini :streamGenerateContent);
  otherwise keep the typing indicator.
- Great on mobile and desktop, matches my site, auto-scroll to the newest message.
- Small line under the input: "AI assistant - may be imperfect."
Safety net

If something breaks (it’s normal).

Try it — like a customer

Test in 60 seconds.

Free tier: ~1,500 messages/day. Public info only — never paste customer data or secrets into the knowledge base.

Recap

Your plan became an employee.

Context is the whole game: update the knowledge → the bot keeps up. The same 5 steps work for any business.

What’s next

Make it sell.

¡Gracias! · Questions?

Rodolfo Capdevilla, Ph.D.
Business Chatbot Class Title
1 / 20