![GitHub top language](https://img.shields.io/github/languages/top/MarcosNicolau/whatsapp-business-sdk)
WhatsApp Business API SDK
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!
Installation
npm install whatsapp-business
yarn add whatsapp-business
Documentation
Most methods accept JS objects. These can be populated using parameters specified by WhatsApp's API documentation or following the typescript schema.
Usage
Basic usage
import { WABAClient, WABAErrorAPI } from "whatsapp-business";
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();
Sending a message
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);
}
};
Support
Cloud API | Business Management API | Analytics API |
---|
- - [x] Business profiles endpoints
| Currently working on | Planning to add future support |
| | |
| | |
- - [x] Phone Numbers endpoints
| | |
- - [x] Registration endpoints
| | |
- - [x] Two-Step-Verification endpoints
| | |
| | |
Webhooks
Although there is no current support for managing webhooks from the API, you can access the Webhooks response types
import { Webhook } from "whatsapp-business";
const webhookListener = (res: Webhook) => {};
Project
Structure
This project uses typescript. Resources are stored in 2 key structures:
- src: the whole connector written in typescript
- dist the packed bundle of the project for use in nodejs environments.
Contribution and thanks
Contributions are encouraged, I will review any incoming pull requests.
Donations
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:
- BTC:
1MjRd2YNNjEx3ze1Y71UNSgbAF9XECKTP1
- ETH:
0xde25d72e9e87513b9c8dad8de11e2d8332276c7e
- USDC:
0xde25d72e9e87513b9c8dad8de11e2d8332276c7e