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
);
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;
}
}