whatify-whatsapp-client
v1.1.3
Published
Free WhatsApp API client for Whatify platform
Maintainers
Readme
Whatify
Free WhatsApp API client for Whatify platform.
Getting Started
Before using this SDK, you need to sign up to get a free API token at https://whatify.dev
Installation
npm install whatify-whatsapp-clientUsage
Initialize the client
import { Whatify } from "whatify-whatsapp-client";
// Initialize with API token
const client = new Whatify({
apiToken: "your-api-token-here",
});Connect to WhatsApp
// Connect with QR Code (default)
const result = await client.connect();
console.log(result.qrCode); // Display QR code to user
// Connect with Pairing Code
const result = await client.connect({
method: "pairingCode",
phoneNumber: "1234567890",
});
console.log(result.pairingCode); // Display pairing code to user
// Force new connection
const result = await client.connect({
forceNew: true,
});Check Connection Status
const status = await client.status();
console.log(status);
// {
// success: true,
// status: 'connected',
// phone: '1234567890',
// name: 'My WhatsApp',
// profilePic: 'https://...'
// }Disconnect from WhatsApp
const result = await client.disconnect();
console.log(result);
// { success: true, message: 'Disconnected successfully' }Send Messages
Send text message
const result = await client.send({
to: "1234567890",
text: "Hello, World!",
});Send to multiple recipients
const result = await client.send({
to: ["1234567890", "0987654321"],
text: "Hello, everyone!",
});Send image with caption
const result = await client.send({
to: "1234567890",
text: "Check out this image!",
attachment: {
type: "image",
url: "https://example.com/image.jpg",
caption: "Beautiful sunset",
},
});Send document from base64
const result = await client.send({
to: "1234567890",
attachment: {
type: "document",
base64: "base64-encoded-data...",
filename: "report.pdf",
mimeType: "application/pdf",
caption: "Monthly report",
},
});Send attachment only (no text)
const result = await client.send({
to: "1234567890",
attachment: {
type: "video",
url: "https://example.com/video.mp4",
},
});Send OTP (One-Time Password)
Send OTP codes via WhatsApp with multi-language support.
Send OTP in English (default)
const result = await client.sendOtp({
phone: "1234567890",
code: "123456",
});Send OTP in Arabic
const result = await client.sendOtp({
phone: "1234567890",
code: 123456, // Can be string or number
language: "Arabic",
});Response:
{
success: true,
message: "OTP sent successfully",
data: {
messageId: "msg-xxx",
whatsappMessageId: "wamid.xxx",
phone: "1234567890",
code: "123456",
language: "English",
sentAt: "2024-01-01T12:00:00.000Z",
}
}API Reference
new Whatify(config)
Create a new Whatify client instance.
Parameters:
config.apiToken(string, required): Your API token
client.connect(options?)
Connect to WhatsApp.
Parameters:
options.method('qrCode' | 'pairingCode', optional): Connection methodoptions.phoneNumber(string, optional): Phone number for pairing code methodoptions.forceNew(boolean, optional): Force new connectionoptions.rawQrCode(boolean, optional): Return raw QR code data
Returns: Promise<ConnectResponse>
client.disconnect()
Disconnect from WhatsApp.
Returns: Promise<DisconnectResponse>
client.status()
Get current WhatsApp connection status.
Returns: Promise<StatusResponse>
client.send(options)
Send a WhatsApp message.
Parameters:
options.to(string | string[], required): Recipient phone number(s)options.text(string, optional): Message textoptions.attachment(object, optional): Attachment objecttype('image' | 'video' | 'audio' | 'document' | 'sticker', required)url(string, optional): URL to the attachmentbase64(string, optional): Base64 encoded attachment datafilename(string, optional): Filename for the attachmentcaption(string, optional): Caption for the attachmentmimeType(string, optional): MIME type of the attachment
options.existingMessageId(string, optional): Existing message ID to reply to
Note: Either text or attachment must be provided.
Returns: Promise<SendMessageResponse>
client.sendOtp(options)
Send an OTP (One-Time Password) via WhatsApp with multi-language support.
Parameters:
options.phone(string, required): Recipient phone number with country code (minimum 10 digits)options.code(string | number, required): OTP code (4-8 digits)options.language('Arabic' | 'English', optional): Language for OTP message (default: 'English')
Returns: Promise<SendOtpResponse>
Rate Limit: 10 requests per minute
Example Response:
{
success: true,
message: "OTP sent successfully",
data: {
messageId: "msg-xxx",
whatsappMessageId: "wamid.xxx",
phone: "1234567890",
code: "123456",
language: "English",
sentAt: "2024-01-01T12:00:00.000Z",
}
}TypeScript Support
This package includes TypeScript definitions out of the box.
License
MIT
