PHP code example of zarulizham / laravel-openwa

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

    

zarulizham / laravel-openwa example snippets


use ZarulIzham\OpenWa\Facades\OpenWa;

// List all sessions
$sessions = OpenWa::getSessions();

// Get the id of the most recently connected session with status "ready"
$sessionId = OpenWa::getLatestReadySessionId();

// Send a text message (auto-resolves the latest ready session if omitted)
OpenWa::sendText('[email protected]', 'Hello from OpenWA!');

// Send an image
OpenWa::sendImage('[email protected]', [
    'url' => 'https://example.com/image.jpg',
    'caption' => 'Check this out!',
]);

// Send a document
OpenWa::sendDocument('[email protected]', [
    'url' => 'https://example.com/invoice.pdf',
    'filename' => 'invoice.pdf',
]);

public function routeNotificationForWhatsapp(): string
{
    return $this->phone.'@c.us';
}

use Illuminate\Notifications\Notification;
use ZarulIzham\OpenWa\Notifications\OpenWaMessage;
use ZarulIzham\OpenWa\Notifications\WhatsAppNotification;

class OrderShipped extends Notification implements WhatsAppNotification
{
    public function via($notifiable): array
    {
        return ['openwa'];
    }

    public function toWhatsApp($notifiable): OpenWaMessage
    {
        return OpenWaMessage::text("Your order #{$this->order->id} has shipped!");
    }
}
bash
php artisan vendor:publish --tag="openwa-config"