PHP code example of elbrahms / wa-gateway

1. Go to this page and download the library: Download elbrahms/wa-gateway 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/ */

    

elbrahms / wa-gateway example snippets


use Elbrahms\WaGateway\Facades\WaGateway;

// Send a text message
WaGateway::sendMessage('22799123456', 'Hello from Laravel!');

// Send an image
WaGateway::sendMedia('22799123456', 'image', 'https://example.com/photo.jpg', 'Check this out!');

// Send a document
WaGateway::sendMedia('22799123456', 'document', 'https://example.com/report.pdf');

// Send a poll
WaGateway::sendPoll('22799123456', 'Favourite color?', ['Red', 'Blue', 'Green']);

// Send a sticker
WaGateway::sendSticker('22799123456', 'https://example.com/sticker.webp');

// Send a location
WaGateway::sendLocation('22799123456', '13.5137', '2.1098');

// Send a vCard
WaGateway::sendVcard('22799123456', 'Ibrahim Sidi', '22799000000');

// Check if a number is on WhatsApp
$result = WaGateway::checkNumber('22799123456');
// $result['msg']['exists'] === true

WaGateway::sendButton(
    number: '22799123456',
    message: 'How can we help?',
    buttons: [
        ['type' => 'reply',  'displayText' => 'Support'],
        ['type' => 'url',    'displayText' => 'Website', 'url' => 'https://fite-ne.com'],
        ['type' => 'call',   'displayText' => 'Call us', 'phoneNumber' => '22799749554'],
        ['type' => 'copy',   'displayText' => 'Copy code', 'copyCode' => 'PROMO2025'],
    ],
    footer: 'Powered by WaGateway'
);

WaGateway::sendList(
    number: '22799123456',
    message: 'Choose a department',
    title: 'Our Departments',
    buttonText: 'View list',
    list: ['Sales', 'Support', 'Billing', 'Technical'],
    footer: 'We reply within 24 h'
);

// Generate QR code to connect a device
$qr = WaGateway::generateQr('22799749554');
// $qr['qrcode'] is a base64-encoded PNG — display or save it

// Create a new device
WaGateway::createDevice('22799000001', 'https://yourapp.com/webhook');

// Get device information
$info = WaGateway::deviceInfo('22799749554');

// Disconnect a device
WaGateway::disconnectDevice('22799749554');

// Create a user
WaGateway::createUser(
    username: 'newuser',
    password: 'secret123',
    email: '[email protected]',
    expire: 30,
    limitDevice: 5
);

// Get user info
$user = WaGateway::userInfo('newuser');

use Elbrahms\WaGateway\WaGateway;

class NotificationService
{
    public function __construct(protected WaGateway $wa) {}

    public function notify(string $phone, string $text): void
    {
        $this->wa->sendMessage($phone, $text);
    }
}

WaGateway::sendMessage('22799123456', 'Hello!', sender: '22788868500');

use Elbrahms\WaGateway\Exceptions\WaGatewayException;

try {
    WaGateway::sendMessage('22799123456', 'Hello!');
} catch (WaGatewayException $e) {
    logger()->error('WaGateway error: ' . $e->getMessage(), $e->getErrors());
}
bash
php artisan vendor:publish --tag=wa-gateway-config