WhatsApp Business API
Integration Guide
Complete step-by-step guide to connect your WhatsApp Business number with LeadSoras CRM through Meta Business Platform and start sending messages to your leads.
๐ Overview
LeadSoras CRM integrates with WhatsApp Business through the Evolution API โ an open-source gateway that connects to WhatsApp Web (via the Baileys library) or the official Meta WhatsApp Business API. This guide covers both approaches:
- Option A โ QR Code (WhatsApp Web): Quick setup using QR code scanning. Best for small teams (up to ~1,000 messages/day). No Meta Business verification required.
- Option B โ Meta Business API (Official): Full enterprise integration through Meta's Cloud API. Supports high-volume messaging, verified business profiles, and message templates. Requires Meta Business verification.
Architecture Diagram
โ Prerequisites
Before starting, make sure you have the following:
Active LeadSoras CRM Account
You need an active CRM subscription with Admin privileges to configure WhatsApp settings.
Dedicated WhatsApp Phone Number
A phone number that is NOT currently registered on WhatsApp Personal or WhatsApp Business app. If the number is already on WhatsApp, you must deregister it first.
Server or VPS (for Evolution API)
A Linux server (Ubuntu 20.04+ recommended) with Docker installed, or a cloud service like Railway, Render, or DigitalOcean. Minimum: 1 vCPU, 1GB RAM, 10GB disk.
Meta Business Account (for Option B only)
A verified Meta Business Suite account at business.facebook.com.
๐ข Step 1 โ Create a Meta Business Account
A Meta Business Account is required to access the WhatsApp Business API. Follow these steps:
Go to Meta Business Suite
Visit business.facebook.com and click "Create Account".
Enter Business Details
Fill in your business name, your name, and business email address. Click "Submit".
Verify Your Email
Check your email inbox for a verification message from Meta. Click the verification link to confirm.
Complete Business Information
Navigate to Settings โ Business Info and fill in:
- Legal business name
- Business address
- Business phone number
- Website URL
- Business category
Business Verification (Recommended)
For higher messaging limits and a verified badge, complete business verification:
- Go to Settings โ Security Center โ Start Verification
- Upload required documents (business registration, utility bill, etc.)
- Wait for Meta to review (usually 2-7 business days)
๐ฑ Step 2 โ Create a Meta App
Go to Meta for Developers
Visit developers.facebook.com and log in with your Facebook account linked to your Business Account.
Create a New App
Click "My Apps" โ "Create App".
- Select "Other" as the use case
- Choose "Business" as the app type
- Enter app name (e.g., "LeadSoras CRM WhatsApp")
- Select your Meta Business Account
- Click "Create App"
Note Your App Credentials
After creation, go to Settings โ Basic and note down:
- App ID โ You'll need this for API calls
- App Secret โ Keep this secure, never expose in frontend code
๐ฌ Step 3 โ Add WhatsApp Product
Add WhatsApp to Your App
In your app dashboard, scroll down to "Add Products to Your App", find WhatsApp, and click "Set Up".
Select Your Business Account
Choose the Meta Business Account you created in Step 1. Click "Continue".
Review API Setup
You'll be taken to the WhatsApp โ API Setup page. Here you'll see:
- Temporary Access Token โ Valid for 24 hours (for testing only)
- Phone Number ID โ Identifies your WhatsApp sender
- WhatsApp Business Account ID โ Your WABA ID
๐ Step 4 โ Register Your Phone Number
For Option A (QR Code โ WhatsApp Web)
No registration needed. You'll simply scan a QR code with your WhatsApp phone. The number can be your existing personal or business WhatsApp number.
For Option B (Meta Business API)
Add a Phone Number
In the WhatsApp โ API Setup page, click "Add Phone Number".
- Enter a display name for your business
- Select a category
- Enter the phone number you want to use
Verify the Phone Number
Choose verification method:
- SMS โ Receive a 6-digit code via SMS
- Voice Call โ Receive a phone call with the code
Enter the verification code and click "Verify".
Configure Business Profile
After verification, set up your business profile:
- Profile picture (logo)
- Business description
- Business address
- Business email
- Website URL
๐ Step 5 โ Generate Permanent Access Token
The temporary token from the API Setup page expires in 24 hours. For production use, you need a permanent (System User) access token.
Create a System User
Go to Meta Business Settings โ System Users.
- Click "Add"
- Name: e.g., "CRM WhatsApp Bot"
- Role: Admin
- Click "Create System User"
Assign Assets
Click "Add Assets" next to your system user:
- Select "Apps" tab
- Find your WhatsApp app โ toggle "Full Control"
- Select "WhatsApp Accounts" tab
- Find your WABA โ toggle "Full Control"
- Click "Save Changes"
Generate Token
Click "Generate New Token" for your system user:
- Select your WhatsApp app
- Enable these permissions:
whatsapp_business_managementwhatsapp_business_messaging
- Click "Generate Token"
- Copy and save the token immediately โ it won't be shown again!
META_PERMANENT_ACCESS_TOKEN) on your server. Never expose it in client-side code.# Add to your backend .env file
META_PERMANENT_ACCESS_TOKEN=EAAxxxxxxxxxxxxxxxxxxxxxxx๐ Step 6 โ Install Evolution API
Evolution API is the middleware that connects LeadSoras CRM to WhatsApp. It handles session management, message queuing, and webhook delivery.
Option 1 โ Docker (Recommended)
# Pull the latest Evolution API image
docker pull atendai/evolution-api:latest
# Create and run the container
docker run -d \
--name evolution-api \
-p 8080:8080 \
-e AUTHENTICATION_API_KEY=YOUR_EVOLUTION_API_KEY \
-e SERVER_URL=https://your-domain.com \
-v evolution_data:/evolution/instances \
atendai/evolution-api:latestOption 2 โ Docker Compose
Create a docker-compose.yml file:
version: '3.8'
services:
evolution-api:
image: atendai/evolution-api:latest
container_name: evolution-api
restart: always
ports:
- "8080:8080"
environment:
# Authentication
- AUTHENTICATION_API_KEY=YOUR_SECURE_API_KEY_HERE
# Server
- SERVER_URL=https://your-domain.com
- SERVER_PORT=8080
# Database (optional - for persistence)
- DATABASE_ENABLED=true
- DATABASE_PROVIDER=postgresql
- DATABASE_CONNECTION_URI=postgresql://user:pass@host:5432/evolution
# Webhook (for CRM integration)
- WEBHOOK_GLOBAL_ENABLED=true
- WEBHOOK_GLOBAL_URL=https://your-crm-backend.com/api/webhooks/evolution
- WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=true
- WEBHOOK_EVENTS_MESSAGES_UPSERT=true
- WEBHOOK_EVENTS_MESSAGES_UPDATE=true
- WEBHOOK_EVENTS_CONNECTION_UPDATE=true
volumes:
- evolution_data:/evolution/instances
volumes:
evolution_data:Then run:
docker compose up -dOption 3 โ Railway / Cloud Deployment
Deploy on Railway
Click the button below or go to railway.app:
- Create a new project โ "Deploy from Docker Image"
- Image:
atendai/evolution-api:latest - Set environment variables (same as Docker section above)
- Deploy and note the public URL provided by Railway
ngrok http 8080โ๏ธ Step 7 โ Configure Evolution API
Create a WhatsApp Instance
After deploying Evolution API, create an instance to connect your WhatsApp number:
curl -X POST 'https://your-evolution-api.com/instance/create' \
-H 'apikey: YOUR_EVOLUTION_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"instanceName": "LeadSoras",
"integration": "WHATSAPP-BAILEYS",
"qrcode": true,
"webhook": {
"url": "https://your-crm-backend.com/api/webhooks/evolution",
"byEvents": true,
"events": [
"MESSAGES_UPSERT",
"MESSAGES_UPDATE",
"CONNECTION_UPDATE"
]
}
}'Verify the Instance
curl -X GET 'https://your-evolution-api.com/instance/connectionState/LeadSoras' \
-H 'apikey: YOUR_EVOLUTION_API_KEY'Expected response:
{
"instance": {
"instanceName": "LeadSoras",
"state": "open"
}
}Environment Variables Reference
| Variable | Description | Example |
|---|---|---|
AUTHENTICATION_API_KEY | Master API key for Evolution API authentication | my_secure_key_2026 |
SERVER_URL | Public URL where Evolution API is hosted | https://evo.example.com |
WEBHOOK_GLOBAL_URL | URL to receive WhatsApp events (your CRM backend) | https://api.example.com/api/webhooks/evolution |
DATABASE_CONNECTION_URI | PostgreSQL connection string for persistence | postgresql://user:pass@host:5432/db |
๐ Step 8 โ Connect Evolution API to LeadSoras CRM
Option A: Configure via CRM Dashboard (Recommended)
Navigate to WhatsApp Settings
In your CRM dashboard, go to WhatsApp โ Settings (or click the โ๏ธ icon from the WhatsApp page).
Enter Connection Details
Fill in the following fields:
- Evolution API URL: The public URL of your Evolution API instance (e.g.,
https://your-evolution-api.com) - API Key: The
AUTHENTICATION_API_KEYyou set during Evolution API setup - Instance Name: The name you gave when creating the instance (e.g.,
LeadSoras)
Test the Connection
Click the "๐ Test Connection" button. If successful, you'll see a green "Connected" status indicator.
Save Settings
Click "๐พ Save Settings" to persist your configuration.
Option B: Configure via Environment Variables
You can also configure the connection through your backend .env file:
# WhatsApp (Evolution API) Configuration
EVOLUTION_API_URL=https://your-evolution-api.com
EVOLUTION_API_KEY=YOUR_EVOLUTION_API_KEY
EVOLUTION_INSTANCE_NAME=LeadSoras- Database settings (configured via Dashboard)
- Environment variables (
.envfile) - Default fallbacks
๐ช Step 9 โ Configure Webhooks
Webhooks allow the CRM to receive real-time updates from WhatsApp โ including incoming messages, delivery receipts, and connection status changes.
CRM Webhook Endpoint
Your LeadSoras CRM backend exposes the following webhook endpoint:
POST https://your-crm-backend.com/api/webhooks/evolutionConfigure in Evolution API
You can set the webhook URL either during instance creation (Step 7) or update it after:
curl -X PUT 'https://your-evolution-api.com/webhook/set/LeadSoras' \
-H 'apikey: YOUR_EVOLUTION_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://your-crm-backend.com/api/webhooks/evolution",
"enabled": true,
"webhookByEvents": true,
"events": [
"MESSAGES_UPSERT",
"MESSAGES_UPDATE",
"CONNECTION_UPDATE",
"SEND_MESSAGE"
]
}'Webhook Events Handled by CRM
| Event | Description | CRM Action |
|---|---|---|
MESSAGES_UPSERT | New message received from a contact | Saves inbound message to lead's chat history |
MESSAGES_UPDATE | Message status update (delivered, read) | Updates message delivery/read status in CRM |
CONNECTION_UPDATE | WhatsApp connection state changed | Updates connection status indicator |
SEND_MESSAGE | Confirmation of sent message | Updates outbound message status |
For Meta Business API โ Facebook Webhook (Lead Ads)
If you're also using Facebook Lead Ads integration, configure the Facebook webhook separately:
Set Up Facebook Webhook
In your Meta App Dashboard โ WhatsApp โ Configuration:
- Callback URL:
https://your-crm-backend.com/api/webhooks/facebook - Verify Token: Your webhook secret (set in CRM Settings โ General โ Webhook Secret)
Subscribe to Events
Subscribe to the following webhook fields:
messagesโ Incoming messagesmessage_deliveriesโ Delivery statusmessage_readsโ Read receiptsleadgenโ Lead form submissions (for Facebook Lead Ads)
prodiet_webhook_secret๐ฑ Step 10 โ Connect via QR Code
Open WhatsApp Settings in CRM
Navigate to Dashboard โ WhatsApp โ Settings in your CRM.
Click 'Show QR Code'
Click the "๐ฑ Show QR Code" button. A QR code will appear on screen.
Scan with Your Phone
On your phone:
- Open WhatsApp on your mobile device
- Tap Settings โ Linked Devices โ Link a Device
- Point your camera at the QR code displayed in the CRM
- Wait for the connection to establish (usually 5-10 seconds)
Verify Connection
After scanning, click "๐ Test Connection" to confirm. The status should show Connected with a green indicator.
โ๏ธ Sending Messages
Once connected, you can send WhatsApp messages to your leads directly from the CRM.
From the Lead Chat
Open a Lead
Navigate to Dashboard โ Leads and click on any lead to open their profile.
Send a Message
In the lead's chat section, type your message and click Send via WhatsApp. The message will be queued and sent through your connected WhatsApp number.
Via the WhatsApp Dashboard
Navigate to Dashboard โ WhatsApp to access the dedicated messaging interface where you can:
- Send individual messages to any phone number
- View message history and delivery status
- Monitor sending queue and statistics
- Pause/resume message sending
- Retry failed messages
Via API (Programmatic)
curl -X POST 'https://your-crm-backend.com/api/whatsapp/send' \
-H 'Authorization: Bearer YOUR_JWT_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"phoneNumber": "201234567890",
"messageText": "Hello! This is a test message from LeadSoras CRM.",
"leadId": "optional-lead-uuid"
}'Message Queue System
Messages are not sent immediately โ they go through an intelligent queuing system:
| Setting | Default | Description |
|---|---|---|
| Delay Between Messages | 5 seconds | Wait time between each sent message |
| Batch Size | 50 messages | Number of messages per batch before pausing |
| Pause Duration | 1 hour | Cooldown period after a batch completes |
| Max Retries | 3 | Retry count for failed messages |
| Processing Interval | 30 seconds | How often the scheduler checks for pending messages |
๐จ Bulk Messaging
Navigate to Bulk Messaging
Go to Dashboard โ WhatsApp โ Bulk Send.
Select Recipients
Choose your recipients:
- From CRM leads: Select leads by status, source, or individually
- Manual numbers: Enter phone numbers directly (one per line)
Compose Message
Write your message or select a pre-built template. You can use variables like{{ name }} and {{ phone }} for personalization.
Send
Click "Send Bulk Messages". Messages will be queued and sent according to your configured batch settings to avoid WhatsApp rate limiting and account bans.
๐ Message Templates
Templates allow you to create reusable message formats with dynamic variables. Manage templates at Dashboard โ WhatsApp โ Templates.
Creating a Template
Click 'Create Template'
Enter a template name and compose your message body. Use double curly braces for variables:
Hello {{ name }}! ๐
Thank you for your interest in our services.
Your inquiry #{{ phone }} has been received.
Our team will contact you within 24 hours.
Best regards,
LeadSoras TeamAvailable Variables
| Variable | Description | Example Output |
|---|---|---|
{{ name }} | Lead's full name | Ahmed Mohamed |
{{ phone }} | Lead's phone number | +201234567890 |
| Custom variables | Any key you pass in templateVars | Depends on your data |
๐ง Troubleshooting
Connection Issues
| Problem | Cause | Solution |
|---|---|---|
| "Disconnected" status | QR session expired or phone offline | Re-scan the QR code; ensure phone has internet |
| QR code not loading | Evolution API is unreachable | Check if Evolution API is running; verify the URL and API key |
| "Instance not found" | Instance wasn't created or name mismatch | Create a new instance or verify the instance name matches CRM settings |
| Connection test fails | Network/firewall blocking requests | Ensure your CRM backend can reach the Evolution API URL; check CORS settings |
Message Sending Issues
| Problem | Cause | Solution |
|---|---|---|
| Messages stuck in "pending" | Scheduler paused or WhatsApp disconnected | Check connection status; resume sending in WhatsApp dashboard |
| Messages failing repeatedly | Invalid phone number format | Ensure numbers include country code without + (e.g., 201234567890) |
| WhatsApp number banned | Too many messages or spam reports | Increase delay between messages; reduce bulk volume; wait 24-72 hours |
| Webhooks not received | Webhook URL misconfigured | Verify webhook URL in Evolution API; check server logs for incoming requests |
Checking Logs
# Check Evolution API logs
docker logs evolution-api --tail 100 -f
# Check CRM backend logs (Railway)
# Go to Railway dashboard โ your service โ Logs tab
# Check CRM backend logs (local)
# Look at terminal output or check console logsโ Frequently Asked Questions
Can I use my personal WhatsApp number?
Option A (QR Code): Yes, you can use your personal WhatsApp number. Your phone acts as the sender.
Option B (Meta API): No, the number must be exclusively registered with the Business API and cannot have WhatsApp installed on the phone.
How many messages can I send per day?
Option A: WhatsApp doesn't publish official limits for personal accounts, but sending more than ~1,000 messages/day risks temporary bans. Use reasonable delays.
Option B: Depends on your tier โ starts at 250/day (unverified), then 1,000, 10,000, 100,000, and unlimited after Meta verification.
Is this integration free?
Evolution API is open-source and free. Meta's WhatsApp Business API charges per conversation (currently first 1,000 service conversations per month are free). Server hosting costs depend on your provider.
Can I send images, videos, and documents?
Yes! The CRM supports sending media messages including images, videos, and documents via WhatsApp. Use the media upload feature when composing messages, or pass mediaUrl and mediaType via the API.
Will incoming messages appear in the CRM?
Yes! When a lead replies to your WhatsApp message, the reply is automatically captured via webhooks and saved in the lead's chat history. The CRM matches incoming messages to leads based on phone number.
Can multiple team members use the same WhatsApp connection?
Yes. The WhatsApp connection is shared at the organization level. All CRM users with WhatsApp permissions can send and view messages through the same connected number.
What happens if my phone disconnects (QR Code mode)?
Pending messages will queue up and be sent once the connection is re-established. If the session fully expires, you'll need to re-scan the QR code from the WhatsApp Settings page.
Need help? Contact our support team.