PHP code example of bayurifkialghifari / waxum-php-client
1. Go to this page and download the library: Download bayurifkialghifari/waxum-php-client 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/ */
bayurifkialghifari / waxum-php-client example snippets
use Bayurifkialghifari\WaxumApi\Facades\WaxumApi;
use Bayurifkialghifari\WaxumApi\DTOs\Session\CreateSessionRequest;
use Bayurifkialghifari\WaxumApi\DTOs\Common\SendTextRequest;
// Create a WhatsApp session using DTO
$session = WaxumApi::session()->create(new CreateSessionRequest(
name: 'Support Session',
));
echo $session->id;
// Send a text message using DTO
$response = WaxumApi::message()->sendText('session-id-123', new SendTextRequest(
to: '[email protected]',
text: 'Hello from Waxum PHP Client! 👋',
));
echo $response->messageId; // Typed property from SendResponse DTO
// Arrays are also supported for quick calls
$response = WaxumApi::message()->sendText('session-id-123', [
'to' => '[email protected]',
'text' => 'Hello from array request!',
]);
use Bayurifkialghifari\WaxumApi\DTOs\Session\CreateSessionRequest;
use Bayurifkialghifari\WaxumApi\DTOs\Common\ConnectRequest;
// Create session
$session = WaxumApi::session()->create(new CreateSessionRequest(name: 'My Session'));
echo $session->id;
// Connect session
$result = WaxumApi::session()->connect('session-123', new ConnectRequest(subscribe: ['Message']));
echo $result->message;
// Get status
$status = WaxumApi::session()->getStatus('session-123');
echo $status->isLoggedIn; // bool
echo $status->socketAlive; // bool
echo $status->paused; // bool
// Pause / resume event processing without disconnecting
WaxumApi::session()->pause('session-123');
WaxumApi::session()->resume('session-123');
// Force an app-state resync
use Bayurifkialghifari\WaxumApi\DTOs\Session\AppStateResyncMode;
WaxumApi::session()->resyncAppState('session-123', ['critical_block'], AppStateResyncMode::SNAPSHOT);
// Fleet-wide operations
WaxumApi::session()->disconnectAll();
WaxumApi::session()->reconnectAll();
$hits = WaxumApi::session()->search('support');
// Export / import a session (ZIP)
WaxumApi::session()->export('session-123')->saveAs(storage_path('backup.zip'));
WaxumApi::session()->import('session-123', storage_path('backup.zip'));
use Bayurifkialghifari\WaxumApi\DTOs\Common\SendTextRequest;
use Bayurifkialghifari\WaxumApi\DTOs\Common\SendImageRequest;
// Send text
$response = WaxumApi::message()->sendText('session-123', new SendTextRequest(
to: '[email protected]',
text: 'Hello World!',
));
echo $response->messageId;
// Send image
$imageResponse = WaxumApi::message()->sendImage('session-123', new SendImageRequest(
to: '[email protected]',
image: 'https://example.com/image.jpg',
caption: 'Awesome picture',
));
use Bayurifkialghifari\WaxumApi\DTOs\Group\CreateGroupRequest;
// Create group
$group = WaxumApi::group()->create('session-123', new CreateGroupRequest(
subject: 'Development Team',
participants: ['[email protected]'],
));
use Bayurifkialghifari\WaxumApi\DTOs\Blast\CreateBlastRequest;
// Create blast job
$blast = WaxumApi::blast()->create('session-123', new CreateBlastRequest(
name: 'Promo Blast',
recipients: ['[email protected]'],
message: 'Check out our latest offer!',
));
use Bayurifkialghifari\WaxumApi\DTOs\Webhook\RegisterWebhookRequest;
// Register webhook
$webhook = WaxumApi::webhook()->register('session-123', new RegisterWebhookRequest(
url: 'https://example.com/webhook',
events: ['message', 'presence'],
));
// Dead-letter queue: inspect and replay failed deliveries
$dlq = WaxumApi::webhook()->listDlq('session-123');
WaxumApi::webhook()->replayDlq('session-123', $dlq->entries[0]->id);
use Bayurifkialghifari\WaxumApi\WebhookSignature;
public function handle(Request $request)
{
if (! WebhookSignature::fromRequest($request, config('services.waxum.webhook_secret'))) {
abort(401);
}
// ... process $request->json()
}