WAPILOT Flutter/Dart SDK
Official Flutter/Dart 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 Flutter/Dart 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 Dart, supports null safety
- π Secure - Built-in token-based authentication and HTTPS
- π Future-based - All operations return Futures for easy async/await usage
Installation
Add this to your package's pubspec.yaml
file:
dependencies:
wapilot_sdk: ^1.0.0
Quick Start
import 'package:wapilot_sdk/wapilot_sdk.dart';
void main() async {
final wapilot = WapilotSDK(
token: 'your-api-token' // Get this from your WAPILOT dashboard
);
try {
final result = await wapilot.sendMessage({
'phone': '+1234567890',
'message': 'Hello from Flutter!'
});
print(result);
} catch (e) {
print('Error: $e');
}
}
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
final contacts = await wapilot.getContacts();
Create Contact
final newContact = await wapilot.createContact({
'name': 'John Doe',
'phone': '+1234567890', // International format with country code
// Optional fields
'email': 'john@example.com',
'notes': 'VIP Customer'
});
Update Contact
final 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
final groups = await wapilot.getContactGroups();
Create Group
final newGroup = await wapilot.createContactGroup({
'name': 'VIP Customers',
'description': 'Our premium customers' // Optional
});
Update Group
final updatedGroup = await wapilot.updateContactGroup('group-uuid', {
'name': 'Premium Customers'
});
Delete Group
await wapilot.deleteContactGroup('group-uuid');
Automated Replies
Get All Automated Replies
final replies = await wapilot.getCannedReplies();
Create Automated Reply
final 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
final 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
final templates = await wapilot.getTemplates();
Error Handling
The SDK uses Dart's built-in error handling with DioException for API errors:
try {
final contacts = await wapilot.getContacts();
} catch (e) {
if (e is DioException) {
// API Error (4xx or 5xx response)
print('API Error: ${e.response?.data}');
print('Status Code: ${e.response?.statusCode}');
} else {
// Other errors (network, etc.)
print('Error: $e');
}
}
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: support@wapilot.io
License
MIT License - feel free to use this SDK in your projects.