WAservix · WordPress

WAservix WordPress integration

WordPress pluginSend WhatsApp messages and add a chat button without writing code: install the free WAservix for WordPress plugin.
Get the plugin →

Connect WAservix to your WordPress app: send WhatsApp messages from your own WhatsApp number, check delivery and receive replies by webhook. Copy the examples, add your key and run.

Requirements

WordPress 5.6+. Put the code in a small plugin (or your theme’s functions.php); it uses the built-in HTTP API.

Add your API key

Create a key under WAservix → Devices → API key (it starts with wpk_). Keep it on your server, in an environment variable or secret store. Never put it in a website, a mobile app or a public repository.

// wp-config.php (above "That's all, stop editing!")
define('WASERVIX_KEY', 'wpk_your_key');
define('WASERVIX_WEBHOOK_SECRET', 'your_webhook_secret');

Send a WhatsApp message

Messages are queued and sent one at a time per number, so the answer comes back at once with "status": "in_progress" and a msgId.

$res = wp_remote_request('https://tekservix.com/waservix/api/send-message', [
    'method'  => 'POST',
    'timeout' => 30,
    'headers' => ['Authorization' => 'Bearer ' . WASERVIX_KEY, 'Content-Type' => 'application/json'],
    'body'    => wp_json_encode([
        'to' => '+250788123456',
        'text' => 'Hello Aline, your order is ready',
    ]),
]);
if (is_wp_error($res)) { error_log($res->get_error_message()); return; }
$json = json_decode(wp_remote_retrieve_body($res), true);
if (wp_remote_retrieve_response_code($res) >= 400) { error_log($json['message'] ?? 'API error'); return; }

Send a document or image

Use imageUrl, videoUrl, audioUrl or documentUrl with a public https link. Groups work too: put the group JID (…@g.us) in to.

$res = wp_remote_request('https://tekservix.com/waservix/api/send-message', [
    'method'  => 'POST',
    'timeout' => 30,
    'headers' => ['Authorization' => 'Bearer ' . WASERVIX_KEY, 'Content-Type' => 'application/json'],
    'body'    => wp_json_encode([
        'to' => '+250788123456',
        'text' => 'Your invoice',
        'documentUrl' => 'https://example.com/inv-1042.pdf',
        'fileName' => 'Invoice-1042.pdf',
    ]),
]);
if (is_wp_error($res)) { error_log($res->get_error_message()); return; }
$json = json_decode(wp_remote_retrieve_body($res), true);
if (wp_remote_retrieve_response_code($res) >= 400) { error_log($json['message'] ?? 'API error'); return; }

Check message status

status is queued, sent, delivered, read, played or failed. Webhooks tell you without polling.

$res = wp_remote_request('https://tekservix.com/waservix/api/messages/58213/info', [
    'method'  => 'GET',
    'timeout' => 30,
    'headers' => ['Authorization' => 'Bearer ' . WASERVIX_KEY],
]);
if (is_wp_error($res)) { error_log($res->get_error_message()); return; }
$json = json_decode(wp_remote_retrieve_body($res), true);
if (wp_remote_retrieve_response_code($res) >= 400) { error_log($json['message'] ?? 'API error'); return; }

Receive WhatsApp messages by webhook

Set a webhook URL and events for the number under WAservix → Devices. Each request carries X-Webhook-Signature, which equals that device’s webhook secret. Compare it in constant time, answer 2xx quickly and process the message after answering (we retry 3 times).

add_action('rest_api_init', function () {
    register_rest_route('wapenda/v1', '/webhook', [
        'methods'             => 'POST',
        'permission_callback' => function (WP_REST_Request $req) {
            return hash_equals(WASERVIX_WEBHOOK_SECRET, (string) $req->get_header('X-Webhook-Signature'));
        },
        'callback' => function (WP_REST_Request $req) {
            $event = $req->get_json_params();
            if ($event['event'] === 'messages.received') {
                $m = $event['data']['messages'];
                error_log(($m['key']['cleanedSenderPn'] ?? '') . ': ' . ($m['messageBody'] ?? ''));
            }
            return new WP_REST_Response(null, 200);
        },
    ]);
});
// Webhook URL: https://yoursite.com/wp-json/wapenda/v1/webhook

Errors, limits and retries

Every answer has success; errors add a readable message. 401 means a wrong key, 402 no active plan for this number or phone, 409 the number or phone isn’t connected, 429 too many requests (300 a minute per key): wait for the Retry-After seconds and try again. Retry 5xx and network errors with a back-off, but don’t blindly retry a send that may have worked: check its status first, or you could send twice.

Full list of endpoints and fields: WAservix API reference.

Questions

Is this the official WhatsApp Business API?

No. WAservix links your own number as a companion device, like WhatsApp Web, so there is no Meta approval. Only message people who expect to hear from you: WhatsApp can ban numbers that spam.

Can I call the API from a mobile app or browser?

Don’t. Anyone could read the key from the app or page. Call the API from your server and let your app talk to your server.

Other languages