VOOZH about

URL: https://dev.to/moatazkhaled93/send-whatsapp-messages-from-nodejs-in-3-lines-of-code-4bid

⇱ Send WhatsApp Messages from Node.js in 3 Lines of Code - DEV Community


If you've ever needed to send WhatsApp messages from a Node.js app — order notifications, OTP codes, shipping alerts — setting it up from scratch is always painful.

I built wasaas, an open-source Node.js SDK that makes it simple.

Install

npm install wasaas

Get a free API key at wasaas.org — 7-day trial, no credit card required.

Send a Message in 3 Lines

import { Wasaas } from "wasaas";

const client = new Wasaas({ apiKey: process.env.WASAAS_API_KEY! });

await client.messages.sendText({
 sessionId: "my-session",
 to: "966501234567",
 message: "Your order #1234 has shipped! 🚚",
});

Connect your WhatsApp number in the dashboard, grab your session ID, and you're live.

What Else Can It Do?

Send an image:

await client.messages.sendImage({
 sessionId: "my-session",
 to: "966501234567",
 imageUrl: "https://example.com/invoice.png",
 caption: "Invoice #1234",
});

Send a PDF or document:

import { readFileSync } from "fs";

const base64 = readFileSync("./invoice.pdf").toString("base64");

await client.messages.sendDocument({
 sessionId: "my-session",
 to: "966501234567",
 base64,
 filename: "invoice-1234.pdf",
 mime: "application/pdf",
 caption: "Your invoice is attached",
});

Check if a number has WhatsApp:

const result = await client.numbers.validate({
 sessionId: "my-session",
 phone: "966501234567",
});
// { exists: true, phone: "966501234567" }

Works with Express, Next.js, any Node framework

import express from "express";
import { Wasaas } from "wasaas";

const app = express();
const client = new Wasaas({ apiKey: process.env.WASAAS_API_KEY! });

app.post("/notify-order", express.json(), async (req, res) => {
 const { phone, orderId } = req.body;

 await client.messages.sendText({
 sessionId: process.env.WASAAS_SESSION_ID!,
 to: phone,
 message: `Order #${orderId} confirmed! We'll notify you when it ships.`,
 });

 res.json({ ok: true });
});

Full TypeScript Support

The package ships with complete TypeScript types — no @types package needed. Works with both ESM and CommonJS:

// CommonJS
const { Wasaas } = require("wasaas");
const client = new Wasaas({ apiKey: process.env.WASAAS_API_KEY });

Links

Would love your feedback — drop a comment or open an issue on GitHub!