Download the PHP package relaybell/relaybell-php without Composer
On this page you can find all versions of the php package relaybell/relaybell-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download relaybell/relaybell-php
More information about relaybell/relaybell-php
Files in relaybell/relaybell-php
Package relaybell-php
Short Description Official PHP server-side SDK for RelayBell web push notifications, event tracking, analytics and webhook verification.
License MIT
Homepage https://relaybell.com
Informations about the package relaybell-php
RelayBell PHP SDK
Official server-side PHP SDK for RelayBell — send web push notifications, track behavioural events, record conversions, and read analytics from your backend.
- PHP 7.4+, framework-free.
- Dependency-light: only
ext-curlandext-json(both bundled with typical PHP builds). - PSR-4 autoloaded under the
Relaybell\namespace.
This is the server-side SDK. To collect subscribers in the browser, use the browser SDK instead — it runs on your storefront, not your server.
Installation
Not published to Packagist yet? Point Composer at the directory:
Quick start
Configuration
Authentication uses the HTTP header Authorization: Bearer <API_KEY>, applied
automatically to every request.
API
send(array $notification): array
POST /api/v1/notifications — send or schedule a push. title is required.
track(string $event, array $opts = []): array
POST /api/v1/events — track a behavioural event. May trigger automations and
sequence enrolments server-side.
trackConversion($value, array $props = []): array
Convenience wrapper over track() that emits a purchase event with a monetary
value in its properties — the same event the browser SDK's trackConversion()
sends. It counts as a conversion (the value is credited to the last notification
that subscriber received) and cancels pending cart reminders and journeys set to
stop on purchase. externalId / subscriberId in $props are lifted out and
used for subscriber attribution; all other keys become event properties. Before
1.1.0 this method sent an event named conversion.
stats(): array
GET /api/v1/stats — account analytics.
listNotifications(array $params = []): array
GET /api/v1/notifications — your sends, newest first, 25 a page. Filters:
from / to (days, "YYYY-MM-DD"), status (one, or a list: draft,
scheduled, queued, held_for_review, sending, sent, failed, canceled — without it,
everything except drafts), q (search in titles and texts), limit (1–100),
cursor and tz.
getNotification(string $id): array
GET /api/v1/notifications/:id — one notification with its report:
['notification', 'funnel', 'devices', 'variants', 'languages', 'errors', 'revenue', 'currency', 'sendBody'].
An id that isn't one of this website's throws a RelaybellException with status 404.
Identity verification
When your site tells relaybell who a signed-in visitor is (externalId, often
their email), sign that id on your server with Client::userHash(). Once your
project requires verified ids (dashboard → Settings → Developer → User ID
verification), relaybell ignores an id that comes without a valid hash, so nobody
can pretend to be one of your customers to get their notifications.
Client::userHash(string $secret, string $externalId): string returns the
lowercase hex HMAC-SHA256 of the id keyed with the secret — the same as
hash_hmac('sha256', $externalId, $secret). Sign the id exactly as you pass it
to the browser. If you rotate the secret, update your server's copy: hashes made
with the old secret stop working at once.
Verifying webhooks
relaybell signs every webhook it sends to your server. Relaybell\Webhook::verify()
checks the X-Relaybell-Webhook-Signature header and returns the event — or
throws Relaybell\WebhookVerificationException — with no network request:
Webhook::verify(string $payload, array $headers, $secret, int $tolerance = 300, bool $allowLegacy = false): array
fails closed; getReason() is one of:
| Reason | When |
|---|---|
missing_secret |
The secret is empty, null or false (an unset getenv()) — it never verifies without one |
missing_signature |
No X-Relaybell-Webhook-Signature header |
malformed_signature |
The header has no valid t / v1 |
timestamp_out_of_tolerance |
The signature is more than $tolerance seconds old (or ahead): a replayed request |
signature_mismatch |
Wrong secret, or the body was changed (or decoded and re-encoded) |
invalid_payload |
The body isn't a JSON object |
The older X-Relaybell-Signature header (a signature of the body only, with no
timestamp) is still sent, but is accepted only with $allowLegacy = true and only
when the request has no v1 signature. relaybell retries failed deliveries for
about 10 hours, so the same event can arrive more than once: de-duplicate by
X-Relaybell-Delivery. See Webhooks.
Error handling
Every non-2xx response throws Relaybell\RelaybellException. Transport failures
(DNS, connection, timeout) throw the same exception with a status code of 0.
The API returns errors as JSON { "error": "code" } with a normal HTTP status.
getErrorCode() extracts that code for you.
Browser SDK
The server SDK is for backend calls only. To subscribe visitors and fire client-side events, load the browser SDK on your storefront:
Requirements
- PHP >= 7.4
ext-curl,ext-json
Changelog
1.2.0
- New
Relaybell\Webhook::verify($payload, $headers, $secret, $tolerance = 300)checks the timestampedX-Relaybell-Webhook-Signatureheader (constant-time,hash_equals) and returns the event; it throwsRelaybell\WebhookVerificationException(getReason()), including when the secret is empty. The olderX-Relaybell-Signatureis accepted only with$allowLegacy = true. See Verifying webhooks. - New
listNotifications(array $params = [])andgetNotification(string $id)forGET /api/v1/notificationsand/:id.
1.1.0
trackConversion()now sends apurchaseevent (it sentconversionbefore), the same event as the browser SDK and the WordPress plugin. Purchases recorded from your server now cancel cart reminders and journeys set to stop on a purchase. Its arguments haven't changed. If you built an automation or journey on theconversionevent, switch it topurchase.- New
Client::userHash($secret, $externalId)for identity verification: signs a visitor's id on your server so the browser SDK can prove it. No network request. See Identity verification.
License
MIT
All versions of relaybell-php with dependencies
ext-curl Version *
ext-json Version *