Skip to main content

Overview

In V2, all API requests are processed through a queued system for improved reliability and performance. When you make any API request (send message, react, etc.), you receive an immediate response with a queued_request_uuid. Use this method to check the actual response of your queued request.
Learn more about the V2 queued request system in the Queued Requests Documentation.

Get Queued Request

Retrieve the status and response of a queued API request using its UUID.
use Hypersender\Hypersender;

$response = Hypersender::whatsapp()
  ->getQueuedRequest(
      uuid: 'a0816120-7e37-4e8b-8cf3-92deb2cdc133',
  );

// Check if the request is completed
$data = $response->json();
if ($data['response_status'] !== null) {
    // Request completed
    echo "Status: " . $data['response_status'];
    echo "Response: " . json_encode($data['response_body']);
} else {
    // Still processing
    echo "Request is still being processed...";
}
The response_status, response_body, and response_header will be null while the request is still being processed.

Response Fields

FieldTypeDescription
uuidstringThe unique identifier for this queued request
requestobjectThe original request payload you submitted
response_statusinteger | nullHTTP status code of the processed request. null while still processing
response_bodyobject | nullThe actual API response. Contains message details on success, error details on failure. null while processing
response_headerobject | nullResponse headers from the processed request. null while processing

Polling Example

If you need to wait for a request to complete, you can implement polling with exponential backoff:
use Hypersender\Hypersender;

function waitForCompletion(string $uuid, int $maxAttempts = 10): array
{
    $attempt = 0;

    while ($attempt < $maxAttempts) {
        $response = Hypersender::whatsapp()
            ->getQueuedRequest(uuid: $uuid);

        $data = $response->json();

        if ($data['response_status'] !== null) {
            return $data; // Request completed
        }

        // Exponential backoff: 100ms, 200ms, 400ms, 800ms...
        usleep(100000 * pow(2, $attempt));
        $attempt++;
    }

    throw new \Exception('Request did not complete in time');
}

// Usage
$sendResponse = Hypersender::whatsapp()
    ->safeSendTextMessage(
        chat_id: '[email protected]',
        text: 'Hello!',
    );

$uuid = $sendResponse->json()['queued_request_uuid'];
$result = waitForCompletion($uuid);

if ($result['response_status'] === 200) {
    echo "Message sent! ID: " . $result['response_body']['message_id'];
} else {
    echo "Failed with status: " . $result['response_status'];
}
For production applications, consider using webhooks instead of polling to receive real-time notifications when messages are sent, delivered, or fail.