PHP code example of afro-technology / waha-laravel-sdk

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

    

afro-technology / waha-laravel-sdk example snippets


'hosts' => [
  'primary' => [
    'base_url' => env('WAHA_PRIMARY_URL', 'http://localhost:3000'),
    'api_key_header' => env('WAHA_API_KEY_HEADER', 'X-Api-Key'),
    'admin_api_key' => env('WAHA_PRIMARY_ADMIN_KEY'),
    'default_session' => env('WAHA_PRIMARY_DEFAULT_SESSION', 'default'),

    // Used for webhook signature verification (HMAC)
    'webhook_secret' => env('WAHA_PRIMARY_WEBHOOK_SECRET'),

    // admin_fallback | strict_session_key
    'mode' => env('WAHA_PRIMARY_MODE', 'admin_fallback'),

    // Optional: per-session keys (newer WAHA versions)
    'session_keys' => [
      // 'default' => env('WAHA_PRIMARY_DEFAULT_SESSION_KEY'),
    ],
  ],
],

use AfroTechnology\Waha\Facades\Waha;

$msg = Waha::sendText(
    chatId: '[email protected]',
    text: 'Hello from WAHA!'
);

$msg = Waha::chatting()->sendText(
    chatId: '[email protected]',
    text: 'Hello via tag proxy!'
);

Waha::host('primary')->sendText(chatId: '[email protected]', text: 'via primary');

Waha::host('secondary')->sendText(chatId: '[email protected]', text: 'via secondary');

// "chatting" tag
$msg = Waha::chatting()->sendText(chatId: '[email protected]', text: 'hi');

// "sessions" tag (example)
$status = Waha::sessions()->list();

$msg = Waha::sendText(chatId: '[email protected]', text: 'Convenience');

$msg = Waha::chatting()->sendText(...);

$arr = Waha::asArray()->sendText(chatId:'[email protected]', text:'array result');

$json = Waha::asJson()->sendText(chatId:'[email protected]', text:'json result');

$model = Waha::asModel()->sendText(chatId:'[email protected]', text:'model result');

$arr = Waha::chatting()->asArray()->sendText(...);

Waha::sendText(chatId:'[email protected]', text:'Hello');

$last = Waha::lastHttp();      // array with request/response/error
$curl = Waha::lastHttpCurl();  // curl string (if available)

Waha::debug()->sendText(chatId:'[email protected]', text:'debug for this call only');

Waha::withDebug(function () {
    Waha::sendText(chatId:'[email protected]', text:'debug scope 1');
    Waha::chatting()->sendText(chatId:'[email protected]', text:'debug scope 2');
});

'webhooks' => [
    'handlers' => [
        'message.any' => \App\Waha\Handlers\AnyMessageHandler::class,
        'message.*' => \App\Waha\Handlers\MessageHandler::class,
    ],
],

use AfroTechnology\Waha\Webhooks\Contracts\WahaWebhookHandler;
use AfroTechnology\Waha\Webhooks\Events\WahaWebhookReceived;

final class AnyMessageHandler implements WahaWebhookHandler
{
    public function handle(WahaWebhookReceived $event): void
    {
        $payload = $event->payload;
    }
}
bash
php artisan vendor:publish --provider="AfroTechnology\Waha\WahaServiceProvider" --tag="waha-config"
text
POST /webhooks/waha/{hostKey}
bash
php artisan vendor:publish --provider="AfroTechnology\Waha\WahaServiceProvider" --tag="waha-migrations"
php artisan migrate
bash
  php artisan waha:openapi:fetch
  
bash
  php artisan waha:openapi:generate
  
bash
  php artisan waha:openapi:update
  
bash
php artisan waha:openapi:ide-helper