PHP code example of rezadaulay / filament-whatsapp-notification

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

    

rezadaulay / filament-whatsapp-notification example snippets


use Rezadaulay\FilamentWhatsappNotification\FilamentWhatsappNotificationPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            FilamentWhatsappNotificationPlugin::make(),
        ]);
}

FilamentWhatsappNotificationPlugin::make()
    ->resource()
    ->statsWidget()
    ->connectionPage();

FilamentWhatsappNotificationPlugin::make()
    ->resource(false)
    ->statsWidget(false)
    ->connectionPage(true);

return [
    'enabled' => env('WHATSAPP_NOTIFICATION_ENABLED', true),
    'gateway' => [
        'base_url' => env('WHATSAPP_NOTIFICATION_GATEWAY_URL', 'http://127.0.0.1:5000'),
        'timeout' => (int) env('WHATSAPP_NOTIFICATION_TIMEOUT', 30),
        'country_code' => env('WHATSAPP_NOTIFICATION_COUNTRY_CODE', '62'),
        'check_status_before_send' => env('WHATSAPP_NOTIFICATION_CHECK_STATUS', false),
    ],
    'queue' => [
        'connection' => env('WHATSAPP_NOTIFICATION_QUEUE_CONNECTION', env('QUEUE_CONNECTION', 'database')),
        'queue' => env('WHATSAPP_NOTIFICATION_QUEUE', 'whatsapp-notifications'),
    ],
    'sending' => [
        'delay_min_seconds' => (int) env('WHATSAPP_NOTIFICATION_DELAY_MIN', 30),
        'delay_max_seconds' => (int) env('WHATSAPP_NOTIFICATION_DELAY_MAX', 60),
        'max_attempts' => (int) env('WHATSAPP_NOTIFICATION_MAX_ATTEMPTS', 2),
        'lock_ttl_seconds' => (int) env('WHATSAPP_NOTIFICATION_LOCK_TTL', 180),
        'stale_processing_minutes' => (int) env('WHATSAPP_NOTIFICATION_STALE_PROCESSING_MINUTES', 10),
    ],
    'table_name' => env('WHATSAPP_NOTIFICATION_TABLE', 'whatsapp_notification_logs'),
];

use Illuminate\Notifications\Notifiable;

class User
{
    use Notifiable;

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

use Illuminate\Notifications\Notification;
use Rezadaulay\FilamentWhatsappNotification\Messages\WhatsappMessage;

class OrderPaidWhatsappNotification extends Notification
{
    public function via(object $notifiable): array
    {
        return ['whatsapp'];
    }

    public function toWhatsapp(object $notifiable): WhatsappMessage
    {
        return WhatsappMessage::make()
            ->content("Your order #{$this->order->number} has been paid.")
            ->payload([
                'order_id' => $this->order->id,
                'type' => 'order-paid',
            ]);
    }
}

$user->notify(new OrderPaidWhatsappNotification($order));

public function toWhatsapp(object $notifiable): WhatsappMessage
{
    return WhatsappMessage::make()
        ->to('081234567890')
        ->countryCode('62')
        ->content('Hello from WhatsApp')
        ->deduplicationKey('order-123-paid');
}
bash
php artisan vendor:publish --tag="filament-whatsapp-notification-config"
php artisan vendor:publish --tag="filament-whatsapp-notification-migrations"
php artisan migrate
css
@source '../../../../vendor/rezadaulay/filament-whatsapp-notification/resources/**/*.blade.php';
bash
php artisan filament:assets
php artisan optimize:clear
bash
php artisan queue:work
bash
php artisan queue:work --queue=whatsapp-notifications