WhatsApp Cloud TS

Getting Started

Learn how to install and set up the WhatsApp Cloud TS client in your project.

Installation

Install the package using npm (or your preferred package manager).

npm install whatsapp-cloud-ts

Client Configuration

First, create a .env file in the root of your project and add your credentials from the Meta App Dashboard:

WA_ACCESS_TOKEN=your_permanent_or_temporary_token
WA_PHONE_NUMBER_ID=your_phone_number_id

Then, initialize the WhatsAppClient with these credentials to start sending messages:

import { WhatsAppClient } from "whatsapp-cloud-ts";

const client = new WhatsAppClient({
  accessToken: process.env.WA_ACCESS_TOKEN,
  phoneNumberId: process.env.WA_PHONE_NUMBER_ID,
});

WhatsAppClientConfig Properties

PropertyTypeRequiredDescription
accessTokenstringYesPermanent or temporary access token from Meta App Dashboard.
phoneNumberIdstringYesThe unique ID of the WhatsApp Business phone number you are sending messages from.
apiVersionstringNoThe Graph API version to use. Defaults to "v25.0".

Quick Start

Once initialized, you can easily define a template and send it with strict typing.

import { defineTemplate } from "whatsapp-cloud-ts";

// 1. Define your template with strict typing
const orderTemplate = defineTemplate({
  name: "order_confirmation",
  language: "en_US",
  header: { type: "IMAGE" },
  body: {
    params: { 1: "customerName", 2: "orderId" },
  },
} as const); // 'as const' is required for type inference!

// 2. Send it with full IDE autocomplete!
await client.sendFromDefinition(orderTemplate, "919876543210", {
  customerName: "Rahul",
  orderId: "#12345",
  header: { url: "https://example.com/banner.jpg" },
});