zarulizham/laravel-openwa

Laravel wrapper for the OpenWA WhatsApp gateway API

Maintainers

Package info

github.com/zarulizham/laravel-openwa

pkg:composer/zarulizham/laravel-openwa

Transparency log

Fund package maintenance!

:vendor_name

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.2 2026-07-31 08:49 UTC

This package is auto-updated.

Last update: 2026-07-31 08:49:18 UTC


README

Latest Version on Packagist Total Downloads

A Laravel wrapper for the OpenWA WhatsApp gateway API — list sessions, send text/image/document messages, and a whatsapp Notification channel.

Installation

You can install the package via composer:

composer require zarulizham/laravel-openwa

Publish the config file:

php artisan vendor:publish --tag="openwa-config"

Set your OpenWA server details in .env:

OPENWA_BASE_URL=https://openwa.prooffice.com.my/api
OPENWA_API_KEY=your-api-key
OPENWA_TIMEOUT=30
OPENWA_SESSION_NAME=my-bot

OPENWA_SESSION_NAME is optional. When set, getLatestReadySessionId() (and any send call that omits an explicit session id) only considers the session with that name — instead of the most recently connected ready session across all of them. The resolved session id is cached for 3 hours.

Usage

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('628123456789@c.us', 'Hello from OpenWA!');

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

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

Notifications

Add a routeNotificationForWhatsapp() method to your notifiable model:

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

Implement ZarulIzham\OpenWa\Notifications\WhatsAppNotification on your notification and return an OpenWaMessage from toWhatsApp():

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

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.