WAHooks
SDKs

TypeScript SDK

Official WAHooks SDK for TypeScript and JavaScript

Installation

npm install @wahooks/sdk

Quick start

import { WAHooks } from '@wahooks/sdk';

const client = new WAHooks({ apiKey: 'wh_...' });

// List connections
const connections = await client.listConnections();

// Send a message
await client.sendMessage(connectionId, '1234@s.whatsapp.net', 'Hello!');

Configuration

const client = new WAHooks({
  apiKey: 'wh_...',
  baseUrl: 'https://api.wahooks.com', // optional, defaults to production
});

API Reference

Connections

// List all active connections
const connections: Connection[] = await client.listConnections();

// Create a new connection
const connection: Connection = await client.createConnection();

// Get a scannable connection (reuses idle or creates new)
const scannable = await client.getOrCreateScannableConnection();
// scannable.id, scannable.status, scannable.qr (base64 PNG)

// Get connection details
const connection: Connection = await client.getConnection(id);

// Delete a connection
await client.deleteConnection(id);

// Restart a connection
const connection: Connection = await client.restartConnection(id);

// Get QR code for linking
const qr = await client.getQR(connectionId);
// qr.value = base64 PNG

// Get recent chats
const chats: Chat[] = await client.getChats(connectionId);

// Get WhatsApp profile info
const profile: Profile = await client.getProfile(connectionId);

// Send a text message
const result: SendResult = await client.sendMessage(connectionId, chatId, text);

// Send an image (by URL)
await client.sendImage(connectionId, chatId, { url: 'https://example.com/photo.jpg', caption: 'Check this out' });

// Send an image (by base64)
await client.sendImage(connectionId, chatId, { data: 'iVBORw0KGgo...', mimetype: 'image/png' });

// Send a document
await client.sendDocument(connectionId, chatId, { url: 'https://example.com/report.pdf', filename: 'report.pdf' });

// Send a video
await client.sendVideo(connectionId, chatId, { url: 'https://example.com/clip.mp4', caption: 'Watch this' });

// Send audio
await client.sendAudio(connectionId, chatId, { url: 'https://example.com/voice.ogg' });

// Send a location
await client.sendLocation(connectionId, chatId, 37.7749, -122.4194, 'San Francisco', '123 Main St');

// Send a contact card
await client.sendContact(connectionId, chatId, 'John Doe', '1234567890');

Webhooks

// List webhooks for a connection
const webhooks: WebhookConfig[] = await client.listWebhooks(connectionId);

// Create a webhook
const webhook: WebhookConfig = await client.createWebhook(
  connectionId,
  'https://example.com/hook',
  ['message', 'message.any'] // optional, defaults to ['*']
);

// Update a webhook
const updated: WebhookConfig = await client.updateWebhook(webhookId, {
  url: 'https://example.com/new-hook',
  events: ['message'],
  active: false,
});

// Delete a webhook
await client.deleteWebhook(webhookId);

// Get delivery logs
const logs: WebhookLog[] = await client.getWebhookLogs(webhookId);

// Send a test event
const result = await client.testWebhook(webhookId);

API Tokens

// List active tokens
const tokens: ApiToken[] = await client.listTokens();

// Create a new token (raw token shown once)
const token = await client.createToken('my-token');
console.log(token.token); // "wh_a1b2c3..."

// Revoke a token
await client.revokeToken(tokenId);

Error handling

The SDK throws WAHooksError for non-2xx responses:

import { WAHooks } from '@wahooks/sdk';

try {
  await client.getConnection('nonexistent-id');
} catch (error) {
  if (error instanceof Error && 'statusCode' in error) {
    console.log(error.message);    // "Connection not found"
    console.log(error.statusCode); // 404
    console.log(error.body);       // full error response
  }
}

Types

The SDK exports all types for TypeScript users:

import type {
  Connection,
  ScannableConnection,
  WebhookConfig,
  WebhookLog,
  ApiToken,
  Chat,
  Profile,
  SendResult,
  WAHooksOptions,
} from '@wahooks/sdk';

On this page