bhoriwal-sdk
v2.0.28
Published
π Powerful WhatsApp Cloud API SDK for Node.js β Send messages, templates, media, flows & more with ease
Maintainers
Readme
π Bhoriwal WhatsApp SDK
A simple, powerful, and reusable SDK for the WhatsApp Cloud API.
Built for:
- Multi-project usage
- SaaS platforms
- Backend automation systems
β¨ Features
- β Send Text Messages
- β Send Media (Image, Video, Document, Audio)
- β Send Template Messages
- β Interactive Button Messages
- β WhatsApp Flows Support
- β Bulk Messaging
- β Phone Number Reachability Check
- β Mark Messages as Read
- β Block / Unblock Users
- β Fetch Templates
- β Analyze Template Structure (π₯ Smart Feature)
- β One-time Configuration
π¦ Installation
npm install bhoriwal-sdkβοΈ Configuration (Recommended)
Configure once and use everywhere:
import Bhoriwal from "bhoriwal-sdk";
Bhoriwal.config({
token: process.env.WA_ACCESS_TOKEN,
phoneId: process.env.WA_PHONE_NUMBER_ID,
wabaId: process.env.WA_BUSINESS_ACCOUNT_ID
});π Environment Variables
WA_PHONE_NUMBER_ID=xxxxxxxxxxxx
WA_ACCESS_TOKEN=EAAGxxxxxxxxxxxxxxxx
WA_BUSINESS_ACCOUNT_ID=xxxxxxxxxxxx㪠Send Text Message
await Bhoriwal.sendText({
to: "919999999999",
message: "Hello from Bhoriwal π"
});π Works only within 24-hour customer window.
πΌοΈ Send Media Message
await Bhoriwal.sendMedia({
to: "919999999999",
type: "image", // image | video | document | audio
link: "https://example.com/image.jpg",
caption: "Check this out π"
});π§Ύ Send Template Message
await Bhoriwal.sendTemplate({
to: "919999999999",
name: "order_update",
components: [
{
type: "body",
parameters: [
{ type: "text", text: "John" },
{ type: "text", text: "ORD123" }
]
}
]
});π Templates must be approved in Meta.
π Fetch & Analyze Templates (π₯ Powerful Feature)
1οΈβ£ Get All Templates
const templates = await Bhoriwal.getTemplates();2οΈβ£ Find Template
const template = templates.find(t => t.name === "order_update");3οΈβ£ Analyze Template Structure
const info = Bhoriwal.analyzeTemplate(template);
console.log(info);β Example Output
{
name: "order_update",
bodyParams: [
{ index: 1, type: "text" },
{ index: 2, type: "text" }
],
header: {
type: "image"
},
buttons: [
{ buttonIndex: 0, type: "dynamic_url" }
]
}π‘ What This Means
- Body requires 2 text parameters
- Header requires an image
- Button needs dynamic value
π No more guessing template structure π―
π Send Button Message (Interactive)
await Bhoriwal.sendMessageFlow({
to: "919999999999",
message: "Hello π Please choose an option:",
buttons: [
{ id: "order", title: "Order" },
{ id: "contact", title: "Contact" },
{ id: "other", title: "Other" }
]
});π Button Rules
- Maximum 3 buttons
- Title max 20 characters
- ID max 256 characters
π Send WhatsApp Flow
await Bhoriwal.sendFlow({
to: "919999999999",
flowId: "123456",
flowToken: "abc123",
flowData: {
name: "John"
}
});π€ Bulk Messaging
await Bhoriwal.bulkSend(
[
{ to: "919111111111", message: "Hello 1" },
{ to: "919222222222", message: "Hello 2" }
],
Bhoriwal.sendText
);βοΈ Check Phone Number
await Bhoriwal.checkPhoneNumber({
to: "919999999999"
});π Uses safe verification method (no official API available).
ποΈ Mark Message as Read
await Bhoriwal.markAsRead({
messageId: "wamid.HBg..."
});π« Block / Unblock User
Block
await Bhoriwal.blockUser({
to: "919999999999"
});Unblock
await Bhoriwal.unblockUser({
to: "919999999999"
});β οΈ Important Notes
- Template messages are required outside the 24-hour window
- Some features (Flows, Blocking) require Meta approval
- Phone check is a workaround, not official API
π§ Best Practices
- Use templates for notifications
- Analyze templates before sending
- Cache templates for performance
- Validate inputs before sending
- Use bulk messaging carefully (rate limits)
π License
MIT
β€οΈ Support
If you like this project, consider starring β and sharing it.
