An SDK to easily work with the Notific API
This SDK lets you perform API calls to Notific. API documentation https://notific.io/api
Usage
To install the SDK in your project you need to require the package via composer:
$ composer require notific/notific-php-sdk
Create an instance of the SDK:
$notific = new Notific\PhpSdk\Notific(APP_ID, API_TOKEN);
If you don't have an App ID yet, sign up at https://app.notific.io/signup
Public notifications
You can get an array of public notification instances with publicNotifications()
method.
$notific->publicNotifications();
You can optionally give arguments to method which will be transformed to query parameters. Read more about filtering and sorting options from API documentation
$notific->publicNotifications([
'page' => 2,
'limit' => 25,
'sort' => '-created_at'
]);
Create new public notification.
$notific->createPublicNotification([
'title' => 'Welcome!'
'body' => 'This is the body of the notification...'
]);
Retrieve a public notification instance.
$notification = $notific->publicNotification($id);
Update the notification.
$notification->update([
'title' => 'Boom!'
'body' => 'This is the updated body of the notification.'
]);
Delete the notification.
$notification->delete();
Recipients
You can get an array of recipient instances with recipients()
method.
$notific->recipients();
You can optionally give arguments to method which will be transformed to query parameters. Read more about filtering and sorting options from API documentation
Create a recipient.
$notific->createRecipient([
'id' => '123', // Unique identifier for the user. You can use integers, hashes or what ever suites you best.
'name' => 'Kung Fury',
'email' => 'kung.fury@email.com'
'phone' => '+358 40 123 456' // You can add meta information to recipient as key => value pairs.
]);
Retrieve a recipient instance.
$recipient = $notific->recipient($id);
Update the recipient.
$recipient = $recipient->update([
'name' => 'Fury'
]);
Add tags to the recipient.
$recipient = $recipient->tag([
'Foo', 'Bar', 'Baz'
]);
Remove tags from the recipient.
$recipient = $recipient->removeTags([
'Bar'
]);
Remove all tags from the recipient.
$recipient = $recipient->removeAllTags();
Templates
Where private notifications are immutable and unnamed, templates are editable and easy to retrieve by name.
You can get an array of template instances with templates()
method.
$notific->templates();
Create a template.
$notific->createTemplate([
'title' => 'Lorem ipsum dolor sit amet.',
'body' => 'Lorem ipsum dolor sit amet, consectetur adipiscing...',
'name' => 'lorem-ipsum'
]);
Retrieve a template with a name parameter.
$template = $notific->template($name);
Private notifications
You can get an array of private notification instances with privateNotifications()
method.
$notific->privateNotifications();
You can optionally give arguments to method which will be transformed to query parameters. Read more about filtering and sorting options from API documentation
$notific->privateNotifications([
'filter[type]' => '1,2',
'sort' => '-created_at'
]);
Create new private notification.
$notific->createPrivateNotification([
'title' => 'Welcome!'
'body' => 'This is the body of the private notification...'
]);
Retrieve a private notification instance.
$notification = $notific->privateNotification($id);
Update the private notification.
$notification->update([
'title' => 'Boom!'
'body' => 'This is the updated body of the private notification.'
]);
Send private notifications
You can use a private notification or a template to send a private notifications to recipient(s). We recommend you to use templates because they are easier to refer and manage as they are editable.
Send private notification with the notification id and recipient(s) id:s. Recipients can be a string, a list or an an array of id:s.
$data = $notific->template($name)->recipients($recipients)->send()
$data = $notific->privateNotification($notificationId)->recipients($recipients)->send()
You can use two delivery channels to send private notifications, broadcast (default) and email. Email channel requires valid email settings.
$data = $notific->template($name)->recipients($recipients)->channels('broadcast', 'email')->send()
$data = $notific->privateNotification($notificationId)->recipients($recipients)->channels('broadcast')->send()
If you are tagging your recipients you can send notification using tags. Tags can be a string, a list or an array of id:s. Recipient must have all given tags.
$data = $notific->template($name)->tags($tags)->send()
$data = $notific->privateNotification($notificationId)->tags($tags)->send()
To send a notification to ALL your recipients, use predefined tag all.
$data = $notific->template($name)->tags('all')->send()
$data = $notific->privateNotification($notificationId)->tags('all')->send()
Alternative way to send private notification with private notification instance.
$data = $notific->template($id)->sendTo($recipients);
$data = $notific->privateNotification($notificationId)->sendTo($recipients);
Send private notification with recipient instance.
$data = $notific->recipient($id)->sendNotification($notificationId);
Tip: you can test the private notification and send it to your self. You will receive the notification instantly if you are logged in to notific.io dashboard.
$data = $notific->template($name)->test();
$data = $notific->privateNotification($id)->test();
Pagination & limiting
Response data will be paginated to 15 items by default. Navigating through the pages and limiting the number of items per page can be done with query parameters. For example ?page=2&limit=25
. Read more about paging and limiting from API documentation.
Security
If you discover any security related issues, please email kalle@klopal.com instead of using the issue tracker.
Credits
This package uses code from and is greatly inspired by the Oh Dear SDK package which is inspired by the Forge SDK package by Mohammed Said.
License
The MIT License (MIT). Please see License File for more information.