Skip to main content

Supported Message Types

Message Type Categories

1. Basic Messages

Simple, straightforward communication:
  • Text: Plain text messages with optional URL previews
  • Location: GPS coordinates with optional metadata

2. Media Messages

Rich media content:
  • Image: Photos, screenshots, graphics (JPEG, PNG, WebP)
  • Video: Video files and recordings (MP4, 3GPP)
  • Audio: Voice messages and audio files (AAC, MP3, OGG)
  • Document: Files and documents (PDF, DOC, XLS, TXT)
  • Sticker: Animated and static WebP stickers

3. Interactive Messages

User engagement and responses:
  • Buttons: Up to 3 action buttons with custom responses
  • Lists: Dropdown menus with multiple options and sections

4. Structured Messages

Business communication:
  • Template: Pre-approved message templates for notifications
  • Contact: vCard contact information sharing

5. Enhanced Communication

Advanced interaction features:
  • Contextual Replies: Reply to specific messages with threaded context
  • Message Reactions: React to messages with emoji expressions

6. Bulk Messaging

Send to multiple recipients:
  • Broadcast Messages: Send messages to multiple recipients with intelligent rate limiting and progress tracking

Quick Reference

Message Size Limits

Message TypeSize LimitCaption Support
Text4,096 charactersN/A
Image5 MB✅ (1,024 chars)
Video16 MB✅ (1,024 chars)
Audio16 MB
Document100 MB✅ (1,024 chars)
Sticker500 KB
InteractiveN/AFooter text supported
TemplateVariesTemplate-defined
LocationN/AName/address fields
ContactN/AMultiple contacts per message
Contextual ReplySame as base typeInherits from message type
ReactionN/ASingle emoji only

Common Properties

All messages share these common properties:
interface BaseMessage {
  type: WhatsAppMessageType;  // Message type identifier
  to: string;                 // Recipient phone number (+1234567890)
  context?: {                 // Optional: Reply to another message
    message_id: string;
  };
}

Response Format

All message sending methods return a consistent response:
interface MessageResponse {
  messaging_product: 'whatsapp';
  contacts: Array<{
    input: string;            // Phone number sent to
    wa_id: string;           // WhatsApp ID
  }>;
  messages: Array<{
    id: string;              // Unique message ID
    message_status?: string; // Message status
  }>;
}

Usage Patterns

1. Simple Message Sending

// Text message
await client.sendText('+1234567890', 'Hello World!');

// Image with caption
await client.sendImage('+1234567890', {
  link: 'https://example.com/image.jpg',
  caption: 'Check out this image!'
});

// Location
await client.sendLocation('+1234567890', 40.7128, -74.0060, {
  name: 'New York City',
  address: 'New York, NY, USA'
});

2. Interactive Messages

// Button menu
await client.sendButtons(
  '+1234567890',
  'Choose an option:',
  [
    { id: 'option1', title: 'Option 1' },
    { id: 'option2', title: 'Option 2' },
    { id: 'option3', title: 'Option 3' }
  ]
);

// List menu
await client.sendList(
  '+1234567890',
  'Select a category:',
  'View Options',
  [
    {
      title: 'Main Category',
      rows: [
        { id: 'item1', title: 'Item 1', description: 'First item' },
        { id: 'item2', title: 'Item 2', description: 'Second item' }
      ]
    }
  ]
);

3. Media Messages

// Upload and send
const mediaResponse = await client.uploadMedia(fileBuffer, 'image');
await client.sendImage('+1234567890', {
  id: mediaResponse.id,
  caption: 'Uploaded image'
});

// Send from URL
await client.sendDocument('+1234567890', {
  link: 'https://example.com/document.pdf',
  filename: 'important-document.pdf'
});

4. Template Messages

await client.sendTemplate(
  '+1234567890',
  'hello_world',
  'en_US',
  [
    {
      type: 'body',
      parameters: [
        { type: 'text', text: 'John' }
      ]
    }
  ]
);

Message Selection Guide

Choose Text Messages When:

  • Sending simple notifications
  • Providing information or updates
  • Responding to basic queries
  • URL sharing (with preview)

Choose Media Messages When:

  • Sharing visual content (images/videos)
  • Sending documents or files
  • Voice communications (audio)
  • Creative expression (stickers)

Choose Interactive Messages When:

  • Providing menu options
  • Collecting user choices
  • Creating conversational flows
  • Reducing typing for users

Choose Template Messages When:

  • Sending business notifications
  • Order confirmations
  • Appointment reminders
  • Promotional content (with approval)

Choose Location Messages When:

  • Sharing business addresses
  • Meeting point coordination
  • Delivery information
  • Geographic references

Choose Contact Messages When:

  • Sharing business contact info
  • Referrals and introductions
  • Support team information
  • Professional networking

Choose Broadcast Messages When:

  • Sending to multiple recipients
  • Order confirmations for many customers
  • Marketing campaigns (with approved templates)
  • System notifications to user base
  • Event announcements to subscriber list

Best Practices

1. Message Type Selection

// ✅ Good: Choose appropriate message type
// For simple confirmations
await client.sendText(to, 'Your order has been confirmed!');

// For choices
await client.sendButtons(to, 'Rate your experience:', [
  { id: 'excellent', title: '⭐⭐⭐⭐⭐' },
  { id: 'good', title: '⭐⭐⭐⭐' },
  { id: 'poor', title: '⭐⭐' }
]);

// For file sharing
await client.sendDocument(to, {
  link: documentUrl,
  filename: 'invoice.pdf',
  caption: 'Your invoice is attached'
});

2. Content Optimization

// ✅ Good: Optimize content for mobile
await client.sendText(
  to,
  'Order Update 📦\n\n' +
  '• Status: Shipped\n' +
  '• Tracking: 123456789\n' +
  '• ETA: Tomorrow 2-4 PM\n\n' +
  'Track: https://track.example.com/123456789'
);

3. Error Handling

try {
  const response = await client.sendImage(to, { link: imageUrl });
  console.log('Message sent:', response.messages[0].id);
} catch (error) {
  if (error instanceof MessageValidationError) {
    console.error('Invalid message:', error.field);
  } else if (error instanceof MediaProcessingError) {
    console.error('Media error:', error.message);
  }
}

4. Message Chaining

// Send related messages in sequence
async function sendOrderConfirmation(to: string, order: Order) {
  // 1. Confirmation text
  await client.sendText(to, `Order #${order.id} confirmed! 🎉`);
  
  // 2. Order details document
  await client.sendDocument(to, {
    link: order.invoiceUrl,
    filename: `invoice-${order.id}.pdf`,
    caption: 'Your order invoice'
  });
  
  // 3. Tracking options
  await client.sendButtons(to, 'What would you like to do?', [
    { id: 'track', title: '📦 Track Order' },
    { id: 'support', title: '💬 Contact Support' },
    { id: 'receipt', title: '📧 Email Receipt' }
  ]);
}

Platform Limitations

WhatsApp Business API Limits

  • Messages per second: Varies by tier (check Meta documentation)
  • Message retention: 30 days for media files
  • Template approval: Required for template messages
  • Business verification: Required for higher rate limits

SDK-Specific Features

  • Automatic retry: Built-in retry logic for failed messages
  • Rate limit handling: Automatic backoff when limits are reached
  • Validation: Pre-send validation to prevent API errors
  • Type safety: Full TypeScript support for all message types

Next Steps

I