The bot's phone ID
The users' phone numbers
A Whatsapp message, built using the corresponding module for each type of message.
The number of messages to send per batch
The delay between each batch of messages in milliseconds
The server's responses
import { WhatsAppAPI } from "whatsapp-api-js";
import { Text } from "whatsapp-api-js/messages/text";
const Whatsapp = new WhatsAppAPI({
token: "YOUR_TOKEN",
appSecret: "YOUR_APP_SECRET"
});
const phoneID = "YOUR_BOT_NUMBER";
const users = ["YOUR_USER1_NUMBER", "YOUR_USER2_NUMBER"];
const message = new Text("Hello World");
const responses = Whatsapp.broadcastMessage(phoneID, users, message);
Promise.all(responses).then(console.log);
The type of the data to be used in the message builder
The bot's phone ID
The users' data
A Whatsapp message builder, it returns an array with the phone number and the message.
The number of messages to send per batch
The delay between each batch of messages in milliseconds
The server's responses
import { WhatsAppAPI } from "whatsapp-api-js";
import { Text } from "whatsapp-api-js/messages/text";
const Whatsapp = new WhatsAppAPI({
token: "YOUR_TOKEN",
appSecret: "YOUR_APP_SECRET"
});
const phoneID = "YOUR_BOT_NUMBER";
const users = [{ user: "USER1_ID" }, { user: "USER2_ID" }];
const message_builder = ({ user }) => [DB.fetch(user).phone, new Text(`Hello ${user}`)];
const responses = Whatsapp.broadcastMessage(phoneID, users, message);
Promise.all(responses).then(console.log);
Mark a message as read, and optionally include a reply indicator
The bot's phone ID
The message ID
Optional
indicator: "text"The type of reply indicator
The server response
Send a Whatsapp message
The bot's phone ID
The user's phone number
A Whatsapp message, built using the corresponding module for each type of message.
Optional
context: stringThe message ID of the message to reply to
Optional
biz_opaque_callback_data: stringAn arbitrary 512B string, useful for tracking (length not checked by the framework)
The server response
Send a Whatsapp message to multiple phone numbers.
In order to avoid reaching the API rate limit, this method will send the messages in batches of 50 per second by default, but this can be changed using the
batch_size
anddelay
parameters.The API rate limit can be increased by contacting Facebook as explained here.