![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
whatsapp-business
Advanced tools
Node.js connector for the WhatsApp Business APIs with TypeScript support, integration tests and more.
Node.js connector for WhatsApp Business Cloud API, with TypeScript support.
This project offers a solution to easily interact with WhatsApp Business Cloud API with Heavy integration testing with real API calls to support implementation stability. Built with Axios and no other extra dependency!
The connector is fully typed, tested and documented!
npm install whatsapp-business
yarn add whatsapp-business
Most methods accept JS objects. These can be populated using parameters specified by WhatsApp's API documentation or following the typescript schema.
import { WABAClient, WABAErrorAPI } from "whatsapp-business";
//You cant get it from the meta for developers app administration
const client = new WABAClient({
accountId: "YOUR_ACCOUNT_ID",
apiToken: "YOUR_API_TOKEN",
phoneId: "YOUR_BUSINESS_PHONE_ID",
});
const foo = async () => {
try {
const res = await client.getBusinessPhoneNumbers();
console.log(res);
} catch (err) {
const error: WABAErrorAPI = err;
console.error(error.message);
}
};
foo();
const sendTextMessage = async (body: string, to: string) => {
try {
const res = await client.sendMessage({ type: "text", text: { body }, to });
console.log(res);
} catch (err) {
const error: WABAErrorAPI = err;
console.error(error.message);
}
};
import { WebhookClient, WABAClient } from "./index";
//The token and path must match the values you set on the application management
//More info here https://developers.facebook.com/docs/whatsapp/business-management-api/guides/set-up-webhooks
const webhookClient = new WebhookClient({
token: "YOUR_VALIDATION_TOKEN",
path: "/whatsapp/business",
});
const wabaClient = new WABAClient({
accountId: "ACCOUNT_ID",
phoneId: "PHONE_ID",
apiToken: "API_TOKEN",
});
//init webhooks takes an object of functions that will be triggered based on the received webhook event type
webhookClient.initWebhook({
onTextMessageReceived: async (payload, contact) => {
try {
await waba_client.markMessageAsRead(payload.id.toString());
await waba_client.sendMessage({
type: "text",
to: contact.wa_id,
text: { body: "Ok!" },
});
} catch (err) {
console.log(err);
}
},
});
Cloud API |
---|
|
|
|
|
|
|
Webhooks |
---|
|
|
Business Management API |
---|
Currently working on |
Analytics API |
---|
Planning to add future support |
This project uses typescript. Resources are stored in 2 key structures:
Contributions are encouraged, I will review any incoming pull requests.
If you found this project interesting or useful, you can give this project a star. Thank you!
Or buy me a coffee using any of these:
1MjRd2YNNjEx3ze1Y71UNSgbAF9XECKTP1
0xde25d72e9e87513b9c8dad8de11e2d8332276c7e
0xde25d72e9e87513b9c8dad8de11e2d8332276c7e
FAQs
Node.js connector for the WhatsApp Business APIs with TypeScript support, integration tests and more.
The npm package whatsapp-business receives a total of 612 weekly downloads. As such, whatsapp-business popularity was classified as not popular.
We found that whatsapp-business demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.