wapilot-sdk
v1.0.1
Published
Official Node.js SDK for WAPILOT.io - WhatsApp Business API Integration
Downloads
12
Maintainers
Readme
WAPILOT Node.js SDK
Official Node.js SDK for WAPILOT.io - WhatsApp Business API Integration Platform
Overview
WAPILOT SDK provides a simple and intuitive way to integrate WhatsApp Business API functionality into your Node.js applications. This SDK handles all the complexity of API communication, authentication, and data formatting, allowing you to focus on building your application logic.
Features
- 📱 Contact Management - Create, update, and manage WhatsApp contacts
- 👥 Contact Groups - Organize contacts into groups for better management
- 💬 Message Sending - Send text, media, and interactive messages
- 📝 Templates - Manage and send template messages
- 🤖 Automated Replies - Set up and manage automated responses
- ✨ Modern Architecture - Built with modern JavaScript, supports both ES Modules and CommonJS
- 🔒 Secure - Built-in token-based authentication and HTTPS
- 🚀 Promise-based - All operations return promises for easy async/await usage
Installation
npm install wapilot-sdkQuick Start
The SDK supports both modern ES Modules and traditional CommonJS imports:
ES Modules (Recommended)
import WapilotSDK from 'wapilot-sdk';
const wapilot = new WapilotSDK({
token: 'your-api-token' // Get this from your WAPILOT dashboard
});CommonJS
const WapilotSDK = require('wapilot-sdk');
const wapilot = new WapilotSDK({
token: 'your-api-token'
});Configuration Options
| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | token | string | Yes | - | Your WAPILOT API token | | baseURL | string | No | https://app.wapilot.io | API base URL |
API Reference
Contact Management
Get All Contacts
const contacts = await wapilot.getContacts();Create Contact
const newContact = await wapilot.createContact({
name: 'John Doe',
phone: '+1234567890', // International format with country code
// Optional fields
email: '[email protected]',
notes: 'VIP Customer'
});Update Contact
const updatedContact = await wapilot.updateContact('contact-uuid', {
name: 'John Smith',
// Include only fields you want to update
});Delete Contact
await wapilot.deleteContact('contact-uuid');Message Sending
Send Text Message with Interactive Buttons
await wapilot.sendMessage({
phone: '+1234567890',
message: 'Hello! How can we help you today?',
header: 'Welcome Message', // Optional
footer: 'Reply with a button', // Optional
buttons: [
{
id: 'support',
title: 'Get Support'
},
{
id: 'sales',
title: 'Sales Inquiry'
}
]
});Send Media Message
await wapilot.sendMediaMessage({
phone: '+1234567890',
media_type: 'image', // 'image', 'video', 'document', 'audio'
media_url: 'https://example.com/image.jpg',
caption: 'Check out our new product!', // Optional
file_name: 'product.jpg' // Required for documents
});Send Template Message
await wapilot.sendTemplateMessage({
phone: '+1234567890',
template: {
name: 'appointment_reminder',
language: {
code: 'en' // Language code
},
components: [
{
type: 'header',
parameters: [
{
type: 'image',
image: {
link: 'https://example.com/appointment.jpg'
}
}
]
},
{
type: 'body',
parameters: [
{
type: 'text',
text: 'John Doe' // Dynamic parameter
},
{
type: 'text',
text: '3:00 PM' // Dynamic parameter
}
]
}
]
}
});Contact Groups
Get All Groups
const groups = await wapilot.getContactGroups();Create Group
const newGroup = await wapilot.createContactGroup({
name: 'VIP Customers',
description: 'Our premium customers' // Optional
});Update Group
const updatedGroup = await wapilot.updateContactGroup('group-uuid', {
name: 'Premium Customers'
});Delete Group
await wapilot.deleteContactGroup('group-uuid');Automated Replies
Get All Automated Replies
const replies = await wapilot.getCannedReplies();Create Automated Reply
const newReply = await wapilot.createCannedReply({
name: 'Welcome Message',
message: 'Thank you for contacting us! Our team will respond shortly.',
keywords: ['hi', 'hello', 'hey'] // Optional trigger keywords
});Update Automated Reply
const updatedReply = await wapilot.updateCannedReply('reply-uuid', {
message: 'Thank you for reaching out! We will get back to you soon.'
});Delete Automated Reply
await wapilot.deleteCannedReply('reply-uuid');Templates
Get All Templates
const templates = await wapilot.getTemplates();Error Handling
The SDK uses Promise-based error handling. All errors include detailed information about what went wrong:
try {
const contacts = await wapilot.getContacts();
} catch (error) {
if (error.response) {
// API Error (4xx or 5xx response)
console.error('API Error:', error.response.data);
console.error('Status Code:', error.response.status);
} else if (error.request) {
// Network Error (no response received)
console.error('Network Error:', error.request);
} else {
// SDK Error (error in request setup)
console.error('Error:', error.message);
}
}Common Error Codes:
- 401: Invalid or expired API token
- 400: Invalid request parameters
- 404: Resource not found
- 429: Rate limit exceeded
- 500: Server error
Best Practices
- Error Handling: Always implement proper error handling using try/catch blocks
- Token Security: Never expose your API token in client-side code
- Rate Limiting: Implement proper rate limiting in your application
- Message Templates: Use templates for recurring messages
- Contact Management: Keep contact information up to date
- Testing: Test your integration thoroughly in a development environment
Support
For support or inquiries, please contact:
- Email: [email protected]
License
MIT License - feel free to use this SDK in your projects.
