PHP code example of vibrantcoder / whatsapp-notifier

1. Go to this page and download the library: Download vibrantcoder/whatsapp-notifier library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vibrantcoder / whatsapp-notifier example snippets


use VibrantCoders\WhatsAppNotifier\Facades\WhatsApp;

WhatsApp::message('Hello {{name}}, this is a test.')
    ->with(['name' => 'Ali'])
    ->send('919727927400');

'meta_templates' => [
    'order_confirmed' => [
        'name'     => 'jaspers_market_order_confirmation_v1',
        'language' => 'en_US',
        'body'     => ['customer_name', 'order_id', 'expected_delivery'],
    ],
],

WhatsApp::metaTemplate('order_confirmed', [
    'customer_name'     => $order->customer_name,
    'order_id'          => (string) $order->id,
    'expected_delivery' => $order->expectedDeliveryFormatted(),
])->send($order->customer_phone);

WhatsApp::metaTemplate('jaspers_market_order_confirmation_v1', 'en_US')
    ->body('Ali', '1042', '4 May 2026')
    ->send('919727927400');

// Image header + URL button
WhatsApp::metaTemplate('order_shipped_v2')
    ->headerImage('https://cdn.example.com/box.jpg')
    ->body('Ali', '1042')
    ->urlButton(0, '1042')
    ->send($phone);

// PDF document header
WhatsApp::metaTemplate('invoice_ready')
    ->headerDocument('https://cdn.example.com/inv-1042.pdf', 'invoice-1042.pdf')
    ->body('Ali', '1042', 'INR 1,499.00')
    ->send($phone);

// Quick-reply buttons
WhatsApp::metaTemplate('feedback_request')
    ->body('Ali')
    ->quickReplyPayload(0, 'YES')
    ->quickReplyPayload(1, 'NO')
    ->send($phone);

// Named placeholders ({{customer_name}} style)
WhatsApp::metaTemplate('order_confirmed_named')
    ->bodyNamed(['customer_name' => 'Ali', 'order_id' => '1042'])
    ->send($phone);

// Escape hatch — supply the full components array
WhatsApp::metaTemplate('any_template')->withRawComponents([...])->send($phone);

WhatsApp::via('twilio')->message('Hi!')->send('+923001234567');
WhatsApp::via('meta')->metaTemplate('order_confirmed', [...])->send($phone);

WhatsApp::message('OTP: 123456')->queue(false)->send($phone);  // sync
WhatsApp::message('Receipt')->queue(true)->send($phone);        // async

// app/Events/OrderPlaced.php
class OrderPlaced
{
    use Dispatchable, SerializesModels;
    public function __construct(public Order $order) {}
}

// app/Listeners/SendOrderConfirmationWhatsApp.php
class SendOrderConfirmationWhatsApp
{
    public function handle(OrderPlaced $event): void
    {
        WhatsApp::metaTemplate('order_confirmed', [
            'customer_name'     => $event->order->customer_name,
            'order_id'          => (string) $event->order->id,
            'expected_delivery' => $event->order->expectedDeliveryFormatted(),
        ])->send($event->order->customer_phone);
    }
}

// Anywhere in your code:
event(new OrderPlaced($order));

use VibrantCoders\WhatsAppNotifier\Contracts\WhatsAppDriver;
use VibrantCoders\WhatsAppNotifier\Services\WhatsAppManager;

app(WhatsAppManager::class)->extend('myprovider', function ($app, $config) {
    return new class implements WhatsAppDriver {
        public function name(): string { return 'myprovider'; }
        public function send(string $to, string $message, array $options = []): array
        {
            // your provider call here...
            return ['success' => true, 'id' => '...', 'response' => [...], 'error' => null];
        }
    };
});

use VibrantCoders\WhatsAppNotifier\Models\WhatsAppMessage;

WhatsAppMessage::orderByDesc('id')->limit(50)->get();
bash
php artisan whatsapp:install
bash
# 1. Install + setup
composer update vibrantcoder/whatsapp-notifier
php artisan vendor:publish --tag=whatsapp-config
php artisan vendor:publish --tag=whatsapp-migrations
php artisan migrate

# 2. Add a tinker test
php artisan tinker
>>> use VibrantCoders\WhatsAppNotifier\Facades\WhatsApp;
>>> WhatsApp::metaTemplate('order_confirmed', [
...     'customer_name' => 'Ali',
...     'order_id' => '999',
...     'expected_delivery' => '4 May 2026',
... ])->send('919727927400');