Whatify LogoWhatify
SDKs

Node.js / Bun / TypeScript SDK

Official Whatify SDK for Node.js and TypeScript applications

Before using this SDK, sign up at https://whatify.dev to get your API token.

Installation

npm install whatify-whatsapp-client
# or
yarn add whatify-whatsapp-client
# or
pnpm add whatify-whatsapp-client

Quick Start

import { Whatify } from "whatify-whatsapp-client";

const client = new Whatify({
  apiToken: "your-api-token",
});

Configuration

const client = new Whatify({
  apiToken: "your-api-token",
});

Using API Key

const client = new Whatify({
  apiKey: "your-api-key",
});

API Methods

Connect Device

Connect your WhatsApp device to start sending messages.

try {
  const result = await client.connect();
  console.log("QR Code:", result.qrCode);
  console.log("Status:", result.status);
} catch (error) {
  console.error("Connection failed:", error);
}

Response:

{
  success: boolean;
  qrCode?: string;
  status: 'connected' | 'qr' | 'disconnected';
  message: string;
}

Disconnect Device

Disconnect your WhatsApp device.

try {
  const result = await client.disconnect();
  console.log("Disconnected:", result.success);
} catch (error) {
  console.error("Disconnect failed:", error);
}

Response:

{
  success: boolean;
  message: string;
}

Check Status

Check the connection status of your WhatsApp device.

try {
  const result = await client.status();
  console.log("Status:", result.status);
  console.log("Connected:", result.isConnected);
} catch (error) {
  console.error("Status check failed:", error);
}

Response:

{
  success: boolean;
  status: "connected" | "qr" | "disconnected";
  isConnected: boolean;
  message: string;
}

Send Message

Send text messages, attachments, or both.

Send Text Message

try {
  const result = await client.send({
    to: "1234567890",
    text: "Hello from Whatify!",
  });
  console.log("Message sent:", result.success);
} catch (error) {
  console.error("Send failed:", error);
}

Send to Multiple Recipients

const result = await client.send({
  to: ["1234567890", "0987654321"],
  text: "Bulk message to multiple contacts",
});

Send Attachment

const result = await client.send({
  to: "1234567890",
  attachment: {
    type: "image",
    url: "https://example.com/image.jpg",
    caption: "Check out this image!",
  },
});

Send Text with Attachment

const result = await client.send({
  to: "1234567890",
  text: "Here is the document you requested",
  attachment: {
    type: "document",
    url: "https://example.com/document.pdf",
    filename: "report.pdf",
  },
});

Attachment Types:

  • image - Image files (jpg, png, gif, etc.)
  • video - Video files
  • audio - Audio files
  • document - Documents (pdf, docx, xlsx, etc.)

Response:

{
  success: boolean;
  message: string;
  messageIds?: string[];
}

Send OTP

Send One-Time Password (OTP) codes via WhatsApp with multi-language support.

Send OTP (English)

try {
  const result = await client.sendOTP({
    phone: "1234567890",
    code: "123456",
    language: "English",
  });
  console.log("OTP sent:", result.data);
} catch (error) {
  console.error("Failed to send OTP:", error);
}

Send OTP (Arabic)

const result = await client.sendOTP({
  phone: "1234567890",
  code: "654321",
  language: "Arabic",
});

Generate and Send OTP

// Generate a random 6-digit OTP
const otpCode = Math.floor(100000 + Math.random() * 900000).toString();

const result = await client.sendOTP({
  phone: "1234567890",
  code: otpCode,
  language: "English",
});

// Store OTP in database for verification
await db.otp.create({
  phone: "1234567890",
  code: otpCode,
  expiresAt: new Date(Date.now() + 10 * 60 * 1000), // 10 minutes
});

OTP Options:

  • phone - Recipient phone number with country code
  • code - OTP code (4-8 digits, string or number)
  • language - Message language: "English" or "Arabic" (default: "English")

Response:

{
  success: boolean;
  message: string;
  data?: {
    messageId: string;
    whatsappMessageId: string;
    phone: string;
    code: string;
    language: string;
    sentAt: string;
  };
}

Expamle OTP Message:

  • English: 123456 is your verification code. For your security, do not share this code
  • Arabic: 123456 هذا هو رمز التحقق الخاص بك. لحمايتك، يرجى عدم مشاركة هذا الرمز.

Error Handling

The SDK throws errors for failed requests. Always wrap calls in try-catch blocks:

try {
  const result = await client.send({
    to: "1234567890",
    text: "Hello!",
  });
} catch (error) {
  if (error.response) {
    // API returned an error response
    console.error("API Error:", error.response.data);
  } else if (error.request) {
    // Request was made but no response received
    console.error("Network Error:", error.message);
  } else {
    // Something else happened
    console.error("Error:", error.message);
  }
}

TypeScript Support

The SDK is written in TypeScript and includes full type definitions:

import { Whatify, SendMessageRequest, SendMessageResponse } from "whatify";

const client = new Whatify({ apiToken: "your-token" });

const request: SendMessageRequest = {
  to: "1234567890",
  text: "Typed message",
};

const response: SendMessageResponse = await client.send(request);

Examples

Express.js Integration

import express from "express";
import { Whatify } from "whatify";

const app = express();
const client = new Whatify({ apiToken: process.env.WHATIFY_API_TOKEN! });

app.post("/send-notification", async (req, res) => {
  try {
    const result = await client.send({
      to: req.body.phone,
      text: req.body.message,
    });
    res.json(result);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

app.listen(3000);

Next.js API Route

import { Whatify } from "whatify";
import type { NextApiRequest, NextApiResponse } from "next";

const client = new Whatify({
  apiToken: process.env.WHATIFY_API_TOKEN!,
});

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  if (req.method !== "POST") {
    return res.status(405).json({ error: "Method not allowed" });
  }

  try {
    const result = await client.send({
      to: req.body.to,
      text: req.body.text,
    });
    res.status(200).json(result);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
}

NestJS Service

import { Injectable } from "@nestjs/common";
import { Whatify } from "whatify";

@Injectable()
export class WhatsAppService {
  private client: Whatify;

  constructor() {
    this.client = new Whatify({
      apiToken: process.env.WHATIFY_API_TOKEN,
    });
  }

  async sendNotification(to: string, message: string) {
    return await this.client.send({ to, text: message });
  }

  async checkStatus() {
    return await this.client.status();
  }
}

Rate Limits

The API has the following rate limits:

  • 100 requests per minute per API token
  • 1000 requests per hour per API token

The SDK does not automatically handle rate limiting. Implement your own retry logic if needed:

async function sendWithRetry(data: SendMessageRequest, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await client.send(data);
    } catch (error) {
      if (error.response?.status === 429 && i < maxRetries - 1) {
        await new Promise((resolve) => setTimeout(resolve, 1000 * (i + 1)));
        continue;
      }
      throw error;
    }
  }
}

Support

For issues and questions: