Skip to main content
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

Create app/api/webhook/route.ts:

Express.js Webhook Route

Configure in Meta Dashboard:
  1. Go to Meta Developer Console
  2. Select your app → WhatsApp → Configuration
  3. Add webhook URL: https://your-domain.com/webhook
  4. Use your WHATSAPP_WEBHOOK_TOKEN for verification
  5. Subscribe to messages events

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:

Expected Output

You should see output similar to this:
When you receive a message, you’ll see:

Troubleshooting

  • Verify your access token and phone number ID are correct
  • Check that your Meta Developer account is active
  • Ensure you have internet connectivity
  • 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
  • Install and configure dotenv: npm install dotenv
  • Add require('dotenv').config() at the top of your file
  • Verify your .env file is in the project root
  • 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
  • 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 messages events in Meta Dashboard
  • Check webhook endpoint returns 200 OK on verification
  • Ensure WHATSAPP_WEBHOOK_TOKEN is set correctly in .env
  • The verify token must match exactly in both places
  • Meta sends GET request for verification with hub.verify_token parameter
  • Your endpoint must return the hub.challenge value

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.