PHP code example of walinko / sdk

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

    

walinko / sdk example snippets


use Walinko\Client;

$client = new Client([
    'api_key'     => getenv('WALINKO_API_KEY'),
    'base_url'    => 'https://api.walinko.com', // optional
    'timeout'     => 30,                         // optional, seconds (used by waitUntilDone)
    'max_retries' => 2,                          // optional
    // 'http_client'     => $psr18Client,        // optional
    // 'request_factory' => $psr17Factory,       // optional
    // 'stream_factory'  => $psr17Factory,       // optional
    // 'logger'          => $psrLogger,          // optional
]);

// Sync send — blocks until the message is delivered (or 504 timeout).
$result = $client->messages->send([
    'device_id'     => 1,
    'template_id'   => 12,
    'variant_index' => 0,                                       // optional, null = primary
    'phone'         => '+8801617738431',
    'variables'     => ['name' => 'Kazi', 'dist' => 'Dhaka'],
]);

echo $result->trackingId;    // tx_...
echo $result->waMessageId;   // 3EB0...
echo $result->status;        // "sent"

// Async enqueue + poll.
$job = $client->messages->enqueue([
    'device_id'   => 1,
    'template_id' => 12,
    'phone'       => '+8801617738431',
    'variables'   => ['name' => 'Kazi', 'dist' => 'Dhaka'],
]);

$final = $client->messages->waitUntilDone($job->trackingId, timeout: 60);
echo $final->status;  // "sent" | "failed"

$status = $client->messages->fetch('tx_767fd2faca0f4037b2a2bbcb91e5735f');

$status->isSent();        // bool
$status->errorCode;       // null if sent, e.g. "phone_not_on_whatsapp" on failure
$status->waMessageId;     // WhatsApp's id, set on success
$status->createdAt;       // DateTimeImmutable
$status->sentAt;          // DateTimeImmutable, null while pending

use Walinko\Exception;

try {
    $client->messages->send([...]);
} catch (Exception\RateLimitException $e) {
    sleep($e->retryAfter ?? 1);
    // retry
} catch (Exception\ValidationException $e) {
    $logger->warning('validation failed', ['fields' => $e->fields()]);
} catch (Exception\DeviceDisconnectedException) {
    // tell the user to reconnect their device from the dashboard
} catch (Exception\WalinkoException $e) {
    $logger->error('Walinko send failed', ['error' => $e->getMessage()]);
}

$client->lastRateLimit();   // ?Walinko\Result\RateLimitSnapshot
$client->lastRequestId();   // ?string — handy for support tickets
bash
cd sdks/php
composer install
vendor/bin/phpunit
vendor/bin/phpstan analyse
vendor/bin/php-cs-fixer fix --dry-run --diff