Skip to main content

Constructor

WhatsAppClient(config)

Creates a new WhatsApp client instance.
Parameters:
  • config (WhatsAppConfig): Client configuration object
Example:

Message Sending Methods

sendText(to, text, options?)

Sends a text message to a WhatsApp user.
Parameters:
  • to (string): Recipient phone number in international format
  • text (string): Message text (max 4,096 characters)
  • options (TextOptions, optional): Additional options
TextOptions:
Example:

sendImage(to, image, options?)

Sends an image message.
Parameters:
  • to (string): Recipient phone number
  • image (ImageMedia): Image data
  • options (MessageOptions, optional): Additional options
ImageMedia:
Example:

sendVideo(to, video, options?)

Sends a video message.
VideoMedia:

sendAudio(to, audio, options?)

Sends an audio message.
AudioMedia:

sendDocument(to, document, options?)

Sends a document file.
DocumentMedia:

sendButtons(to, text, buttons, options?)

Sends an interactive message with buttons.
Parameters:
  • buttons (Button[]): Array of buttons (max 3)
Button:
Example:

sendList(to, text, buttonText, sections, options?)

Sends an interactive list message.
ListSection:

sendTemplate(to, templateName, languageCode, components?)

Sends a template message.

sendLocation(to, latitude, longitude, options?)

Sends a location message.
LocationOptions:

sendContacts(to, contacts, options?)

Sends contact information.

sendSticker(to, sticker, options?)

Sends a sticker message.

Media Management Methods

uploadMedia(file, type)

Uploads a media file to WhatsApp servers.
Parameters:
  • file (Buffer | string): File buffer or file path
  • type (string): Media type
Returns:
Example:

getMediaInfo(mediaId)

Gets information about uploaded media.
Returns:

downloadMedia(mediaId)

Downloads media content as a buffer.
Example:

Webhook Methods

verifyWebhook(mode, token, challenge)

Verifies webhook subscription requests.
Parameters:
  • mode (string): Hub mode from query parameters
  • token (string): Verify token from query parameters
  • challenge (string): Challenge string from query parameters
Returns:
  • Challenge string if verification succeeds
  • null if verification fails

parseWebhook(payload)

Parses incoming webhook messages.
Returns: Array of processed incoming messages

createWebhookProcessor(handlers)

Creates a framework-agnostic webhook processor.
Example:

Utility Methods

testConnection()

Tests connectivity to the WhatsApp API.
Returns:
  • true if connection is successful
  • false if connection fails
Example:

getConfig()

Gets the current client configuration (with masked sensitive data).
Example:

Response Types

MessageResponse

Standard response for message sending operations.

ProcessedIncomingMessage

Parsed incoming message from webhooks.

Error Handling

All methods can throw the following error types:
  • ConfigurationError: Invalid client configuration
  • MessageValidationError: Invalid message content
  • WhatsAppApiError: API errors from Meta
  • RateLimitError: Rate limiting
  • MediaProcessingError: Media upload/download errors
  • WebhookVerificationError: Webhook verification failures
Example:

Method Chaining

Some operations can be chained for efficiency:

Configuration Options

WhatsAppConfig Interface