PHP code example of haimanresources / laravel-whatsapp
1. Go to this page and download the library: Download haimanresources/laravel-whatsapp 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/ */
haimanresources / laravel-whatsapp example snippets
use HRC\WhatsApp\Facades\WhatsApp;
WhatsApp::sendText('+234 801 234 5678', 'Your order has shipped.');
use HRC\WhatsApp\Events\MessageReceived;
class ReplyToCustomer
{
public function handle(MessageReceived $event): void
{
$event->message->text; // 'Where is my order?'
$event->conversation->wa_id; // '2348012345678'
$event->conversation->owner; // your model, if attached
}
}
use HRC\WhatsApp\Broadcaster;
$broadcast = app(Broadcaster::class)->create(
name: 'September promo',
recipients: ['2348011111111', '2348022222222'],
bodyText: 'Our new prices are live.', // reaches contacts inside the window
template: 'promo_september', // reaches everyone else
);
app(Broadcaster::class)->dispatch($broadcast);
use HRC\WhatsApp\Models\Conversation;
Conversation::with('messages')->latest('last_message_at')->paginate(30);
Conversation::sole()->messages()->inbound()->get();