PHP code example of aghfatehi / laravel-whatsapp-api
1. Go to this page and download the library: Download aghfatehi/laravel-whatsapp-api 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/ */
aghfatehi / laravel-whatsapp-api example snippets
use Aghfatehi\WhatsApp\Facades\WhatsApp;
// Send a text message
WhatsApp::messages()->sendText('966555555555', 'Hello!');
// Send a media message (image, document, audio, video)
WhatsApp::messages()->sendMedia('966555555555', 'image', 'https://example.com/photo.jpg', 'Caption');
// Send a template message
WhatsApp::messages()->sendTemplate('966555555555', 'hello_world', 'en');
// Send a location
WhatsApp::messages()->sendLocation('966555555555', 24.7136, 46.6753, 'Riyadh', 'Saudi Arabia');
// Send an interactive (button/list)
WhatsApp::messages()->sendInteractive('966555555555', [
'type' => 'button',
'body' => ['text' => 'Choose:'],
'action' => [
'buttons' => [
['type' => 'reply', 'reply' => ['id' => '1', 'title' => 'Yes']],
['type' => 'reply', 'reply' => ['id' => '2', 'title' => 'No']],
],
],
]);
// Send reaction
WhatsApp::messages()->sendReaction('966555555555', 'wamid.xxx', '👍');
// Mark message as read
WhatsApp::messages()->markAsRead('wamid.xxx');
WhatsApp::media()->upload($filePath, $type); // Upload to WhatsApp servers
WhatsApp::media()->getUrl($mediaId); // Get download URL
WhatsApp::media()->download($mediaId); // Download raw content
WhatsApp::media()->delete($mediaId); // Delete from WhatsApp
WhatsApp::phoneNumbers()->list(); // All phone numbers
WhatsApp::phoneNumbers()->get($phoneNumberId); // Single number details
WhatsApp::phoneNumbers()->requestPin($phoneNumberId);
WhatsApp::phoneNumbers()->verifyPin($phoneNumberId, $pin);
WhatsApp::phoneNumbers()->deregister($phoneNumberId);