From 568fa32bb9522ee5c1f06226b97a4e9d4876af96 Mon Sep 17 00:00:00 2001 From: berkayk Date: Mon, 2 May 2016 17:18:39 +0300 Subject: [PATCH] Updated readme. --- README.md | 40 +++++++++++++++++++++++++++++++++++++++- src/OneSignalClient.php | 14 +++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d2186c7..012c4bf 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ ## Introduction +This is a simple OneSignal wrapper library for Laravel. It simplifies the basic notification flow with the defined methods. You can send a message to all users or you can notify a single user. Before you start installing this service, please complete your OneSignal setup at https://onesignal.com and finish all the steps that is necessary to obtain an application id and REST API Keys. @@ -46,7 +47,44 @@ You need to fill in `onesignal.php` file that is found in your applications `con ## Usage -... +### Sending a Notification To All Users +You can easily send a message to all registered users with the command + OneSignal::sendNotificationToAll("Some Message"); + OneSignal::sendNotificationToAll("Some Message", $url); + OneSignal::sendNotificationToAll("Some Message", $url, $data); + +`$url` and `$data` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. + + +### Sending a Notification To A Specific User + +After storing a user's tokens in a table, you can simply send a message with + + OneSignal::sendNotificationToUser("Some Message", $userId); + OneSignal::sendNotificationToUser("Some Message", $userId, $url); + OneSignal::sendNotificationToUser("Some Message", $userId, $url, $data); + +`$userId` is the user's unique id where he/she is registered for notifications. Read https://documentation.onesignal.com/docs/website-sdk-api#getUserId for additional details. +`$url` and `$data` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. + + +### Sending a Notification To Segment + +You can simply send a notification to a specific segment with + + OneSignal::sendNotificationToSegment("Some Message", $segment); + OneSignal::sendNotificationToSegment("Some Message", $segment, $url); + OneSignal::sendNotificationToSegment("Some Message", $segment, $url, $data); + +`$url` and `$data` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. + +### Sending a Custom Notification + +You can send a custom message with + + OneSignal::sendNotificationCustom($parameters); + +Please refer to https://documentation.onesignal.com/docs/notifications-create-notification for all customizable parameters. diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index b88b121..5ed2e9a 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -57,7 +57,7 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n $this->sendNotificationCustom($params); } - public function sendNotificationToAll($message, $data = null) { + public function sendNotificationToAll($message, $url = null, $data = null) { $contents = array( "en" => $message ); @@ -68,6 +68,10 @@ public function sendNotificationToAll($message, $data = null) { 'included_segments' => array('All') ); + if (isset($url)) { + $params['url'] = $url; + } + if (isset($data)) { $params['data'] = $data; } @@ -75,7 +79,7 @@ public function sendNotificationToAll($message, $data = null) { $this->sendNotificationCustom($params); } - public function sendNotificationToSegment($message, $segments, $data = null) { + public function sendNotificationToSegment($message, $segment, $url = null, $data = null) { $contents = array( "en" => $message ); @@ -83,9 +87,13 @@ public function sendNotificationToSegment($message, $segments, $data = null) { $params = array( 'app_id' => $this->appId, 'contents' => $contents, - 'included_segments' => array('All') + 'included_segments' => [$segment] ); + if (isset($url)) { + $params['url'] = $url; + } + if (isset($data)) { $params['data'] = $data; }