sendivent / sdk
Official PHP SDK for Sendivent - Multi-channel notification platform
Installs: 50
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/sendivent/sdk
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.0
This package is auto-updated.
Last update: 2025-12-25 08:11:37 UTC
README
Official PHP SDK for Sendivent - Multi-channel notification platform supporting Email, SMS, Slack, and Push notifications.
Installation
composer require sendivent/sdk
Requires PHP 8.1+ and Guzzle 7.0+
Quick Start
use Sendivent\Sendivent; $sendivent = new Sendivent('test_your_api_key_here'); $sendivent ->event('welcome') ->to('user@example.com') ->payload(['name' => 'John Doe']) ->send();
The SDK automatically routes to sandbox (test_*) or production (live_*) based on your API key prefix.
Response Object
The send() method returns a SendResponse object with helper methods:
$response = $sendivent ->event('invoice') ->to('user@example.com') ->payload(['amount' => 100]) ->send(); if ($response->isSuccess()) { echo "Sent! Queue IDs: " . json_encode($response->data); } else { echo "Error: " . $response->error; } // Available properties: success, data, error, message // Available methods: isSuccess(), hasError(), toArray(), toJson()
Fire-and-Forget
For background sending without waiting for the response:
$promise = $sendivent ->event('notification') ->to('user@example.com') ->payload(['message' => 'Hello']) ->sendAsync(); // Continue with other work... // Promise resolves in background
Contact Objects & Smart Detection
The to() method accepts strings, Contact objects, or arrays of either. Sendivent automatically detects what type of identifier you're sending:
// String inputs - automatically detected by pattern matching $sendivent->event('welcome')->to('user@example.com')->send(); // Detected as email $sendivent->event('sms-code')->to('+1234567890')->send(); // Detected as phone $sendivent->event('alert')->to('U12345')->send(); // Detected as Slack user ID // Contact objects - your user's ID maps to external_id in Sendivent $sendivent ->event('welcome') ->to([ 'id' => 'user-12345', // Your user's ID 'email' => 'user@example.com', 'phone' => '+1234567890', 'name' => 'John Doe', 'avatar' => 'https://example.com/avatar.jpg', 'meta' => ['tier' => 'premium'] ]) ->payload(['welcome_message' => 'Hello!']) ->send(); // Multiple recipients $sendivent ->event('newsletter') ->to([ 'user1@example.com', ['id' => 'user-456', 'email' => 'user2@example.com', 'name' => 'Jane'] ]) ->payload(['subject' => 'Monthly Update']) ->send(); // Broadcast to Slack channel (no contact created) $sendivent ->event('system-alert') ->channel('slack') ->to('#general') // Broadcasts to channel, doesn't create contact ->payload(['message' => 'System update']) ->send();
Key Features
- Multi-channel - Email, SMS, Slack, and Push in one API
- Fluent API - Clean, chainable method calls
- Type-safe - Full PHP 8.1+ type hints
- Fire-and-forget - Async sending with
sendAsync() - Idempotency - Prevent duplicate sends with
idempotencyKey() - Template overrides - Customize subject, sender, etc. per request
- Language support - Send in different languages with
language() - Channel control - Force specific channels with
channel() - Broadcast mode - Send to event listeners without specifying recipients
Additional Examples
Channel-Specific Sending
$sendivent ->event('verification-code') ->channel('sms') ->to('+1234567890') ->payload(['code' => '123456']) ->send();
Template Overrides
$sendivent ->event('invoice') ->to('user@example.com') ->payload(['amount' => 100]) ->overrides([ 'subject' => 'Custom Subject', 'from_email' => 'billing@company.com' ]) ->send();
Idempotency
$sendivent ->event('order-confirmation') ->to('user@example.com') ->payload(['order_id' => '12345']) ->idempotencyKey('order-12345-confirmation') ->send();
Language Selection
$sendivent ->event('welcome') ->to('user@example.com') ->payload(['name' => 'Anders']) ->language('sv') // Swedish ->send();
Broadcast Events
Send to configured event listeners without specifying recipients:
$sendivent ->event('system-alert') ->payload(['severity' => 'high', 'message' => 'System alert']) ->send();
Full Example
See example.php for a comprehensive demonstration of all SDK features.
Support
- Documentation: docs.sendivent.com
- Issues: github.com/sendivent/sdk-php/issues
License
MIT License - see LICENSE file for details.