PHP code example of mohdradzee / laravel-wati-notification

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

    

mohdradzee / laravel-wati-notification example snippets


// config/app.php

'providers' => [
    mohdradzee\WatiNotification\WatiNotificationServiceProvider::class,
],

return [
    'token' => env('WATI_TOKEN'),
    'base_url' => env('WATI_BASE_URL', 'https://live-server.wati.io/441627/api/v1'),
];

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use mohdradzee\WatiNotification\WatiMessage;

class ConfirmWhatsappNumber extends Notification
{
    use Queueable;

    public function via($notifiable)
    {
        return ['wati'];
    }

    public function toWati($notifiable)
    {
        return WatiMessage::create()
            ->to($notifiable->phone)
            ->withAction('add_contact')
            ->withMeta([
                'fullName' => $notifiable->name,
                'customParams' => [
                    'source' => 'signup_page',
                ],
            ]);
    }
}

use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

    // Ensure `phone` attribute exists
}

$user = App\Models\User::first();
$user->notify(new App\Notifications\ConfirmWhatsappNumber());

WatiMessage::create()
    ->to('601122334455')
    ->withAction('send_template')
    ->withTemplate('template_name')
    ->withBroadcastName('broadcast1')
    ->withParameters([
        ['name' => 'name', 'value' => 'alibaba']
    ]);

use mohdradzee\WatiNotification\Contracts\WatiApiStrategy;

class MyCustomStrategy implements WatiApiStrategy
{
    public function execute(array $data): array
    {
        // call your custom WATI endpoint...
    }
}

WatiApiExecutor::register('my_action', MyCustomStrategy::class);

$user = App\Models\User::first();
$user->notify(new App\Notifications\ConfirmWhatsappNumber());
bash
php artisan vendor:publish --tag=wati-config
bash
php artisan make:notification ConfirmWhatsappNumber
bash
php artisan tinker