PHP code example of advhub / meta-whatsapp-laravel

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

    

advhub / meta-whatsapp-laravel example snippets


use AdvHub\MetaWhatsApp\MetaWhatsAppClient;

$meta = app(MetaWhatsAppClient::class);
$meta->sendText('11999999999', 'Olá!');

MetaWhatsApp::sendText('11999999999', 'Olá!');

$meta->sendImage('11999999999', 'https://site.com/imagem.jpg', 'Legenda');

$meta->sendDocument('11999999999', 'https://site.com/arquivo.pdf', 'arquivo.pdf', 'Segue em anexo');

$meta->sendTemplate(
    '11999999999',
    'notificacao_tarefa',
    'pt_BR',
    [
        [
            'type' => 'body',
            'parameters' => [
                ['type' => 'text', 'text' => 'Ricardo'],
                ['type' => 'text', 'text' => '#123'],
            ],
        ],
    ]
);

use AdvHub\MetaWhatsApp\Support\WebhookVerifier;
use Illuminate\Http\Request;

public function verify(Request $request, WebhookVerifier $verifier)
{
    $challenge = $verifier->verifyChallenge($request);
    if ($challenge === null) {
        return response()->json(['message' => 'Token inválido'], 403);
    }

    return response($challenge, 200);
}

public function handle(Request $request, WebhookVerifier $verifier)
{
    if (!$verifier->hasValidSignature($request)) {
        return response()->json(['message' => 'Assinatura inválida'], 401);
    }

    $statuses = $verifier->extractStatuses($request->all());
    // atualizar dt_lido etc.

    return response()->json(['ok' => true]);
}
bash
php artisan vendor:publish --tag=meta-whatsapp-config