octinix / pingzr-whatsapp
A Laravel package for sending WhatsApp messages via Pingzr API
dev-master
2025-05-18 13:51 UTC
Requires
- php: ^7.4|^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|^10.0
This package is auto-updated.
Last update: 2025-05-19 08:55:34 UTC
README
A Laravel package for sending WhatsApp messages via the Pingzr API.
Installation
You can install the package via composer:
composer require octinix/pingzr-whatsapp
Configuration
Publish the configuration file:
php artisan vendor:publish --provider="Octinix\PingzrWhatsapp\PingzrWhatsappServiceProvider" --tag="config"
Add your Pingzr WhatsApp API token to your .env
file:
PINGZR_WHATSAPP_TOKEN=your-api-token
Usage
Sending a Text Message
use Octinix\PingzrWhatsapp\Facades\PingzrWhatsapp; // Send a simple text message try { $response = PingzrWhatsapp::sendText('18876656789', 'Hello, this is a test message!'); // Success response: ['success' => true, 'message' => 'Message sent successfully!'] } catch (\Octinix\PingzrWhatsapp\Exceptions\PingzrException $e) { // Handle exception echo $e->getMessage(); }
Sending an Image
try { $response = PingzrWhatsapp::sendImage( '18876656789', 'https://example.com/image.jpg', 'Check out this image!' ); } catch (\Octinix\PingzrWhatsapp\Exceptions\PingzrException $e) { echo $e->getMessage(); }
Sending an Audio Message
try { $response = PingzrWhatsapp::sendAudio( '18876656789', 'https://example.com/audio.mp3' ); } catch (\Octinix\PingzrWhatsapp\Exceptions\PingzrException $e) { echo $e->getMessage(); }
Sending a Document
try { $response = PingzrWhatsapp::sendDocument( '18876656789', 'https://example.com/document.pdf', 'Important document' ); } catch (\Octinix\PingzrWhatsapp\Exceptions\PingzrException $e) { echo $e->getMessage(); }
Sending a Video
try { $response = PingzrWhatsapp::sendVideo( '18876656789', 'https://example.com/video.mp4', 'Check out this video!' ); } catch (\Octinix\PingzrWhatsapp\Exceptions\PingzrException $e) { echo $e->getMessage(); }
Sending an Interactive List
try { $sections = [ [ 'title' => 'Section 1', 'rows' => [ [ 'id' => 'option1', 'title' => 'Option 1', 'description' => 'Description for option 1' ], [ 'id' => 'option2', 'title' => 'Option 2', 'description' => 'Description for option 2' ] ] ], [ 'title' => 'Section 2', 'rows' => [ [ 'id' => 'option3', 'title' => 'Option 3', 'description' => 'Description for option 3' ] ] ] ]; $response = PingzrWhatsapp::sendList( '18876656789', 'List Header', 'Please select an option', 'Footer text', 'View Options', $sections ); } catch (\Octinix\PingzrWhatsapp\Exceptions\PingzrException $e) { echo $e->getMessage(); }
Sending Reply Buttons
try { $buttons = [ [ 'id' => 'btn1', 'title' => 'Yes' ], [ 'id' => 'btn2', 'title' => 'No' ] ]; $response = PingzrWhatsapp::sendButtons( '18876656789', 'Do you want to proceed?', $buttons ); } catch (\Octinix\PingzrWhatsapp\Exceptions\PingzrException $e) { echo $e->getMessage(); }
Sending a Custom Message
try { $customPayload = [ 'to' => '18876656789', 'type' => 'text', 'text' => [ 'preview_url' => true, 'body' => 'Check out this link: https://example.com' ] ]; $response = PingzrWhatsapp::sendCustom($customPayload); } catch (\Octinix\PingzrWhatsapp\Exceptions\PingzrException $e) { echo $e->getMessage(); }
Error Handling
The package throws exceptions when errors occur:
PingzrException
: Base exception classInvalidMessageTypeException
: Thrown when an invalid message type is providedApiException
: Thrown when the API returns an error