/how-to-build-lovable

How to build SMS notification system with Lovable?

Step-by-step guide to build a scalable SMS notification system with Lovable. Integrate APIs, manage delivery, retries, templates and analytics.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to build SMS notification system with Lovable?

Quick answer: Build the SMS system as a two-part flow in Lovable — a safe in-preview UI + mock sender you can use immediately in Lovable Preview, and a real server-side sender (Supabase Edge Function using Twilio credentials) stored in the repo and deployed outside Lovable (via GitHub export + supabase CLI). In Lovable you’ll add UI components and a mock handler, configure Twilio secrets in Lovable Cloud Secrets, and add the real function code files so they live with your app and can be deployed from GitHub.

 

Lovable-native approach (what you’ll do in Chat Mode + Preview + Publish)

 

What we do in Lovable: Use Chat Mode edits to add a client SMS form component and a mock sender that runs in Preview (no credentials exposed). Add the real server function source code (supabase/functions/send-sms/index.ts) that uses Twilio and environment variables. Use Lovable Cloud Secrets UI to store Twilio creds. Preview shows simulated sends. When ready, export/sync to GitHub and deploy the Supabase function with the supabase CLI (outside Lovable).

  • No terminal inside Lovable: real deployment of the Supabase function is labeled outside Lovable (terminal required). Lovable holds the code and secrets securely; deployment happens via GitHub sync + your CLI/CI.

 

Meta-prompts to paste into Lovable (paste each as its own Chat Mode message)

 

Prompt 1 — Add client SMS form + mock sender

 

Goal: Add a simple SMS form to the app and a mock sender used in Preview so you can test without sending real SMS.

  • Files to create: create src/components/SmsForm.tsx and src/lib/smsClient.ts
  • Edit: update src/App.tsx (or your app root page) to import and render <SmsForm /> on the main route or homepage.
  • Acceptance criteria: Done when Lovable Preview shows a form with phone, message, and "Send" button; clicking Send displays "Preview: SMS simulated to +1..." and writes an entry to the page log (no real outbound request).

Prompt text for Lovable (paste into Chat Mode):

// Goal: add client SMS form and a mock sender for Preview
// Create src/components/SmsForm.tsx with a small form (phone, message, send button).
// Create src/lib/smsClient.ts with a function sendSms({to, body}) that detects Preview by checking process.env.NODE_ENV === 'development' || window.location.hostname.includes('lovable') and returns a simulated success object.
// Update src/App.tsx: import SmsForm and render it on the main page (wrap with minimal UI).
// Acceptance: Preview shows the form; pressing Send shows a simulated success message and a log entry.

 

Prompt 2 — Add server-side Twilio sender (Supabase Edge Function source)

 

Goal: Add a server-side function that sends SMS via Twilio. This file will live in the repo so you can deploy it to Supabase later.

  • Files to create: create supabase/functions/send-sms/index.ts
  • Contents: code that reads TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO\_FROM from env and POSTs to Twilio API to create an SMS. Use fetch or Twilio HTTP API calls. Include input validation and return JSON status.
  • Acceptance criteria: Done when file exists in repo and uses env variables (no literal secrets). The client code should be ready to call the function URL (once deployed).
  • Note: Deploying this function to Supabase requires the supabase CLI — see deployment step below (outside Lovable).

Prompt text for Lovable (paste into Chat Mode):

// Goal: create Supabase Edge Function source for sending SMS via Twilio
// Create file supabase/functions/send-sms/index.ts
// The function should:
//  - accept JSON { to, body }
//  - read TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_FROM from environment
//  - call Twilio REST API to create a message
//  - return { ok: true, sid } or { ok: false, error }
// Do not add secrets here. Acceptance: file exists and uses process.env variables.

 

Prompt 3 — Add README + Secrets instructions

 

Goal: Add short README steps and prompt Lovable to create instructions to set Secrets in Lovable Cloud and to export/sync to GitHub for deployment.

  • Files to create: create SMS\_README.md at project root
  • Acceptance criteria: README explains which Lovable Secrets to set (TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO\_FROM), how to test in Preview, and explicit "outside Lovable" Supabase deploy commands.

Prompt text for Lovable (paste into Chat Mode):

// Goal: add SMS_README.md with exact steps
// Create SMS_README.md describing:
//  - Lovable Cloud Secrets to set: TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_FROM
//  - How to test in Preview (use the form -> simulated send)
//  - How to export to GitHub and deploy Supabase Edge Function (outside Lovable): `supabase functions deploy send-sms --project-ref YOUR_REF` (labelled outside Lovable)
// Acceptance: file present with those exact instructions.

 

How to verify in Lovable Preview

 

  • Open Preview; the homepage should show the SMS form.
  • Enter a phone number and message; click Send. You should see “Preview: SMS simulated to …” and a page log entry. No external SMS provider is contacted in Preview.

 

How to Publish / re-publish

 

  • Publish UI: Use Lovable’s Publish button to push the frontend (includes the mock). This makes the app live with simulated sends only.
  • Deploy server (real sending): Sync/export to GitHub from Lovable, then on your machine or CI use supabase CLI to deploy supabase/functions/send-sms. This step is outside Lovable (terminal required).

 

Secrets / Integration setup steps

 

  • In Lovable Cloud Secrets UI add TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO\_FROM (don’t put them in code).
  • If using Supabase also ensure you have the project ref and supabase URL/keys for deployment; but only Twilio creds are required for the function.

 

