Prerequisites: Make sure you’ve completed the Installation & Setup guide and have your WhatsApp Business API credentials ready.
Step 1: Initialize the Client
Create a new file and initialize the WhatsApp client with your credentials:Step 2: Send Your First Text Message
Add this code to send a simple text message:Step 3: Send a Message with Interactive Buttons
Let’s make it more interesting with interactive buttons:Step 4: Setup Webhook to Receive Messages
Configure webhook to receive incoming messages from Meta:Next.js Webhook Route
Createapp/api/webhook/route.ts:
Express.js Webhook Route
Configure in Meta Dashboard:
- Go to Meta Developer Console
- Select your app → WhatsApp → Configuration
- Add webhook URL:
https://your-domain.com/webhook - Use your
WHATSAPP_WEBHOOK_TOKENfor verification - Subscribe to
messagesevents
Step 5: Send Media Content
Send an image with a caption:Complete Example
Here’s the complete working example with webhook:Run Your Code
Execute your quick start script:- TypeScript
- JavaScript
Expected Output
You should see output similar to this:Troubleshooting
Connection failed
Connection failed
- Verify your access token and phone number ID are correct
- Check that your Meta Developer account is active
- Ensure you have internet connectivity
Message not received
Message not received
- Make sure the recipient number is added to your WhatsApp Business account
- Verify the phone number format includes the country code
- Check the WhatsApp Business API status page
Environment variables not loaded
Environment variables not loaded
- Install and configure dotenv:
npm install dotenv - Add
require('dotenv').config()at the top of your file - Verify your
.envfile is in the project root
TypeScript errors
TypeScript errors
- Make sure TypeScript is installed:
npm install -D typescript @types/node - Install ts-node for direct execution:
npm install -D ts-node - Check your tsconfig.json configuration
Webhook not receiving messages
Webhook not receiving messages
- Verify webhook URL is publicly accessible (not localhost)
- Use ngrok for local testing:
ngrok http 3000 - Check webhook token matches in Meta Dashboard and
.env - Verify you subscribed to
messagesevents in Meta Dashboard - Check webhook endpoint returns 200 OK on verification
Webhook verification failed
Webhook verification failed
- Ensure
WHATSAPP_WEBHOOK_TOKENis set correctly in.env - The verify token must match exactly in both places
- Meta sends GET request for verification with
hub.verify_tokenparameter - Your endpoint must return the
hub.challengevalue
Next Steps
Explore Message Types
Learn about all 11 supported message types including lists, templates, and media
Set Up Webhooks
Receive and respond to incoming messages with webhooks
Advanced Configuration
Configure timeouts, retry logic, and other advanced options
Common Patterns
Error Handling Pattern
Configuration Pattern
Pro tip: Start with the basic configuration and add advanced options as needed. The SDK provides sensible defaults for most use cases.