Tutorial & SDK Guide

How to Send WhatsApp Messages with Node.js.

A comprehensive, production-ready guide to integrating Wapix WhatsApp OTP and transactional messaging into your Node.js and TypeScript applications.

Prerequisites

  • 1. Node.js v18.0.0 or higher installed.
  • 2. An active Wapix API key (generated from your Console dashboard).
  • 3. A connected WhatsApp session with status 'WORKING'.
  • 4. Minimum ₹50 prepaid wallet balance.

Step 1: Install HTTP Client

Install Axios or use Node 18+ native Fetch:

npm install axios dotenv

Step 2: Send WhatsApp OTP Verification Code

Create an `otpService.js` module to send verification codes:

import axios from "axios";
import dotenv from "dotenv";
dotenv.config();

export async function sendOtp(phoneNumber, otpCode) {
  try {
    const payload = {
      service: "otp",
      whatsaap_number: phoneNumber, // e.g. "919876543210"
      otp: otpCode,
      text: "Your secure login passcode is:",
      api_key: process.env.WAPIX_API_KEY
    };

    const response = await axios.post("https://api.wapix.sbs/api/v1/send/otp", payload);
    return response.data;
  } catch (error) {
    console.error("Error sending OTP:", error.response?.data || error.message);
    throw error;
  }
}

Step 3: Send Single Transactional Message

export async function sendOrderAlert(phoneNumber, orderId, trackingUrl) {
  const payload = {
    service: "message",
    whatsaap_number: phoneNumber,
    text: `Order #${orderId} is confirmed! Track shipment: ${trackingUrl}`,
    api_key: process.env.WAPIX_API_KEY
  };

  const response = await axios.post("https://api.wapix.sbs/api/v1/send/message", payload);
  return response.data;
}

Step 4: Receive Customer Replies in Express

import express from "express";

const app = express();
app.use(express.json());

app.post("/webhook", (req, res) => {
  const { event, data } = req.body;
  if (event === "message") {
    console.log(`New inbound message from ${data.from}: ${data.body}`);
  }
  return res.sendStatus(200);
});

app.listen(3000, () => console.log("Server listening on port 3000"));
Also developing in Python?Explore Python Guide →