Skip to main content
Use whatsappBusiness.config(...) with credentials from Meta for Developers.

Config

whatsappBusiness.config({
  accessToken: "your-access-token",
  phoneNumberId: "your-phone-number-id",
  appSecret: "your-app-secret",
});
OptionDescriptionEnv fallback
accessTokenPermanent or system-user token from Meta for Developers.SPECTRUM_WHATSAPP_BUSINESS_ACCESS_TOKEN
phoneNumberIdThe phone number ID for the business account sending messages.SPECTRUM_WHATSAPP_BUSINESS_PHONE_NUMBER_ID
appSecretApp secret used to verify webhook payload signatures.SPECTRUM_WHATSAPP_BUSINESS_APP_SECRET
Each option falls back to its environment variable when omitted (an explicit value always wins). If you set both SPECTRUM_WHATSAPP_BUSINESS_ACCESS_TOKEN and SPECTRUM_WHATSAPP_BUSINESS_PHONE_NUMBER_ID, calling whatsappBusiness.config() with no arguments boots the provider in direct mode from the environment. A partial set (only one of the two) instead falls back to cloud mode, which uses your projectId/projectSecret. Find these values in your WhatsApp Business app settings on Meta for Developers.

Example

import { Spectrum } from "spectrum-ts";
import { whatsappBusiness } from "spectrum-ts/providers/whatsapp-business";

const app = await Spectrum({
  providers: [
    whatsappBusiness.config({
      accessToken: process.env.WA_TOKEN!,
      phoneNumberId: process.env.WA_NUMBER_ID!,
      appSecret: process.env.WA_SECRET!,
    }),
  ],
});

for await (const [space, message] of app.messages) {
  if (message.content.type === "text") {
    await message.reply(`Got it: ${message.content.text}`);
  }
}