Send your first WhatsApp message from Node.js
You need two values from the WhatsApp section of the App Dashboard: an access token and the ID of the business phone number you send from. A message to a number that is not in a customer service window can only be a template message. See Send a template message.
const client = new WhatsAppClient({ accessToken: process.env.WHATSAPP_ACCESS_TOKEN!, phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!,});
const res = await client.messages.sendText('15551234567', 'Hello from the SDK');console.log(res.messages[0]?.id); // the WhatsApp message ID (WAMID)sendText posts to /<PHONE_NUMBER_ID>/messages and returns the API response. The first entry in messages holds the WhatsApp message ID, which later appears in status webhooks. See Configuration for timeouts, retries and the API version, and Messaging for the other message types.
Independent open-source project. Not affiliated with, endorsed by or sponsored by Meta or WhatsApp. Released under the MIT licence. Source on GitHub.