Integration Guide

Connect Your WhatsApp Business Cloud API

This guide connects your own Meta WhatsApp Business Platform account to SCREEN X PROTECTION. All credentials stay server-side — never in frontend code.

Connection Checklist

  • Booking form → validates & submits to POST /api/bookings
  • Backend generates unique Booking ID (SXP-YYYYMMDD-XXXX)
  • Booking saved to store (status: NEW)
  • Owner WhatsApp message built (click-to-chat always available)
  • Customer WhatsApp confirmation sent via Cloud API (when configured)
  • Webhook /api/whatsapp/webhook verifies & replies to TRACK <ID>
  • Track page /track looks up booking by ID
  • Admin /admin manages & updates status

Environment Variables

Add these as server-side environment (secrets). Never put them in frontend code, HTML, or GitHub. Do NOT fill with fake values — leave empty until you have the real ones from Meta.

WHATSAPP_ACCESS_TOKEN=
What: The permanent (or system-user) access token for the Meta app that can send messages via the WhatsApp Cloud API.
Where: Meta App Dashboard → WhatsApp → API Setup (or Business Manager → System Users → Generate token).
WHATSAPP_PHONE_NUMBER_ID=
What: The ID of the business phone number that sends messages.
Where: Meta App Dashboard → WhatsApp → API Setup → Phone Number ID.
WHATSAPP_BUSINESS_ACCOUNT_ID=
What: The WhatsApp Business Account ID (WABA ID).
Where: Meta Business Manager → Business Settings → WhatsApp Accounts → your account ID.
WHATSAPP_VERIFY_TOKEN=
What: A custom string YOU choose. Used to verify the webhook belongs to you. Set it here, then enter the same value in the Meta webhook config.
Where: You create this value. Use any hard-to-guess string (e.g. sxp_verify_8f3k2).
DATABASE_URL=
What: Connection string for your bookings database (optional in this template — bookings are stored in-memory by default).
Where: Your database provider (e.g. Supabase, Neon, PlanetScale) connection string.

Meta WhatsApp Setup Steps

1. Create a Meta Business Account

Go to business.facebook.com and create a Business Account for SCREEN X PROTECTION. Verify your business if you plan to go live with production messaging.

2. Create a Meta App

Go to developers.facebook.com → My Apps → Create App → select 'Business' type → name it (e.g. Screen X Protection WhatsApp) → Create.

3. Add the WhatsApp product

In your app dashboard → Add Product → WhatsApp → Set Up. This enables the WhatsApp Cloud API for your app and gives you a test phone number.

4. Get your Phone Number ID & Access Token

Go to WhatsApp → API Setup. Copy the Phone Number ID. Generate a permanent access token via Business Manager → System Users → Add User → Generate token with whatsapp_business_messaging permission.

5. Add your own business number

To use your real WhatsApp Business number (instead of the test number), go to WhatsApp Manager → add a number and migrate/link it. Then copy its Phone Number ID.

6. Configure the webhook

In WhatsApp → Configuration → Webhook, set the Callback URL to your site's https://YOURDOMAIN/api/whatsapp/webhook. Enter the same Verify Token you set in env (WHATSAPP_VERIFY_TOKEN). Verify & Save. Subscribe to 'messages'.

7. Create a message template

Automated customer confirmations sent outside the 24-hour session window require an APPROVED template. Go to WhatsApp Manager → Message Templates → Create. Submit for approval. Use the template name in your send-confirmation logic.

8. Test the API

Use the API Setup 'Send Message' tester in Meta, or enable Test Mode on your booking form to create bookings without sending real messages. Once credentials are set in env, real automated messages will dispatch.

Template vs Session Messages

Session messages (free-form text) can be sent only within 24 hours of the customer's last message to your business number. Template messages (pre-approved by Meta) are required for automated confirmations sent outside that window. Do not bypass Meta's policies — submit and approve a template for the customer confirmation message.

Backend Endpoints

POST /api/bookings — create booking + trigger WhatsApp
GET /api/bookings — list/search bookings (admin)
GET/PATCH /api/bookings/:id — get / update status
POST /api/whatsapp/send-confirmation — resend confirmation
GET/POST /api/whatsapp/webhook — verify + incoming TRACK lookup