Constructor
WhatsAppClient(config)
Creates a new WhatsApp client instance.config(WhatsAppConfig): Client configuration object
Message Sending Methods
sendText(to, text, options?)
Sends a text message to a WhatsApp user.to(string): Recipient phone number in international formattext(string): Message text (max 4,096 characters)options(TextOptions, optional): Additional options
sendImage(to, image, options?)
Sends an image message.to(string): Recipient phone numberimage(ImageMedia): Image dataoptions(MessageOptions, optional): Additional options
sendVideo(to, video, options?)
Sends a video message.sendAudio(to, audio, options?)
Sends an audio message.sendDocument(to, document, options?)
Sends a document file.sendButtons(to, text, buttons, options?)
Sends an interactive message with buttons.buttons(Button[]): Array of buttons (max 3)
sendList(to, text, buttonText, sections, options?)
Sends an interactive list message.sendTemplate(to, templateName, languageCode, components?)
Sends a template message.sendLocation(to, latitude, longitude, options?)
Sends a location message.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.file(Buffer | string): File buffer or file pathtype(string): Media type
getMediaInfo(mediaId)
Gets information about uploaded media.downloadMedia(mediaId)
Downloads media content as a buffer.Webhook Methods
verifyWebhook(mode, token, challenge)
Verifies webhook subscription requests.mode(string): Hub mode from query parameterstoken(string): Verify token from query parameterschallenge(string): Challenge string from query parameters
- Challenge string if verification succeeds
nullif verification fails
parseWebhook(payload)
Parses incoming webhook messages.createWebhookProcessor(handlers)
Creates a framework-agnostic webhook processor.Utility Methods
testConnection()
Tests connectivity to the WhatsApp API.trueif connection is successfulfalseif connection fails
getConfig()
Gets the current client configuration (with masked sensitive data).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