ReachBellDocs

Server SDK (PHP)

reachbell/reachbell is the PHP server-side companion to the browser SDK. Use it from your backend to send transactional messages, track events, and manage subscribers — without writing raw HTTP calls. It also powers the Laravel, CodeIgniter, and WooCommerce integrations. The Server API is the underlying REST layer for anything the SDK doesn't wrap yet.

PHP 8.1+.

Install

composer require reachbell/reachbell

Initialize

use ReachBell\ReachBell;
 
$rb = new ReachBell('rb_live_yourkey'); // keep this server-side only

Keep your API key server-side only — never ship it to the browser. (The browser uses the public key via @reachbell/sdk.) Option arrays use the API's camelCase keys; null values are dropped automatically.

Transactional push

Send a push to one user, identified by externalId (set via the browser SDK's identify()) or by raw token:

$r = $rb->transactional->send([
    'externalId' => 'user_42',
    'title'      => 'Order shipped 📦',
    'body'       => 'Your order arrives tomorrow.',
    'url'        => 'https://shop.example/orders/4821',
]);
 
// A 200 with delivered=false just means the user has no active subscription —
// a normal outcome, not an error.
if (empty($r['delivered'])) {
    // no active subscription
}

Pass templateId (plus variables) instead of title/body to send from a saved template.

Transactional email

$rb->transactional->email([
    'to'          => 'user@example.com',
    'subject'     => 'Your verification code',
    'htmlContent' => '<p>Your code is <b>123456</b></p>',
]);

senderEmail / replyTo must be on your verified sending domain.

Transactional SMS & WhatsApp

$rb->transactional->sms(['externalId' => 'user_42', 'text' => 'Your code is 123456']);
 
$rb->transactional->whatsapp([
    'externalId' => 'user_42',
    'template'   => ['name' => 'order_update', 'params' => ['#4821', 'shipped']],
]);

WhatsApp business-initiated messages need a pre-approved template (outside WhatsApp's 24-hour customer-service window); inside it you can send free-form text. Both channels must be configured for your project first — see SMS and WhatsApp.

Track events

Events can trigger automations:

$rb->events->track(['name' => 'order_paid', 'externalId' => 'user_42', 'properties' => ['amount' => 4999]]);
$rb->events->trackBatch([ /* up to 25 events */ ]);

Subscribers

$rb->subscribers->identify($token, 'user_42'); // link a subscription to your user id
$rb->subscribers->delete($token);              // remove a subscriber

Errors

Non-2xx responses and network failures throw a ReachBell\ReachBellException with ->statusCode (0 for network errors) and ->body:

use ReachBell\ReachBellException;
 
try {
    $rb->transactional->send(['externalId' => 'u', 'title' => 't', 'body' => 'b']);
} catch (ReachBellException $e) {
    error_log($e->statusCode . ' ' . json_encode($e->body));
}

Laravel

Bind it once as a singleton (e.g. in AppServiceProvider::register), then type-hint ReachBell\ReachBell anywhere or resolve with app(\ReachBell\ReachBell::class):

$this->app->singleton(\ReachBell\ReachBell::class, fn () =>
    new \ReachBell\ReachBell(config('services.reachbell.key'))
);

CodeIgniter

Register a shared service in app/Config/Services.php, then use \Config\Services::reachbell():

public static function reachbell(bool $getShared = true)
{
    if ($getShared) return static::getSharedInstance('reachbell');
    return new \ReachBell\ReachBell(getenv('REACHBELL_KEY'));
}

Escape hatch

For any endpoint not yet wrapped by a helper:

$rb->request('POST', '/some/endpoint', ['any' => 'payload']);