Getting started

Quick start

From npm install to a delivered WhatsApp message in about five minutes.

1. Install

npm install wapi-cloud

2. Create the client

Instantiate Whatsapp once and reuse it across your application. Only accessToken and phoneNumberId are strictly required to send messages — optional parameters unlock additional modules.

whatsapp.ts
import { Whatsapp } from "wapi-cloud";

export const whatsapp = new Whatsapp({
  accessToken: process.env.WA_TOKEN!,
  phoneNumberId: process.env.WA_PHONE_ID!,
  businessAccountId: process.env.WA_WABA_ID!, // needed for templates/flows/QR/analytics
  appSecret: process.env.WA_APP_SECRET!,      // needed for webhook signature verification
  businessId: process.env.WA_BUSINESS_ID,     // needed for catalogs.list()
  appId: process.env.WA_APP_ID,               // needed for embedded signup
});

3. Send your first message

send.ts
import { whatsapp } from "./whatsapp";

const { data, error } = await whatsapp.messages.sendText(
  "15551234567",
  { body: "Hello from wapi-cloud!" }
);

if (error) {
  console.error("Send failed:", error.code, error.type, error.message);
} else {
  console.log("Message sent successfully! ID:", data.messageId);
}
Recipient numbers must be in international format without a leading + (for example 15551234567). Outside of an approved template message, you can only send free-form messages to a user who has messaged your business within the last 24 hours (Meta's "customer service window").

4. Send a template message

Template messages can be sent outside the 24-hour window and are required to initiate conversations with customers. Create templates in Meta Business Manager or via the templates module, then send them by name:

send-template.ts
const { data, error } = await whatsapp.messages.sendTemplate("15551234567", {
  name: "order_confirmation",
  language: "en_US",
  components: [
    {
      type: "body",
      parameters: [{ type: "text", text: "Jordan" }],
    },
  ],
});

if (!error) {
  console.log("Template sent! ID:", data.messageId);
}

5. Root-level sugar

For the two most common calls, wapi-cloud provides convenient shortcuts directly on the client instance:

// Sugar for whatsapp.messages.sendText()
await whatsapp.send("15551234567", { body: "Hello!" });

// Sugar for whatsapp.messages.sendTemplate()
await whatsapp.sendTemplate("15551234567", {
  name: "order_confirmation",
  language: "en_US",
});

Next steps