Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.photon.codes/docs/llms.txt

Use this file to discover all available pages before exploring further.

import { whatsappBusiness } from "spectrum-ts/providers/whatsapp-business";
The WhatsApp Business provider wraps the official WhatsApp Business Cloud API. Reactions and threaded replies map to native WhatsApp features.
WhatsApp Business supports 1:1 conversations only. The API does not expose group management for business accounts — calling space(userA, userB) throws.

Config

whatsappBusiness.config({
  accessToken: "your-access-token",
  phoneNumberId: "your-phone-number-id",
  appSecret: "your-app-secret",
});
OptionDescription
accessTokenPermanent or system-user token from Meta for Developers.
phoneNumberIdThe phone number ID for the business account sending messages.
appSecretApp secret used to verify webhook payload signatures.
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}`);
  }
}

Starting a conversation

Resolve a user by their WhatsApp phone number (international format, digits only) and open a 1:1 space:
const wa = whatsappBusiness(app);
const customer = await wa.user("15551234567");
const space = await wa.space(customer);

await space.send("Thanks for reaching out.");
Passing more than one user to space() throws — the provider rejects group creation explicitly.