PHP code example of excelle-insights / whatsapp

1. Go to this page and download the library: Download excelle-insights/whatsapp 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/ */

    

excelle-insights / whatsapp example snippets



ExcelleInsights\WhatsApp\Facade\WhatsAppManager;

$whatsapp = new WhatsAppManager();

echo $whatsapp->getAuthUrl();
// Redirect the user to this URL for Meta Login

use ExcelleInsights\WhatsApp\Controller\OAuthController;

$oauth = new OAuthController($whatsapp);
echo $oauth->handleCallback();
// On success, all discovered WABAs are auto-linked

$whatsapp->setDirectToken('EAAT...');

$result = $whatsapp->sendText(1, '254712345678', 'Hello from WhatsApp API!');
echo $result->wam_id;

$result = $whatsapp->sendTemplate(1, '254712345678', 'welcome_msg', [
    'language' => 'en_US',
    'components' => [
        ['type' => 'body', 'parameters' => [['type' => 'text', 'text' => 'John']]],
    ],
]);

// Local (synced)
$local = $whatsapp->getAllTemplates(1);

// From Meta API
$remote = $whatsapp->getTemplatesFromMeta(1);

use ExcelleInsights\WhatsApp\Controller\WebhookController;

$webhook = new WebhookController($whatsapp);

// GET request — verification
$challenge = $webhook->verify();

// POST request — incoming messages / status updates
$response = $webhook->process();

$result = $whatsapp->downloadMedia(1, '4567890123456789', 'image', 'caption');
// ['media_url' => '2026/08/17/a1b2c3d4.jpg', 'media_mime_type' => 'image/jpeg', 'media_file_size' => 12345, 'wa_media_id' => '4567890123456789']

use ExcelleInsights\WhatsApp\Facade\WhatsAppManager;

$httpClient = new MyCustomHttpClient();
$whatsapp = new WhatsAppManager($httpClient);

$pdo = new PDO('mysql:host=...;dbname=...', 'user', 'pass');
$whatsapp = new WhatsAppManager(null, $pdo);
bash
# Using the package migrate script
php vendor/excelle-insights/whatsapp/migrate.php

# Or manually with Phinx
vendor/bin/phinx migrate -c vendor/excelle-insights/whatsapp/phinx.php