PHP code example of dineshstack / laravel-whatsapp-cost-control

1. Go to this page and download the library: Download dineshstack/laravel-whatsapp-cost-control 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/ */

    

dineshstack / laravel-whatsapp-cost-control example snippets


use Dineshstack\WhatsApp\Services\WhatsAppService;

$wa = app(WhatsAppService::class);

// A pre-approved template
$wa->sendTemplate('971501234567', 'order_shipped', 'en_US', [
    ['type' => 'body', 'parameters' => [['type' => 'text', 'text' => '#4821']]],
]);

// OTP via the template configured in whatsapp.templates.otp
$wa->sendOtp('971501234567', '482913');

// Free-form text (only lands inside an open 24h service window)
$wa->sendText('971501234567', 'Your driver has arrived.');

use Dineshstack\WhatsApp\Models\WhatsAppSuppression;
use Dineshstack\WhatsApp\Services\WhatsAppSuppressionService;

app(WhatsAppSuppressionService::class)->suppress('971501234567', WhatsAppSuppression::SCOPE_ALL, WhatsAppSuppression::SOURCE_MANUAL, 'Asked at the counter');
app(WhatsAppSuppressionService::class)->lift('971501234567', WhatsAppSuppression::SOURCE_MANUAL);

// config/whatsapp.php
'routes' => [
    'admin' => [
        'prefix'     => 'api/v1/admin/whatsapp',
        'middleware' => ['api', 'auth:sanctum'],
    ],
],
bash
php artisan whatsapp:test {phone}       # end-to-end send check
php artisan whatsapp:templates          # list templates as Meta sees them
php artisan whatsapp:prune-logs         # trim the audit log (default 90 days)