wapilot / sdk
Official PHP/Laravel SDK for WAPILOT.io - WhatsApp Business API Integration
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^6.0|^7.0|^8.0
- phpunit/phpunit: ^9.0
This package is not auto-updated.
Last update: 2025-09-07 19:19:11 UTC
README
Official PHP/Laravel 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 PHP/Laravel 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 PHP 8.0+
- 🔒 Secure - Built-in token-based authentication and HTTPS
- 🚀 Laravel Integration - Seamless Laravel integration with Facade support
Installation
You can install the package via composer:
composer require wapilot/sdk
Laravel Setup
-
The package will automatically register its service provider and facade.
-
Publish the configuration file:
php artisan vendor:publish --provider="Wapilot\SDK\WapilotServiceProvider"
- Add your WAPILOT credentials to your
.env
file:
WAPILOT_API_TOKEN=your-api-token WAPILOT_API_URL=https://app.wapilot.io # Optional
Usage
Laravel Usage (Recommended)
Using the Facade:
use Wapilot\SDK\Facades\Wapilot; // Send a message $result = Wapilot::sendMessage([ 'phone' => '+1234567890', 'message' => 'Hello from Laravel!' ]);
Standalone PHP Usage
use Wapilot\SDK\WapilotSDK; $wapilot = new WapilotSDK('your-api-token'); // Send a message try { $result = $wapilot->sendMessage([ 'phone' => '+1234567890', 'message' => 'Hello from PHP!' ]); print_r($result); } catch (\Exception $e) { echo 'Error: ' . $e->getMessage(); }
API Reference
Contact Management
Get All Contacts
$contacts = Wapilot::getContacts();
Create Contact
$newContact = Wapilot::createContact([ 'name' => 'John Doe', 'phone' => '+1234567890', // International format with country code 'email' => 'john@example.com', // Optional 'notes' => 'VIP Customer' // Optional ]);
Update Contact
$updatedContact = Wapilot::updateContact('contact-uuid', [ 'name' => 'John Smith' ]);
Delete Contact
Wapilot::deleteContact('contact-uuid');
Message Sending
Send Text Message with Interactive Buttons
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
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
Wapilot::sendTemplateMessage([ 'phone' => '+1234567890', 'template' => [ 'name' => 'appointment_reminder', 'language' => [ 'code' => 'en' ], 'components' => [ [ 'type' => 'header', 'parameters' => [ [ 'type' => 'image', 'image' => [ 'link' => 'https://example.com/appointment.jpg' ] ] ] ], [ 'type' => 'body', 'parameters' => [ [ 'type' => 'text', 'text' => 'John Doe' ], [ 'type' => 'text', 'text' => '3:00 PM' ] ] ] ] ] ]);
Contact Groups
Get All Groups
$groups = Wapilot::getContactGroups();
Create Group
$newGroup = Wapilot::createContactGroup([ 'name' => 'VIP Customers', 'description' => 'Our premium customers' // Optional ]);
Update Group
$updatedGroup = Wapilot::updateContactGroup('group-uuid', [ 'name' => 'Premium Customers' ]);
Delete Group
Wapilot::deleteContactGroup('group-uuid');
Automated Replies
Get All Automated Replies
$replies = Wapilot::getCannedReplies();
Create Automated Reply
$newReply = 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
$updatedReply = Wapilot::updateCannedReply('reply-uuid', [ 'message' => 'Thank you for reaching out! We will get back to you soon.' ]);
Delete Automated Reply
Wapilot::deleteCannedReply('reply-uuid');
Templates
Get All Templates
$templates = Wapilot::getTemplates();
Error Handling
The SDK uses PHP exceptions for error handling:
try { $contacts = Wapilot::getContacts(); } catch (\GuzzleHttp\Exception\ClientException $e) { // API Error (4xx response) echo 'API Error: ' . $e->getResponse()->getBody()->getContents(); echo 'Status Code: ' . $e->getResponse()->getStatusCode(); } catch (\Exception $e) { // Other errors echo 'Error: ' . $e->getMessage(); }
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.