Search by

relaywa / sdk

haidershakoori

RelayWA PHP SDK for WhatsApp messaging, sessions, and webhooks

v0.1.0 2026-10-30 04:42 UTC

This package is auto-updated.

Last update: 2026-10-30 05:47:47 UTC


README

Server-side PHP client for the RelayWA WhatsApp API. PHP 8.1+, cURL, and JSON are required. The package uses Composer PSR-4 autoloading and sends requests to https://relaywa.com/api by default.

Publication status: This package is being prepared for Packagist. composer require relaywa/sdk will work only after a Packagist package and installable release have been published. Do not assume it is available yet.

1. Prerequisites

  • PHP 8.1 or newer, with the curl and json extensions enabled
  • Composer
  • A RelayWA account and a valid session key for server-side API authentication

Check your setup:

php -v
php -m
composer --version

2. Install with Composer (after Packagist publication)

In an existing PHP or Laravel application:

composer require relaywa/sdk

Until the package is publicly released, you can test it locally using a Composer path repository. From a project with a checkout of the RelayWA monorepo:

composer config repositories.relaywa path "/absolute/path/to/wa/sdks/php"
composer require "relaywa/sdk:@dev"

This local installation is for testing only and is not the public Packagist release.

3. Configure credentials

Get your session key from your RelayWA account. Set RELAYWA_SESSION_KEY as a server environment variable; never put it in browser JavaScript, mobile applications, committed .env files, or logs.

Windows CMD

set "RELAYWA_SESSION_KEY=your-session-key"

PowerShell

$env:RELAYWA_SESSION_KEY = "your-session-key"

Linux / macOS

export RELAYWA_SESSION_KEY="your-session-key"

4. First request: list sessions (read-only)

Create example.php:

<?php
declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

$key = getenv('RELAYWA_SESSION_KEY');
if ($key === false || trim($key) === '') {
    throw new RuntimeException('Set RELAYWA_SESSION_KEY first');
}

$relaywa = new \RelayWA\Client($key);

try {
    $sessions = $relaywa->sessions();
    print_r($sessions);
} catch (RuntimeException $e) {
    fwrite(STDERR, 'RelayWA request failed: ' . $e->getMessage() . PHP_EOL);
    exit(1);
}

Run:

php example.php

This is a live read-only request. It does not connect, restart, or disconnect a WhatsApp session.

5. Send a text message (live operation)

Only run this once your WhatsApp session is connected and you have permission to message the recipient:

$result = $relaywa->sendText('12025550123', 'Hello from RelayWA');
print_r($result);

A successful request can send a real WhatsApp message. Avoid automatically retrying sends after ambiguous network timeouts; the first attempt might already have been processed.

6. More PHP examples

Session details and chats (read-only)

$details = $relaywa->session('your-session-id');
$chats = $relaywa->sessionChats('your-session-id');

Send an image by HTTPS URL (live operation)

$result = $relaywa->sendImage([
    'to' => '12025550123',
    'url' => 'https://example.com/image.jpg',
    'mimeType' => 'image/jpeg',
    'mediaSizeBytes' => 102400,
]);

The media URL must be HTTPS and the size must be within the SDK's per-media limit.

Laravel example

Set RELAYWA_SESSION_KEY in your deployment's environment configuration, then use the client from server-side application code:

use RelayWA\Client;

$relaywa = new Client((string) config('services.relaywa.session_key'));
$sessions = $relaywa->sessions();

In config/services.php, add:

'relaywa' => [
    'session_key' => env('RELAYWA_SESSION_KEY'),
],

Do not call the API from Blade/browser code. Laravel's config cache may need refreshing after deployment environment changes.

7. Supported methods

Category Methods
Text/media sendText, sendImage, sendVideo, sendAudio, sendDocument
Interactive messages sendLocation, sendContact, sendPoll, sendReply, sendReaction
Sessions sessions, session, createSession, updateSession, connectSession, restartSession, disconnectSession, deleteSession
Session data sessionQrCode, sessionStatistics, sessionLogs, sessionMessages, sessionMessage, sessionContacts, sessionChats, sessionGroups
Webhooks webhooks, createWebhook, updateWebhook, deleteWebhook, webhookDeliveries

The methods return decoded JSON arrays. Webhook endpoint management is supported; this PHP SDK does not currently expose a webhook-signature verification helper.

8. Troubleshooting

Problem What to check
Composer cannot find relaywa/sdk The package may not yet be published on Packagist; use the local path repository for pre-release testing.
Class "RelayWA\\Client" not found Install Composer dependencies and include vendor/autoload.php.
Call to undefined function curl_init() Enable the PHP cURL extension for the PHP runtime executing your app.
Session key required Set RELAYWA_SESSION_KEY in the server process environment.
RelayWA HTTP 401 or 403 Verify the session key and account permissions without sharing the key.
RelayWA transport failure Check HTTPS connectivity, DNS, firewall, and timeouts.

The SDK uses a 30-second request timeout, 10-second connection timeout, and disables HTTP redirects. API errors are thrown as RuntimeException. Never log credentials or automatically retry uncertain message sends.

9. Publishing note for maintainers

This repository is the dedicated Composer package repository for relaywa/sdk. Its root contains composer.json, src/, README.md, and LICENSE. After CI validation, tag a release and register this repository on Packagist. Keep release tags and Packagist metadata aligned.

Links

License

MIT.