PHP code example of waapi / waapi-laravel-sdk

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

    

waapi / waapi-laravel-sdk example snippets


return [
    'api_token' => env('WAAPI_API_TOKEN'),
    'instance_id' => env('WAAPI_INSTANCE_ID'),
];

$waAPI = new WaAPI\WaAPI();
$waAPI->sendMessage('[email protected]', 'Hello there!');

app(WaAPI::class)->updateInstance(
    route('waapi.webhooks'),
    [
        EventType::MESSAGE->value,
        EventType::QR->value
    ]
);

    use App\Listeners\WaAPIInstanceReadyListener;
    use App\Listeners\WaAPIMessageListener;
    use WaAPI\WaAPI\Events\MessageEvent;
    use WaAPI\WaAPI\Events\QrEvent;
        
    [...]
        
    protected $listen = [
        MessageEvent::class => [
            WaAPIMessageListener::class,
        ],
        QrEvent::class => [
            WaAPIQrCodeListener::class,
        ],
    ];



namespace App\Listeners;

use WaAPI\WaAPI\Events\MessageEvent;
use WaAPI\WaAPI\WaAPI;

class WaAPIMessageListener
{
    /**
     * Handle the event.
     */
    public function handle(MessageEvent $message): void
    {
        if (!$message->isFromMe()) {
            app(WaAPI::class)->sendMessage($message->getFrom(), 'Hello to you too!');
        }
    }
}

bash
php artisan vendor:publish --tag="waapi-config"
bash
php artisan make:listener WaAPIMessageListener --event=\\WaAPI\\WaAPI\\Events\\MessageEvent
bash
php artisan make:listener WaAPIQrCodeListener --event=\\WaAPI\\WaAPI\\Events\\QrEvent