← Blog

·

How to connect a Lovable app to the official WhatsApp Business API

Updated on November 10, 2026

There are two ways to connect a Lovable app to the official WhatsApp Business API. The first is Lovable’s own WhatsApp Business connector, which connects your number through Meta’s guided signup and bills messages directly to your Meta account. The second is integrating a provider’s API like any external API: the call goes out from a backend function (Edge Function or server function), the token is stored in Secrets, and the webhook is another, public function. In both cases, the token never reaches the browser.

This guide explains when to use each path, the prompts to ask Lovable for the integration, the code it should generate (for you to review) and the safeguards that prevent leaked tokens and a number abused for spam.

Path 1: Lovable’s WhatsApp Business connector

According to the WhatsApp Business connector page, Lovable offers an “app + chat” connector that lets you receive messages, send replies and templates, track statuses (sent, delivered, read, failed) and list, create and delete templates. The connection is made through Meta’s Embedded Signup, without creating a developer app or copying a key. Points the documentation highlights:

  • Meta bills usage directly, outside Lovable credits, and Meta’s pricing, limits and Business Messaging Policy apply.
  • Each connection represents one account and one number; each project uses a single WhatsApp Business connection.
  • Only one project receives messages and statuses at a time, and it must be a newer app, created on or after May 13, 2026 on TanStack Start. Older React + Vite projects can’t receive messages through the connector.
  • The connector doesn’t edit existing templates: to change one, you create a new one.
  • If the number shares conversation routing with another provider, incoming messages may go to that provider; the documentation explains how to adjust this in Meta Business Suite.

If your app is new, the number isn’t on any provider yet and you want to pay Meta directly with your account’s payment method, the connector is the shortest path.

Path 2: integrating a provider’s API

An API integration makes sense when the number is already with a provider (and you don’t want to change routing), when the app is React + Vite, when the same number serves other systems besides Lovable, or when you prefer the provider’s billing model. Lovable’s API integration docs describe the approach: in newer TanStack Start apps, Lovable writes a server function; in React + Vite apps, an Edge Function in the built-in backend. The key lives in the project’s secrets and is read only by server code.

PieceWhere it runsWhat it does
App screen (React)BrowserCollects data and calls the function; never sees the token
Send functionBackend (Edge Function or server function)Checks the caller, builds the JSON and calls the API
Webhook functionBackend, publicReceives events, validates their origin and writes to the database
Database (Postgres)Built-in backend or your own SupabaseStores messages, statuses and who already received what

A variation is the custom connector: according to the create a connector page, a workspace admin can register any REST API with an https:// base URL and Bearer token authentication, and each person enters their own credential when connecting. The examples below use an Edge Function, which gives you full control of the code and works in both project types.

Want to try it while you read? Create a Vectalk account and send your first message through the official API. Create free account →

Why the token can’t live in the front end

Everything that goes into front-end code ends up in the visitor’s browser. A WhatsApp API token there lets anyone send messages on behalf of your number, burn your balance and tank the account’s quality.

Lovable’s Secrets page says secrets are encrypted, injected automatically into Edge Functions and never reach the browser. Variables prefixed with VITE_, on the other hand, are build-time values embedded in the client bundle: they’re for public keys, never for the WhatsApp token.

Step 1: store the token in Secrets

Add the values under More → Settings → Secrets → Add secret, as the documentation indicates. Don’t paste the token in the chat. Suggested names:

  • WA_SEND_URL: the provider’s send endpoint.
  • WA_TOKEN: the access token.
  • WA_WEBHOOK_KEY: a secret you make up to protect the webhook.

If the project uses your own Supabase, the Supabase integration page warns that Lovable projects sharing the same Supabase project overwrite each other’s secrets. Use one Supabase project per app.

Step 2: ask Lovable for the send function

A precise prompt, with endpoint, authentication and a security rule, gets better results than “integrate WhatsApp”:

Create an edge function called send-whatsapp. It must:
1. Require a logged-in user: read the JWT from the Authorization header and reject with 401 if there is no user.
2. Receive { orderId } in the body and look up the customer's phone in the orders table.
3. Send the "order_confirmed" template (language en_US) with orderId as a body variable,
   via POST to Deno.env.get("WA_SEND_URL"), header Authorization: Bearer Deno.env.get("WA_TOKEN").
4. Store the returned wamid in the whatsapp_outbound table.
Do not put any token in the front-end code.

The generated code should look like this. Review it before publishing:

// supabase/functions/send-whatsapp/index.ts
import { createClient } from "npm:@supabase/supabase-js@2";

const supabase = createClient(
  Deno.env.get("SUPABASE_URL")!,
  Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!,
);

Deno.serve(async (req) => {
  const jwt = (req.headers.get("Authorization") ?? "").replace("Bearer ", "");
  const { data: { user } } = await supabase.auth.getUser(jwt);
  if (!user) return new Response("unauthorized", { status: 401 });

  const { orderId } = await req.json();
  const { data: order } = await supabase
    .from("orders").select("phone").eq("id", orderId).eq("user_id", user.id).single();
  if (!order) return new Response("not found", { status: 404 });

  const res = await fetch(Deno.env.get("WA_SEND_URL")!, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${Deno.env.get("WA_TOKEN")}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      messaging_product: "whatsapp",
      to: order.phone,
      type: "template",
      template: {
        name: "order_confirmed",
        language: { code: "en_US" },
        components: [{ type: "body", parameters: [{ type: "text", text: String(orderId) }] }],
      },
    }),
  });

  const data = await res.json();
  if (!res.ok) return Response.json({ error: data?.error?.message }, { status: 502 });

  await supabase.from("whatsapp_outbound").insert({
    wamid: data.messages[0].id, to: order.phone, user_id: user.id, status: "accepted",
  });
  return Response.json({ wamid: data.messages[0].id });
});

