1. Go to this page and download the library: Download whatsdev/whatsdev-php 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/ */
whatsdev / whatsdev-php example snippets
use WhatsDev\Client;
$client = new Client('YOUR_TEST_API_KEY');
$session = $client->sessions()->create();
while ($client->sessions()->get($session['data']['id'])['data']['status'] !== 'connected') {
sleep(1);
}
$result = $client->messages()->sendText($session['data']['id'], '967700000000', 'Hello from WhatsDev!');
echo $result->data['data']['id'];
use WhatsDev\Exceptions\ApiException;
use WhatsDev\Exceptions\QuotaExceededException;
try {
$client->messages()->sendText($sessionId, '967700000000', 'Hello!');
} catch (QuotaExceededException $e) {
// this plan's daily or monthly send quota is used up
echo "Out of quota: {$e->errorCode}\n";
} catch (ApiException $e) {
// any other typed API error — $e->errorCode, $e->status, $e->details and $e->requestId are all available
echo "Request {$e->requestId} failed ({$e->status}): {$e->getMessage()}\n";
}
$file = $client->messages()->media($messageId);
file_put_contents('/tmp/inbound-media', $file->contents);
echo $file->contentType; // e.g. image/jpeg, or null if the server named none
use WhatsDev\Webhooks\SignatureVerifier;
$rawBody = file_get_contents('php://input'); // must be the exact raw bytes, not a re-encoded payload
$signature = $_SERVER['HTTP_X_SIGNATURE'] ?? null;
SignatureVerifier::assert($rawBody, $signature, $webhookSecret); // throws InvalidSignatureException on failure
$payload = json_decode($rawBody, true);