PHP code example of relaybell / relaybell-php
1. Go to this page and download the library: Download relaybell/relaybell-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/ */
relaybell / relaybell-php example snippets
elaybell\Client;
use Relaybell\RelaybellException;
$client = new Client('rb_live_xxxx');
try {
$result = $client->send([
'title' => 'Flash sale ends tonight',
'body' => '20% off everything until midnight.',
'url' => 'https://shop.example.com/sale',
'icon' => 'https://shop.example.com/icon.png',
]);
echo "Queued notification {$result['notificationId']} (status: {$result['status']})\n";
} catch (RelaybellException $e) {
fwrite(STDERR, "RelayBell error {$e->getStatusCode()}: {$e->getErrorCode()}\n");
fwrite(STDERR, $e->getResponseBody() . "\n");
}
// Default base URL is https://relaybell.com.
$client = new Client('rb_live_xxxx');
// Override the base URL (staging, self-hosted, etc.).
$client = new Client('rb_live_xxxx', 'https://staging.relaybell.com');
// Tune timeouts (seconds).
$client = new Client('rb_live_xxxx', 'https://relaybell.com', [
'timeout' => 30, // total request timeout (default 30)
'connectTimeout' => 10, // connection phase timeout (default 10)
]);
$client->send([
'title' => 'Back in stock',
'body' => 'The item on your wishlist is available again.',
'url' => 'https://shop.example.com/p/123',
'icon' => 'https://shop.example.com/icon.png',
'image' => 'https://shop.example.com/hero.jpg',
'badge' => 'https://shop.example.com/badge.png',
'actions' => [
['action' => 'view', 'title' => 'View item'],
],
',
]);
// => ['ok' => true, 'notificationId' => 'ntf_...', 'status' => 'queued']
$client->track('product_viewed', [
'externalId' => 'user_42', // your ID for the subscriber
// 'subscriberId' => 'sub_...', // or RelayBell's subscriber ID
'properties' => [
'productId' => 'sku_123',
'price' => 49.0,
],
]);
// => ['ok' => true, 'eventId' => 'evt_...', 'subscriberId' => 'sub_...',
// 'automationsTriggered' => [...], 'sequencesEnrolled' => [...]]
$client->trackConversion(129.99, [
'externalId' => 'user_42',
'orderId' => 'ord_789',
'currency' => 'USD',
]);
// Emits event "conversion" with properties { value: 129.99, orderId, currency }.
$stats = $client->stats();
// => ['subscribers' => 12345,
// 'totals' => ['sent' => ..., 'clicks' => ..., 'ctr' => ...,
// 'conversions' => ..., 'revenue' => ...],
// 'notifications' => [ ... ]]
try {
$client->send(['title' => 'Hi']);
} catch (RelaybellException $e) {
$e->getStatusCode(); // int — HTTP status, or 0 for transport errors
$e->getErrorCode(); // ?string — the API's "error" code, e.g. "invalid_api_key"
$e->getResponseBody(); // string — raw, undecoded response body
$e->getResponseData(); // ?array — decoded JSON body, if any
}
bash
composer json
{
"repositories": [
{ "type": "path", "url": "sdks/php" }
],
"