PHP code example of rocketslab / wa-laravel

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

    

rocketslab / wa-laravel example snippets


    /* Com o servidor da API iniciado...
    // O segundo parâmetro é opcional. E informa a API
    */ que é uma versão legada do WA 
      
    $wa = \RocketsLab\WALaravel\WhatsApp::factory();
    /* Recomenda-se remover a sessão existente */
    $wa->removeSession('session-id');   
    $wa->startSession('session-id', false);

// No arquivo de rotas
Route::post('sendMessage', funciton(Request $request) {
    /* Pode-se extrair somente o necessário da requisição */
    $data = $request->only(['receiver', 'message', 'sessionId']);
    
    \RocketsLab\WALaravel\WhatsApp::factory()
        ->sendText(...$data);
})

Route::get('whatsapp-config', function() { 
   
   $sessionId = 'my-session';
   return view('wa-config', compact('sessionId')); 

});

<!-- VIEW: wa-config -->

@push('scripts') 
    <script>
        Echo.channel('{{ ".meesage-upsert.{$sessionId}" }}') 
            .listen('.message-upsert', ({ event }) => {
                console.log("MU: " + JSON.stringify(event))
            });
    </script>
@endpush
shell
php artisan wa:install
shell
php artisan vendor:publish --provider=RocketsLab\\WALaravel\\WALaravelServiceProvider
shell
php artisan websocket:serve
shell
php artisan wa:serve