PHP code example of manzar / laravel-whatsapp-cloud
1. Go to this page and download the library: Download manzar/laravel-whatsapp-cloud 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/ */
use Manzar\WhatsAppCloud\Facades\WhatsApp;
// Option 1: get raw binary bytes (store in DB, stream to browser, etc.)
$bytes = WhatsApp::downloadMedia($incomingMessage->media_id);
// Stream directly to the browser
return response($bytes, 200)->header('Content-Type', 'image/jpeg');
// Option 2: save to a local path, returns the saved path
$path = WhatsApp::downloadMediaTo(
$incomingMessage->media_id,
storage_path('app/whatsapp/media/' . $incomingMessage->media_id . '.jpg')
);
// Option 3: use the media service directly for more control
$meta = WhatsApp::getMediaUrl($incomingMessage->media_id);
// $meta['url'] — authenticated temporary URL
// $meta['mime_type'] — e.g. image/jpeg
// $meta['sha256'] — checksum for verification
use Manzar\WhatsAppCloud\Models\WhatsAppIncomingMessage;
use Manzar\WhatsAppCloud\Models\WhatsAppOutgoingMessage;
use Manzar\WhatsAppCloud\Models\WhatsAppMessageStatus;
use Manzar\WhatsAppCloud\Models\WhatsAppWebhookLog;
// All unread incoming text messages
WhatsAppIncomingMessage::where('type', 'text')->latest()->get();
// All outgoing messages not yet delivered
WhatsAppOutgoingMessage::whereIn('status', ['pending', 'sent'])->get();
// Status history for a specific message
WhatsAppMessageStatus::where('wamid', 'wamid.HBgM...')->orderBy('sent_at')->get();
use Manzar\WhatsAppCloud\Contracts\WhatsAppStorageInterface;
// In AppServiceProvider::register()
$this->app->bind(WhatsAppStorageInterface::class, MyCustomStorage::class);