Add a free, bilingual AI chatbot to your landing page — grounded in your business plan.
Follow along with your own business — one step at a time.
Answers only from your business facts — and guides visitors toward contact.
Those facts are the context. Supplying them is grounding.
Your knowledge base is glued into the system instruction on every request.
Left: you paste (or fetch) your business docs into the knowledge base. Right: the chat reads it to answer every question.
Anyone can view source, copy your key, and spend your quota.
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 chat bubble your customers type into.
Secure middleman that calls Gemini and hides your key.
A Supabase table of your business docs — the context, one row per source.
Where you paste, summarize, and update those docs.
The free AI model that writes the answers.
Done — the Lovable site from the previous class. ✓
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.
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.
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.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).
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.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."Free tier: ~1,500 messages/day. Public info only — never paste customer data or secrets into the knowledge base.
Context is the whole game: update the knowledge → the bot keeps up. The same 5 steps work for any business.