PHP code example of emmaogunwobi / whatsapp-api

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!');

$response = $whatsappService->sendTemplateMessage('2348123456789', 'hello_world');

$response = $whatsappService->sendMediaMessage('2348123456789', 'https://example.com/image.jpg', 'image');
bash
php artisan vendor:publish --tag=config