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');
// 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();