1. Go to this page and download the library: Download emmaogunwobi/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/ */
emmaogunwobi / whatsapp-api example snippets
use Emmaogunwobi\WhatsAppApi\Services\WhatsAppService;
class WhatsAppController extends Controller
{
protected $whatsappService;
public function __construct(WhatsAppService $whatsappService)
{
$this->whatsappService = $whatsappService;
}
public function sendWhatsAppMessage()
{
$recipient = '2348123456789'; // WhatsApp number in international format
$message = "Hello! This is a test message from Laravel.";
$response = $this->whatsappService->sendMessage($recipient, $message);
return response()->json($response);
}
}
php artisan serve
http://127.0.0.1:8000/api/send-whatsapp
$response = $whatsappService->sendMessage('2348123456789', 'Hello from Laravel!');