PHP code example of nml / whatsapp-notifier

1. Go to this page and download the library: Download nml/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/ */

    

nml / whatsapp-notifier example snippets


use Nml\WhatsApp\WhatsAppClient;

$wa = app(WhatsAppClient::class);

$response = $wa->sendText(
    to: '94771234567',
    text: 'Hello! Your order has been placed successfully.',
    previewUrl: true
);

use Nml\WhatsApp\WhatsAppClient;

$wa = app(WhatsAppClient::class);

$response = $wa->sendTemplate(
    to: '94771234567',
    templateName: 'jaspers_market_order_confirmation_v1',
    languageCode: 'en_US',
    components: [
        [
            'type' => 'body',
            'parameters' => [
                ['type' => 'text', 'text' => 'John Doe'],
                ['type' => 'text', 'text' => '123456'],
                ['type' => 'text', 'text' => 'Sep 2, 2026'],
            ]
        ]
    ]
);

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Nml\WhatsApp\Channels\WhatsAppChannel;
use Nml\WhatsApp\Messages\WhatsAppTemplateMessage;

class OrderShippedNotification extends Notification
{
    public function via($notifiable): array
    {
        return [WhatsAppChannel::class];
    }

    public function toWhatsApp($notifiable)
    {
        return WhatsAppTemplateMessage::create('jaspers_market_order_confirmation_v1')
            ->language('en_US')
            ->bodyParameters([
                $notifiable->name,
                $notifiable->order_id,
                now()->format('M j, Y'),
            ]);
    }
}

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

    public function routeNotificationForWhatsApp($notification): string
    {
        return $this->phone_number;
    }
}

$user->notify(new OrderShippedNotification());
text
nml-whatsapp-notifier/
├── config/
│   └── whatsapp.php
├── src/
│   ├── WhatsAppServiceProvider.php
│   ├── WhatsAppClient.php
│   ├── Channels/
│   │   └── WhatsAppChannel.php
│   ├── Messages/
│   │   ├── WhatsAppTextMessage.php
│   │   └── WhatsAppTemplateMessage.php
│   └── Exceptions/
│       └── WhatsAppApiException.php
├── tests/
│   ├── TestCase.php
│   └── Unit/
│       └── WhatsAppPackageTest.php
├── composer.json
├── phpunit.xml
├── README.md
└── DOCUMENTATION.md
bash
php artisan vendor:publish --tag=whatsapp-config
bash
php artisan make:notification OrderShippedNotification