In the front end, the call uses the Supabase client, which sends the user session automatically:

const { data, error } = await supabase.functions.invoke("send-whatsapp", {
  body: { orderId: "12345" },
});

The body follows the format in Meta’s send messages documentation. Store phone numbers as digits only, with the country code. For header media and buttons, see how to send a template through the API.

Step 3: lock down what the function accepts

Lovable’s Edge Functions page points out that anyone who knows a function’s address can send requests to it, and recommends that every function check who is calling. For WhatsApp, go beyond login:

  • Template fixed on the server. The front end sends only data (orderId), never the template name or free text.
  • Recipient from the database. As in the example, the phone comes from the user’s own order, not from the request body.
  • Per-user limit. A simple count of sends per hour prevents abuse from a compromised account.
  • Consent. Only message people who asked to receive messages, as Meta’s policy requires.

Step 4: receive messages with a webhook function

The webhook is another function, public, because the caller is the provider (or Meta), not a logged-in user. The full code, with hub.challenge verification, signature validation and table writes, is in WhatsApp webhook with Supabase. It applies to Lovable because the built-in backend uses the same database, auth and Edge Functions foundation, according to the Supabase integration page.

A prompt for Lovable:

Create a public edge function called whatsapp-webhook, without requiring login.
- Reject with 401 if the URL parameter key is different from Deno.env.get("WA_WEBHOOK_KEY").
- POST: read the body with req.text() and only then JSON.parse it.
- Store messages[] in whatsapp_inbound (unique wamid) and update statuses[] in whatsapp_outbound.
- Respond 200 quickly.

Redeliveries happen: Meta retries deliveries that didn’t get a 200 for up to 7 days, and they may arrive duplicated, according to the webhooks overview. That’s why wamid needs a unique index. If messages don’t show up, open the function’s View logs and follow the webhook not working checklist.

Common mistakes

SymptomLikely causeFix
Token shows up in the front-end codeRequest made without specifying a backendAsk to move the call into a function and revoke the old token
401 on every call to the send functionFront end calling with fetch without the sessionUse supabase.functions.invoke, which sends the JWT
Webhook returns 401 to the providerFunction requiring loginMake the function public and validate the secret or signature
Incoming messages don’t reach the appConversation routing pointing elsewhereCheck where the number delivers messages (connector or provider)
Message “sent” but never arrivesOutside the 24-hour window without a templateUse an approved template; see the 24-hour window

How to do this with Vectalk

Vectalk is a proxy for Meta’s official Cloud API and fits path 2: the code above doesn’t change, only the values in Secrets. Use WA_SEND_URL=https://apis.vectalk.com.br/api/messages and, in WA_TOKEN, a token created under Settings (Configurações) → API Tokens in the dashboard. According to the authentication page, an instance token resolves the phone_number_id on its own; an organization token (the global token) serves every instance and requires phone_number_id in the body. The token is shown only once at creation, so paste it straight into Secrets.

For the webhook, register the function URL with POST https://apis.vectalk.com.br/api/webhooks (instance_id, url, name), with ?key= already appended. The Hub forwards the same payload Meta sends and expects 200 within 20 seconds, according to the webhooks documentation; it doesn’t describe a signature header on the forwarded request, hence the secret in the URL. Confirm the details through the contact page.

For billing, you pay the plan’s monthly fee and load a prepaid balance; Vectalk puts its own credit line on your number and each delivered message is deducted from the balance, with no card registered at Meta. And to be clear: Vectalk has no support inbox, AI or bulk messaging in its dashboard. You build those screens in your own Lovable app. To get started, create your account. If you prefer visual workflows, see WhatsApp API in Bubble; for the big picture, the official WhatsApp API guide.

Frequently asked questions

Does Lovable have a native WhatsApp integration?

Yes. The WhatsApp Business connector connects your number through Meta’s guided signup, and Meta bills usage directly to your account. To receive messages, the project must be a TanStack Start app created on or after May 13, 2026.

Can I use the connector and a provider on the same number?

A number’s incoming messages go to a single destination, set by Meta’s conversation routing. The connector documentation describes exactly the case where another provider keeps the incoming messages. Choose one path per number.

Can I use a VITE_ variable for the token?

No. VITE_ variables are embedded in the browser bundle at build time. They’re for public keys, never for the WhatsApp token.

Can I use an unofficial (QR code) API in Lovable?

Technically any HTTP API can be called, but QR code connections go against WhatsApp’s terms and can get the number banned. The official API is the path Meta authorizes.

How do I message a customer who has never contacted me?

Only with an approved template and the contact’s consent (opt-in). Free-form messages are only allowed inside the 24-hour window opened by a customer message.


Official sources consulted on November 10, 2026: Lovable: WhatsApp Business connector, Lovable: Integrate any API, Lovable: create a custom connector, Lovable: Secrets, Lovable: Edge functions, Lovable: Connect to Supabase, Meta: send messages, Meta: webhooks overview, WhatsApp: Business Messaging Policy, Vectalk: authentication, Vectalk: webhooks.

Put your business on the official WhatsApp

Create your account, connect your number to the official API (you can keep the app with coexistence) and start serving customers and sending messages.