DEV Community

Moataz khaled
Moataz khaled

Posted on

Send WhatsApp Messages from Laravel in 3 Lines of Code

If you've ever needed to send WhatsApp messages from a Laravel app — order confirmations, OTP codes, shipping updates — you know how painful it can be to set up.

I built wasaas-php, an open-source Laravel SDK that makes it dead simple.

Install

composer require wasaas/wasaas-php
Enter fullscreen mode Exit fullscreen mode

Add your API key to .env:

WASAAS_API_KEY=wsa_your_key_here
Enter fullscreen mode Exit fullscreen mode

Get a free API key at wasaas.org — 7-day trial, no credit card required.

Send a Message in 3 Lines

use Wasaas\Laravel\Facades\Wasaas;

Wasaas::messages()->sendText(
    sessionId: 'my-session',
    to: '966501234567',
    message: 'Your order #1234 has shipped! 🚚',
);
Enter fullscreen mode Exit fullscreen mode

That's it. Connect your WhatsApp number in the dashboard, grab a session ID, and you're sending messages.

What Else Can It Do?

Send an image:

Wasaas::messages()->sendImage(
    sessionId: 'my-session',
    to: '966501234567',
    imageUrl: 'https://example.com/invoice.png',
    caption: 'Invoice #1234',
);
Enter fullscreen mode Exit fullscreen mode

Send a PDF or document:

$base64 = base64_encode(file_get_contents('/path/to/invoice.pdf'));

Wasaas::messages()->sendDocument(
    sessionId: 'my-session',
    to: '966501234567',
    base64: $base64,
    filename: 'invoice-1234.pdf',
    mime: 'application/pdf',
    caption: 'Your invoice is attached',
);
Enter fullscreen mode Exit fullscreen mode

Check if a number has WhatsApp:

$result = Wasaas::numbers()->validate('my-session', '966501234567');
// ['exists' => true, 'phone' => '966501234567']
Enter fullscreen mode Exit fullscreen mode

Works Without Laravel Too

Plain PHP — no framework needed:

use Wasaas\WasaasClient;

$client = new WasaasClient(apiKey: 'wsa_your_key_here');
$client->messages->sendText('my-session', '966501234567', 'Hello from PHP!');
Enter fullscreen mode Exit fullscreen mode

Links

Would love your feedback — drop a comment or open an issue on GitHub!

Top comments (0)