Common pitfalls (and how to avoid them)

 

  • Exposing Twilio creds in the client: never call Twilio directly from browser — always use server-side function. Use Lovable Secrets.
  • Assuming Preview is real: Preview uses the mock sender. Real SMS are only sent after you deploy the server function externally.
  • Forgetting to deploy: adding the function file in Lovable does not deploy it; you must export to GitHub and run supabase functions deploy from your terminal or CI.

 

Validity bar

 

This flow is strictly Lovable-native where possible: UI and mock sender are implemented and testable inside Lovable Preview; Secrets are configured in Lovable Cloud. The actual Twilio send code lives in repo files and must be deployed to Supabase (or another serverless host) via GitHub + CLI — that deploy step is correctly labelled as outside Lovable because Lovable has no terminal.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

How to add SMS delivery-receipt webhook & status endpoint

This prompt helps an AI assistant understand your setup and guide to build the feature

AI AI Prompt

How to add per-number SMS rate limiter + reservation endpoint

This prompt helps an AI assistant understand your setup and guide to build the feature

AI AI Prompt

How to add an SMS segmenter & preview endpoint

This prompt helps an AI assistant understand your setup and guide to build the feature

AI AI Prompt

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation
Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

Best Practices for Building a SMS notification system with AI Code Generators

Use Lovable to build a small serverless endpoint that composes SMS with an AI model, stores/send events through a provider like Twilio, keep all API keys in Lovable Secrets, test via Preview, and deploy via Publish or GitHub sync. Mind consent, PII, rate limits, retry/backoff, and prefer queued delivery (Supabase or external worker) for reliability.

 

High-level workflow

 

From user/event → AI generator → queue/store → SMS provider → delivery status. Build each piece as a small, testable function in Lovable, store keys in Secrets, use Preview to hit your endpoints, and export to GitHub when you need package installs, scheduled jobs, or custom CI.

  • AI composition — call OpenAI (or other) from a server-side endpoint, not client-side, to keep keys secret.
  • Persistence/Queue — record messages and statuses in Supabase or a DB so you can retry and audit.
  • Delivery — use Twilio/Vonage SDK to send SMS. Keep a fallback provider for failures.
  • Secrets — add OPENAI_API_KEY, TWILIO\_\* etc. in Lovable Secrets UI (no CLI).
  • Testing — use Preview to POST to your endpoint; use Publish or GitHub sync to run in production.

 

Practical checklist in Lovable

 

  • Create files via Chat Mode edits (endpoint code, package.json).
  • Add secrets in Lovable Secrets UI: OPENAI_API_KEY, TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_FROM, SUPABASE_URL/KEY.
  • Use Preview to test your HTTP endpoints (Preview provides a reachable URL for webhooks).
  • Publish to Lovable Cloud for a stable URL, or sync to GitHub to run CI and install npm packages (no terminal inside Lovable).
  • For scheduled jobs, use GitHub Actions cron or Supabase scheduled functions — Lovable itself doesn’t provide a terminal to run cron jobs.

 

Example: minimal serverless endpoint (Node) that uses OpenAI to compose and Twilio to send

 

// api/send-sms.js

// // This is a server-side endpoint file. Save dependencies in package.json: twilio and node-fetch (or use native fetch in Node 18+).

const fetch = require('node-fetch'); // // or global fetch in newer Node runtimes
const twilio = require('twilio');

module.exports = async (req, res) => {
  try {
    // // Basic validation
    const { to, context } = req.body;
    if (!to) return res.status(400).json({ error: 'missing "to" number' });

    // // Generate SMS text with OpenAI
    const openaiResp = await fetch('https://api.openai.com/v1/chat/completions', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        model: 'gpt-3.5-turbo',
        messages: [
          { role: 'system', content: 'Write a short friendly SMS <=160 chars, no PII.' },
          { role: 'user', content: `Context: ${context || 'generic notification'}` }
        ],
        max_tokens: 60
      })
    });
    const data = await openaiResp.json();
    const text = data.choices?.[0]?.message?.content?.trim() || 'Hello!';

    // // Send SMS via Twilio
    const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
    await client.messages.create({ body: text, from: process.env.TWILIO_FROM, to });

    // // Persist/send status to your DB here (Supabase) if desired

    return res.json({ ok: true, text });
  } catch (err) {
    // // Log server-side; do not expose secrets. Consider storing errors in your DB for retries.
    console.error(err);
    return res.status(500).json({ error: 'failed to send' });
  }
};

 

Operational best practices

 

  • Consent & content rules — ensure users opted in for SMS. Use templates and redaction to avoid sending PII to OpenAI.
  • Rate limiting & batching — throttle sends and use batching or segmented sends to avoid provider rate limits and cost spikes.
  • Queue + retries — write messages to Supabase (or Redis/DB) and have a worker (GitHub Actions, Supabase Function, or external worker) pull and retry with exponential backoff.
  • Observability — store send attempts, provider response codes, and timestamps for audit/retry and user support.
  • Fallbacks — implement a secondary SMS provider webhook for failures above a threshold.
  • Security — keep all keys in Lovable Secrets; do AI calls server-side only.

 

When you need more than Lovable cloud UI

 

  • Install packages — add them to package.json in the project and use GitHub sync so CI installs dependencies (no terminal).
  • Scheduled jobs — use GitHub Actions cron or Supabase Edge Functions; Lovable does not provide an internal cron CLI.
  • Heavy throughput — export to your infra (via GitHub) and run workers with horizontal scaling.

 

Follow these steps inside Lovable: create endpoint files via Chat Mode, add secrets in Secrets UI, test with Preview, and Publish or sync to GitHub for production, keeping consent, PII, rate limits, queuing, and retries as first-class concerns.

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022