Skip to main content
The WSAPI Node.js SDK provides a strongly-typed client for sending WhatsApp messages, managing groups and chats, and receiving real-time events.

Installation

Requirements

  • Node.js 20.0 or later
  • Valid WSAPI API key and instance ID

Quick start

baseUrl, apiKey and instanceId are all required: the constructor throws if any of them is missing. Recipients use the WhatsApp JID format, <number>@s.whatsapp.net for people and <id>@g.us for groups.

Method naming

Two conventions apply to every client:
  • All methods end in Async and return a Promise.
  • Each method has a try prefixed twin (sendTextAsync and trySendTextAsync). The plain method throws ApiException on failure; the try variant never throws and returns an ApiResponse instead.

API surface

WSApiClient groups every operation under a namespace:

Error handling

Methods throw ApiException on failure. The API error body is available on problem:

Sending media

Media requests use url for a remote file or data for base64 content. Documents also require filename. Use mimeType when needed (voice uses OGG; stickers use WebP). Legacy names such as imageUrl, imageBase64 and fileName remain accepted and are translated before sending; canonical fields take precedence.
mentions, replyTo, replyToSenderId, ephemeralExpiration and isForwarded are accepted by every message type:

Acting on a message

Reactions, edits, receipts and deletions take the message ID as the first argument and the rest of the payload as the second:
In a group, chatId is the group JID and senderId is the participant who sent the message. In a one to one chat both are the same JID.

Groups, chats, contacts and session

Participants are added, removed, promoted and demoted through a single call:

Receiving events

WSAPI delivers events to your own endpoint as a webhook. Point your instance at an HTTPS URL and parse the body with EventFactory. When a signing secret is configured, verifySignature checks the X-Webhook-Signature header for you, in constant time:
EventFactory.parseEvent throws on an event type it does not know, so keep the handler in a try/catch if you want unknown events to be ignored rather than to fail the delivery. See Events for the payload envelope and the full list of event types.

Account and compatibility

Account operations are Cloud-only; the OSS administrative API is separate. Create a named Cloud instance with client.account.createSubscriptionInstanceAsync(subscriptionId, "Support") (also available in the Try variant). Session responses use isConnected, isLoggedIn and deviceId; QR text is code. Invite-link responses use link; joining via link returns id. Joining via invite returns no object (HTTP 204). To rotate a link, call getInviteLinkAsync(groupId, true). Message events, including history messages, expose optional adReferral. Persist message.adReferral?.ctwaClid when present; subsequent messages may not contain attribution.

GitHub

github.com/wsapi-chat/wsapi-node