From 874df712fe5599ccd203941600d163de753ddca1 Mon Sep 17 00:00:00 2001 From: "Kasper B. Svendsen" Date: Mon, 4 Dec 2017 19:00:37 +0100 Subject: [PATCH 01/61] getNotification and get method --- src/OneSignalClient.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index db676de..656a939 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -240,6 +240,16 @@ public function sendNotificationCustom($parameters = []){ return $this->post(self::ENDPOINT_NOTIFICATIONS); } + public function getNotification($notification_id, $app_id = null) { + $this->requiresAuth(); + $this->usesJSON(); + + if(!$app_id) + $app_id = $this->appId; + + return $this->get(self::ENDPOINT_NOTIFICATIONS . '/'.$notification_id . '?app_id='.$app_id); + } + /** * Creates a user/player * @@ -299,4 +309,8 @@ public function put($endPoint) { } return $this->client->put(self::API_URL . $endPoint, $this->headers); } + + public function get($endPoint) { + return $this->client->put(self::API_URL . $endPoint, $this->headers); + } } From 2072e3de0fd60785daf85c4fbc2ce13e91514c8b Mon Sep 17 00:00:00 2001 From: "Kasper B. Svendsen" Date: Mon, 4 Dec 2017 19:05:05 +0100 Subject: [PATCH 02/61] hotfix typo --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 656a939..107624e 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -311,6 +311,6 @@ public function put($endPoint) { } public function get($endPoint) { - return $this->client->put(self::API_URL . $endPoint, $this->headers); + return $this->client->get(self::API_URL . $endPoint, $this->headers); } } From 45ca12c17031bfe652618bc13a59a3cee6fce407 Mon Sep 17 00:00:00 2001 From: Ryan Edgar Date: Tue, 23 Jan 2018 23:10:51 +0000 Subject: [PATCH 03/61] Allow array of userIds to be passed instead of just a single userId --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index db676de..a9e5eb3 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -96,7 +96,7 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n $params = array( 'app_id' => $this->appId, 'contents' => $contents, - 'include_player_ids' => array($userId) + 'include_player_ids' => is_array($userId) ? $userId : array($userId) ); if (isset($url)) { From 563ff64a6a89e25a4063c01cf23f1f48615bdad3 Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Sat, 24 Feb 2018 15:06:18 +0330 Subject: [PATCH 04/61] Fixed filters/tags not working --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 16e8d3c..b787644 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -126,7 +126,7 @@ public function sendNotificationUsingTags($message, $tags, $url = null, $data = $params = array( 'app_id' => $this->appId, 'contents' => $contents, - 'tags' => $tags, + 'filters' => $tags, ); if (isset($url)) { From 04a0f53b522b9c4ecb403cc0d850d872ed127c80 Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Sat, 24 Feb 2018 15:08:48 +0330 Subject: [PATCH 05/61] updated read me updated read me to reflect new fixes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 553a1ee..1d6f530 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ You can easily send a message to all registered users with the command You can send a message based on a set of tags with the command - OneSignal::sendNotificationUsingTags("Some Message", array("key" => "device_uuid", "relation" => "=", "value" => 123e4567-e89b-12d3-a456-426655440000), $url = null, $data = null, $buttons = null, $schedule = null); + OneSignal::sendNotificationUsingTags("Some Message", array(["field" => "email", "relation" => "=", "value" => "m.alavi1989@gmail.com"]), $url = null, $data = null, $buttons = null, $schedule = null); ### Sending a Notification To A Specific User From 543a9f7c95fb75b6177adec3522f32111a29aabe Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Sat, 24 Feb 2018 15:42:51 +0330 Subject: [PATCH 06/61] Updated read me updated read me with another example for "Sending a Notification based on Tags/Filters" --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d6f530..26d9476 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,10 @@ You can easily send a message to all registered users with the command You can send a message based on a set of tags with the command +#####Example 1: OneSignal::sendNotificationUsingTags("Some Message", array(["field" => "email", "relation" => "=", "value" => "m.alavi1989@gmail.com"]), $url = null, $data = null, $buttons = null, $schedule = null); - +#####Example 2: + OneSignal::sendNotificationUsingTags("Some Message", array(["field" => "session_count", "relation" => ">", "value" => '2']), $url = null, $data = null, $buttons = null, $schedule = null); ### Sending a Notification To A Specific User From 587c9a3c0aaa12beec1fe7386341271f0bffea06 Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Tue, 27 Feb 2018 16:44:43 +0330 Subject: [PATCH 07/61] cahnged email to soemthing else --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 26d9476..b81694e 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ You can easily send a message to all registered users with the command You can send a message based on a set of tags with the command #####Example 1: - OneSignal::sendNotificationUsingTags("Some Message", array(["field" => "email", "relation" => "=", "value" => "m.alavi1989@gmail.com"]), $url = null, $data = null, $buttons = null, $schedule = null); + OneSignal::sendNotificationUsingTags("Some Message", array(["field" => "email", "relation" => "=", "value" => "someone@example.com"]), $url = null, $data = null, $buttons = null, $schedule = null); #####Example 2: OneSignal::sendNotificationUsingTags("Some Message", array(["field" => "session_count", "relation" => ">", "value" => '2']), $url = null, $data = null, $buttons = null, $schedule = null); From 3dbf904d0f2c8a8880677a8fd36b46fbcafe91c6 Mon Sep 17 00:00:00 2001 From: Michel Bardelmeijer Date: Sat, 3 Mar 2018 19:15:53 +0100 Subject: [PATCH 08/61] Add guzzle retry middleware --- src/OneSignalClient.php | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index b787644..ed7de75 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -3,6 +3,13 @@ namespace Berkayk\OneSignal; use GuzzleHttp\Client; +use GuzzleHttp\Exception\ConnectException; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Handler\CurlHandler; +use GuzzleHttp\HandlerStack; +use GuzzleHttp\Middleware; +use GuzzleHttp\Psr7\Request as Psr7Request; +use GuzzleHttp\Psr7\Response as Psr7Response; class OneSignalClient { @@ -23,6 +30,16 @@ class OneSignalClient */ public $requestAsync = false; + /** + * @var int + */ + public $maxRetries = 2; + + /** + * @var int + */ + public $retryDelay = 500; + /** * @var Callable */ @@ -57,11 +74,33 @@ public function __construct($appId, $restApiKey, $userAuthKey) $this->restApiKey = $restApiKey; $this->userAuthKey = $userAuthKey; - $this->client = new Client(); + $this->client = new Client([ + 'handler' => $this->createGuzzleHandler(), + ]); $this->headers = ['headers' => []]; $this->additionalParams = []; } + private function createGuzzleHandler() { + return tap(HandlerStack::create(new CurlHandler()), function (HandlerStack $handlerStack) { + $handlerStack->push(Middleware::retry(function ($retries, Psr7Request $request, Psr7Response $response = null, RequestException $exception = null) { + if ($retries >= $this->maxRetries) { + return false; + } + + if( $exception instanceof ConnectException ) { + return true; + } + + if ($response && $response->getStatusCode() > 500) { + return true; + } + + return false; + }), $this->retryDelay); + }); + } + public function testCredentials() { return "APP ID: ".$this->appId." REST: ".$this->restApiKey; } From 84ff0daecac235c4c13167acdd3e098281df7e49 Mon Sep 17 00:00:00 2001 From: Michel Bardelmeijer Date: Sat, 3 Mar 2018 19:16:50 +0100 Subject: [PATCH 09/61] Retry the exact '500' status code as well --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index ed7de75..af4bb7a 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -92,7 +92,7 @@ private function createGuzzleHandler() { return true; } - if ($response && $response->getStatusCode() > 500) { + if ($response && $response->getStatusCode() >= 500) { return true; } From 3a0c64b419cc283a35a05c1fbce832c25984b623 Mon Sep 17 00:00:00 2001 From: Michel Bardelmeijer Date: Sat, 3 Mar 2018 19:17:15 +0100 Subject: [PATCH 10/61] Code style --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index af4bb7a..e97bba6 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -88,7 +88,7 @@ private function createGuzzleHandler() { return false; } - if( $exception instanceof ConnectException ) { + if ($exception instanceof ConnectException) { return true; } From 8c6a5c806208fc29bc2643b63dfff06796012651 Mon Sep 17 00:00:00 2001 From: Mohammad Babaei Date: Wed, 7 Mar 2018 14:30:38 +0330 Subject: [PATCH 11/61] adding heading and subtitle --- src/OneSignalClient.php | 56 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index b787644..30f2022 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -88,7 +88,7 @@ public function setParam($key, $value) return $this; } - public function sendNotificationToUser($message, $userId, $url = null, $data = null, $buttons = null, $schedule = null) { + public function sendNotificationToUser($message, $userId, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { $contents = array( "en" => $message ); @@ -115,10 +115,22 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n $params['send_after'] = $schedule; } + if(isset($headings)){ + $params['headings'] = array( + "en" => $headings + ); + } + + if(isset($subtitle)){ + $params['subtitle'] = array( + "en" => $subtitle + ); + } + $this->sendNotificationCustom($params); } - public function sendNotificationUsingTags($message, $tags, $url = null, $data = null, $buttons = null, $schedule = null) { + public function sendNotificationUsingTags($message, $tags, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { $contents = array( "en" => $message ); @@ -145,10 +157,22 @@ public function sendNotificationUsingTags($message, $tags, $url = null, $data = $params['send_after'] = $schedule; } + if(isset($headings)){ + $params['headings'] = array( + "en" => $headings + ); + } + + if(isset($subtitle)){ + $params['subtitle'] = array( + "en" => $subtitle + ); + } + $this->sendNotificationCustom($params); } - public function sendNotificationToAll($message, $url = null, $data = null, $buttons = null, $schedule = null) { + public function sendNotificationToAll($message, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { $contents = array( "en" => $message ); @@ -175,10 +199,22 @@ public function sendNotificationToAll($message, $url = null, $data = null, $butt $params['send_after'] = $schedule; } + if(isset($headings)){ + $params['headings'] = array( + "en" => $headings + ); + } + + if(isset($subtitle)){ + $params['subtitle'] = array( + "en" => $subtitle + ); + } + $this->sendNotificationCustom($params); } - public function sendNotificationToSegment($message, $segment, $url = null, $data = null, $buttons = null, $schedule = null) { + public function sendNotificationToSegment($message, $segment, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { $contents = array( "en" => $message ); @@ -205,6 +241,18 @@ public function sendNotificationToSegment($message, $segment, $url = null, $data $params['send_after'] = $schedule; } + if(isset($headings)){ + $params['headings'] = array( + "en" => $headings + ); + } + + if(isset($subtitle)){ + $params['subtitle'] = array( + "en" => $subtitle + ); + } + $this->sendNotificationCustom($params); } From 1cd0a931d8dad2811e334322dde1446660d0c964 Mon Sep 17 00:00:00 2001 From: Zohaib Aslam Date: Tue, 12 Jun 2018 17:35:02 +0500 Subject: [PATCH 12/61] Added a method to delete notifications Notification can be deleted by passing the ID of it. Delete method is also added as it requires a DELETE HTTP method to cancel a notification --- src/OneSignalClient.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 30f2022..114d89e 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -256,6 +256,16 @@ public function sendNotificationToSegment($message, $segment, $url = null, $data $this->sendNotificationCustom($params); } + public function deleteNotification($notificationId, $appId = null) { + $this->requiresAuth(); + + if(!$appId) + $appId = $this->appId; + $notificationCancelNode = "/$notificationId?app_id=$this->appId"; + return $this->delete(self::ENDPOINT_NOTIFICATIONS . $notificationCancelNode); + + } + /** * Send a notification with custom parameters defined in * https://documentation.onesignal.com/reference#section-example-code-create-notification @@ -361,4 +371,12 @@ public function put($endPoint) { public function get($endPoint) { return $this->client->get(self::API_URL . $endPoint, $this->headers); } + + public function delete($endPoint) { + if($this->requestAsync === true) { + $promise = $this->client->deleteAsync(self::API_URL . $endPoint, $this->headers); + return (is_callable($this->requestCallback) ? $promise->then($this->requestCallback) : $promise); + } + return $this->client->delete(self::API_URL . $endPoint, $this->headers); + } } From 790b51ffdcd1635cefacef4f5c63650d02dfd483 Mon Sep 17 00:00:00 2001 From: loox Date: Thu, 5 Jul 2018 17:32:54 +0200 Subject: [PATCH 13/61] Adding support for getApp / getApps in OneSignalClient --- src/OneSignalClient.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 30f2022..953ea06 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -10,6 +10,7 @@ class OneSignalClient const ENDPOINT_NOTIFICATIONS = "/notifications"; const ENDPOINT_PLAYERS = "/players"; + const ENDPOINT_APPS = "/apps"; protected $client; protected $headers; @@ -298,6 +299,23 @@ public function getNotification($notification_id, $app_id = null) { return $this->get(self::ENDPOINT_NOTIFICATIONS . '/'.$notification_id . '?app_id='.$app_id); } + public function getApp($app_id = null) { + $this->requiresAuth(); + $this->usesJSON(); + + if(!$app_id) + $app_id = $this->appId; + + return $this->get(self::ENDPOINT_APPS . '/'.$app_id); + } + + public function getApps() { + $this->requiresAuth(); + $this->usesJSON(); + + return $this->get(self::ENDPOINT_APPS); + } + /** * Creates a user/player * From 6dcf4316dbf6393bd09cf1487ed7336d04177a24 Mon Sep 17 00:00:00 2001 From: loox Date: Thu, 5 Jul 2018 17:43:45 +0200 Subject: [PATCH 14/61] adding requiresUserAuth method --- src/OneSignalClient.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 953ea06..e4199b0 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -71,6 +71,10 @@ private function requiresAuth() { $this->headers['headers']['Authorization'] = 'Basic '.$this->restApiKey; } + private function requiresUserAuth() { + $this->headers['headers']['Authorization'] = 'Basic '.$this->userAuthKey; + } + private function usesJSON() { $this->headers['headers']['Content-Type'] = 'application/json'; } @@ -300,7 +304,7 @@ public function getNotification($notification_id, $app_id = null) { } public function getApp($app_id = null) { - $this->requiresAuth(); + $this->requiresUserAuth(); $this->usesJSON(); if(!$app_id) @@ -310,7 +314,7 @@ public function getApp($app_id = null) { } public function getApps() { - $this->requiresAuth(); + $this->requiresUserAuth(); $this->usesJSON(); return $this->get(self::ENDPOINT_APPS); From b3830e15aa6645ba1a52bf9d962feae9c8fe40a4 Mon Sep 17 00:00:00 2001 From: loox Date: Fri, 6 Jul 2018 11:46:00 +0200 Subject: [PATCH 15/61] Adding getNotifications method to OneSignalClient --- src/OneSignalClient.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index e4199b0..5899e23 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -303,6 +303,29 @@ public function getNotification($notification_id, $app_id = null) { return $this->get(self::ENDPOINT_NOTIFICATIONS . '/'.$notification_id . '?app_id='.$app_id); } + public function getNotifications($app_id = null, $limit = null, $offset = null) { + $this->requiresAuth(); + $this->usesJSON(); + + $endpoint = self::ENDPOINT_NOTIFICATIONS; + + if(!$app_id) { + $app_id = $this->appId; + } + + $endpoint.='?app_id='.$app_id; + + if($limit) { + $endpoint.="&limit=".$limit; + } + + if($offset) { + $endpoint.="&offset=".$$offset; + } + + return $this->get($endpoint); + } + public function getApp($app_id = null) { $this->requiresUserAuth(); $this->usesJSON(); From 2d051fa40e7b4251cc6e7179b4ec7d7728394110 Mon Sep 17 00:00:00 2001 From: loox Date: Tue, 10 Jul 2018 15:34:31 +0200 Subject: [PATCH 16/61] Adding CSV export --- src/OneSignalClient.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 5899e23..662f7ba 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -367,6 +367,16 @@ public function editPlayer(Array $parameters) { return $this->sendPlayer($parameters, 'PUT', self::ENDPOINT_PLAYERS . '/' . $parameters['id']); } + public function requestPlayersCSV($app_id = null, Array $parameters = null) { + $this->requiresAuth(); + $this->usesJSON(); + + $endpoint = self::ENDPOINT_PLAYERS."/csv_export?"; + $endpoint .= "app_id" . $app_id?$app_id:$this->appId; + + return $this->sendPlayer($parameters, 'POST', $endpoint); + } + /** * Create or update a by $method value * From 8a1be2734a413c151b4eea94c2aa294ed74cc892 Mon Sep 17 00:00:00 2001 From: Scarwolf Date: Mon, 24 Sep 2018 17:45:27 +0200 Subject: [PATCH 17/61] Add 5.5 AutoDiscover support --- README.md | 2 ++ composer.json | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 553a1ee..e97d323 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ composer require berkayk/onesignal-laravel Aftwards, run `composer update` from your command line. +**You only need to do the following if your Laravel version is below 5.5**: + Then, update `config/app.php` by adding an entry for the service provider. ```php diff --git a/composer.json b/composer.json index 8d8469a..04278f9 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,16 @@ "Berkayk\\OneSignal\\": "src/" } }, + "extra": { + "laravel": { + "providers": [ + "Berkayk\\OneSignal\\OneSignalServiceProvider" + ], + "aliases": { + "OneSignal": "Berkayk\\OneSignal\\OneSignalFacade" + } + } + }, "license": "MIT", "authors": [ { From 19783297de071e3ebef10b2ca5d6e1dac0574d4e Mon Sep 17 00:00:00 2001 From: Samundra Shrestha Date: Wed, 3 Oct 2018 00:40:38 +0700 Subject: [PATCH 18/61] fix the broken readme render --- README.md | 103 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 85 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e348a4f..7ff7005 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,11 @@ ## 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. +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. ## Installation @@ -14,7 +17,7 @@ First, you'll need to require the package with Composer: composer require berkayk/onesignal-laravel ``` -Aftwards, run `composer update` from your command line. +Afterwards, run `composer update` from your command line. **You only need to do the following if your Laravel version is below 5.5**: @@ -27,7 +30,6 @@ Then, update `config/app.php` by adding an entry for the service provider. ]; ``` - Then, register class alias by adding an entry in aliases section ```php @@ -45,9 +47,11 @@ php artisan vendor:publish --tag=config ``` to publish the default configuration file. -This will publish a configuration file named `onesignal.php` which includes your OneSignal authorization keys. +This will publish a configuration file named `onesignal.php` which includes +your OneSignal authorization keys. -> **Note:** If the previous command does not publish the config file successfully, please check the steps involving *providers* and *aliases* in the `config/app.php` file. +> **Note:** If the previous command does not publish the config file successfully, +> please check the steps involving *providers* and *aliases* in the `config/app.php` file. ## Configuration @@ -61,49 +65,112 @@ You need to fill in `onesignal.php` file that is found in your applications `con You can easily send a message to all registered users with the command - OneSignal::sendNotificationToAll("Some Message", $url = null, $data = null, $buttons = null, $schedule = null); +```php + OneSignal::sendNotificationToAll( + "Some Message", + $url = null, + $data = null, + $buttons = null, + $schedule = null + ); +``` -`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. +`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you +provide a `$url` parameter, users will be redirecting to that url. ### Sending a Notification based on Tags/Filters You can send a message based on a set of tags with the command -#####Example 1: - OneSignal::sendNotificationUsingTags("Some Message", array(["field" => "email", "relation" => "=", "value" => "someone@example.com"]), $url = null, $data = null, $buttons = null, $schedule = null); -#####Example 2: - OneSignal::sendNotificationUsingTags("Some Message", array(["field" => "session_count", "relation" => ">", "value" => '2']), $url = null, $data = null, $buttons = null, $schedule = null); + ##### Example 1: + +```php + OneSignal::sendNotificationUsingTags( + "Some Message", + array( + ["field" => "email", "relation" => "=", "value" => "email21@example.com"], + ["field" => "email", "relation" => "=", "value" => "email1@example.com"], + ... + ), + $url = null, + $data = null, + $buttons = null, + $schedule = null + ); +``` + + ##### Example 2: + +```php + OneSignal::sendNotificationUsingTags( + "Some Message", + array( + ["field" => "session_count", "relation" => ">", "value" => '2'], + ["field" => "first_session", "relation" => ">", "value" => '2000'], + ), + $url = null, + $data = null, + $buttons = null, + $schedule = null + ); +``` ### 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, $url = null, $data = null, $buttons = null, $schedule = null); +```php + OneSignal::sendNotificationToUser( + "Some Message", + $userId, + $url = null, + $data = null, + $buttons = null, + $schedule = null + ); +``` -`$userId` is the user's unique id where he/she is registered for notifications. Read https://documentation.onesignal.com/docs/web-push-tagging-guide for additional details. -`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. +`$userId` is the user's unique id where he/she is registered for notifications. +Read https://documentation.onesignal.com/docs/web-push-tagging-guide for additional details. +`$url` , `$data` , `$buttons` and `$schedule` 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, $url = null, $data = null, $buttons = null, $schedule = null); +```php + OneSignal::sendNotificationToSegment( + "Some Message", + $segment, + $url = null, + $data = null, + $buttons = null, + $schedule = null + ); +``` -`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. +`$url` , `$data` , `$buttons` and `$schedule` 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 +```php OneSignal::sendNotificationCustom($parameters); +``` - ### Sending a Custom Notification +### Sending a Custom Notification + ### Sending a async Custom Notification You can send a async custom message with +```php OneSignal::async()->sendNotificationCustom($parameters); +``` Please refer to https://documentation.onesignal.com/reference for all customizable parameters. From f33e27ee7c68c51d36e2664620d8211e73c5c8d1 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Tue, 23 Oct 2018 12:00:23 -0500 Subject: [PATCH 19/61] Alias the 'onesignal' service This will allow the Laravel container to autowire services which have a dependency to the `Berkayk\OneSignal\OneSignalClient` without requiring use of the facade, `app()` helper, or other types of service locator based code. --- src/OneSignalServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OneSignalServiceProvider.php b/src/OneSignalServiceProvider.php index 2b54867..962f756 100644 --- a/src/OneSignalServiceProvider.php +++ b/src/OneSignalServiceProvider.php @@ -40,11 +40,11 @@ public function register() return $client; }); + + $this->app->alias('onesignal', 'Berkayk\OneSignal\OneSignalClient'); } public function provides() { return ['onesignal']; } - - } From 5e25505d089c3bd675f2f18ccdef0d77daea1188 Mon Sep 17 00:00:00 2001 From: Ayaz Shakoor Date: Tue, 22 Jan 2019 20:07:16 +0500 Subject: [PATCH 20/61] Send notification by external user ids --- README.md | 21 +++++++++++++++++ src/OneSignalClient.php | 51 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/README.md b/README.md index 7ff7005..bde8741 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,27 @@ Read https://documentation.onesignal.com/docs/web-push-tagging-guide for additio a `$url` parameter, users will be redirecting to that url. + +### Sending a Notification To A Specific external User (custom user id added by user) + +After storing a user's tokens in a table, you can simply send a message with + +```php + OneSignal::sendNotificationToExternalUser( + "Some Message", + $userId, + $url = null, + $data = null, + $buttons = null, + $schedule = null + ); +``` + +`$userId` is the user's unique external id (custom id) added by the user where he/she is registered for notifications. +Read https://documentation.onesignal.com/docs/web-push-tagging-guide for additional details. +`$url` , `$data` , `$buttons` and `$schedule` 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 diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index d8e1e7f..4d600c6 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -174,6 +174,57 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n $this->sendNotificationCustom($params); } + /** + * @param $message + * @param $userId + * @param null $url + * @param null $data + * @param null $buttons + * @param null $schedule + * @param null $headings + * @param null $subtitle + */ + public function sendNotificationToExternalUser($message, $userId, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { + $contents = array( + "en" => $message + ); + + $params = array( + 'app_id' => $this->appId, + 'contents' => $contents, + 'include_external_user_ids' => is_array($userId) ? $userId : array($userId) + ); + + if (isset($url)) { + $params['url'] = $url; + } + + if (isset($data)) { + $params['data'] = $data; + } + + if (isset($buttons)) { + $params['buttons'] = $buttons; + } + + if(isset($schedule)){ + $params['send_after'] = $schedule; + } + + if(isset($headings)){ + $params['headings'] = array( + "en" => $headings + ); + } + + if(isset($subtitle)){ + $params['subtitle'] = array( + "en" => $subtitle + ); + } + + $this->sendNotificationCustom($params); + } public function sendNotificationUsingTags($message, $tags, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { $contents = array( "en" => $message From 6837be55fe6b4b561b30082c270274cd2c0a4d93 Mon Sep 17 00:00:00 2001 From: Matheus Naldi Date: Wed, 30 Jan 2019 16:34:07 -0200 Subject: [PATCH 21/61] Fixed verification to call method configure --- src/OneSignalServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalServiceProvider.php b/src/OneSignalServiceProvider.php index 962f756..51ed967 100644 --- a/src/OneSignalServiceProvider.php +++ b/src/OneSignalServiceProvider.php @@ -18,7 +18,7 @@ public function boot() $this->publishes([$configPath => config_path('onesignal.php')], 'config'); $this->mergeConfigFrom($configPath, 'onesignal'); - if ( class_exists('Laravel\Lumen\Application') ) { + if ($this->app instanceof Laravel\Lumen\Application::class) { $this->app->configure('onesignal'); } } From 44dfa1dadac3a3b5092639c28f62e3a5bf47001a Mon Sep 17 00:00:00 2001 From: Matheus Naldi Date: Wed, 30 Jan 2019 16:38:21 -0200 Subject: [PATCH 22/61] Removed incorrect method called --- src/OneSignalServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalServiceProvider.php b/src/OneSignalServiceProvider.php index 51ed967..828219a 100644 --- a/src/OneSignalServiceProvider.php +++ b/src/OneSignalServiceProvider.php @@ -18,7 +18,7 @@ public function boot() $this->publishes([$configPath => config_path('onesignal.php')], 'config'); $this->mergeConfigFrom($configPath, 'onesignal'); - if ($this->app instanceof Laravel\Lumen\Application::class) { + if ($this->app instanceof Laravel\Lumen\Application) { $this->app->configure('onesignal'); } } From 858c28c1f5b57dd349bd0f3851da7af40fdd3cf2 Mon Sep 17 00:00:00 2001 From: Berkay Kaya Date: Mon, 19 Aug 2019 00:45:50 +0300 Subject: [PATCH 23/61] Fixed README. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bde8741..d18f998 100644 --- a/README.md +++ b/README.md @@ -89,8 +89,8 @@ You can send a message based on a set of tags with the command OneSignal::sendNotificationUsingTags( "Some Message", array( - ["field" => "email", "relation" => "=", "value" => "email21@example.com"], - ["field" => "email", "relation" => "=", "value" => "email1@example.com"], + ["key" => "email", "relation" => "=", "value" => "email21@example.com"], + ["key" => "email", "relation" => "=", "value" => "email1@example.com"], ... ), $url = null, @@ -106,8 +106,8 @@ You can send a message based on a set of tags with the command OneSignal::sendNotificationUsingTags( "Some Message", array( - ["field" => "session_count", "relation" => ">", "value" => '2'], - ["field" => "first_session", "relation" => ">", "value" => '2000'], + ["key" => "session_count", "relation" => ">", "value" => '2'], + ["key" => "first_session", "relation" => ">", "value" => '2000'], ), $url = null, $data = null, From c04c22911b2cd639e789a62d0dd1e94b050fd7df Mon Sep 17 00:00:00 2001 From: Mark Beech Date: Wed, 28 Aug 2019 21:31:47 +0100 Subject: [PATCH 24/61] Allow Laravel 6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 04278f9..67bc570 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "php": ">=5.4.0", "guzzlehttp/guzzle": "^6.2", - "illuminate/support": "4.*|5.*", + "illuminate/support": "4.*|5.*|6.*", "symfony/psr-http-message-bridge": "1.*" }, "require-dev": { From 69158ee85f046ddb6bad850b1ff4176b5678ac8c Mon Sep 17 00:00:00 2001 From: Berkay Kaya Date: Wed, 15 Jan 2020 13:43:33 +0300 Subject: [PATCH 25/61] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d18f998..0fab4a2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# OneSignal Push Notifications for Laravel 5 +# OneSignal Push Notifications for Laravel 5+ ## Introduction From 5d0e986671ce40a25fcf978f32ec5d1916653a2f Mon Sep 17 00:00:00 2001 From: Berkay Kaya Date: Wed, 15 Jan 2020 13:47:48 +0300 Subject: [PATCH 26/61] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fab4a2..9d4e1dc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ -# OneSignal Push Notifications for Laravel 5+ +# OneSignal Push Notifications for Laravel 5+ +[![Latest Stable Version](https://poser.pugx.org/berkayk/onesignal-laravel/v/stable)](https://packagist.org/packages/berkayk/onesignal-laravel) +[![Total Downloads](https://poser.pugx.org/berkayk/onesignal-laravel/downloads)](https://packagist.org/packages/berkayk/onesignal-laravel) +[![License](https://poser.pugx.org/berkayk/onesignal-laravel/license)](https://packagist.org/packages/berkayk/onesignal-laravel) + + ## Introduction From 2fb36f9c0e07796be5a80fbc1bc5babe409966b5 Mon Sep 17 00:00:00 2001 From: Berkay Kaya Date: Mon, 20 Jan 2020 12:59:22 +0300 Subject: [PATCH 27/61] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 9d4e1dc..b358c25 100644 --- a/README.md +++ b/README.md @@ -188,8 +188,6 @@ You can send a custom message with ```php OneSignal::sendNotificationCustom($parameters); ``` - -### Sending a Custom Notification ### Sending a async Custom Notification You can send a async custom message with From 47f24ba02e824177e4910083fb150f313f4c39dc Mon Sep 17 00:00:00 2001 From: Aykut Farsak Date: Thu, 5 Mar 2020 15:01:33 +0300 Subject: [PATCH 28/61] Add Laravel 7 support --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 67bc570..e507666 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "php": ">=5.4.0", "guzzlehttp/guzzle": "^6.2", - "illuminate/support": "4.*|5.*|6.*", + "illuminate/support": "4.*|5.*|6.*|7.*", "symfony/psr-http-message-bridge": "1.*" }, "require-dev": { From 6120721f5cf215a018a9b1fe4bfc093a2953f212 Mon Sep 17 00:00:00 2001 From: Berkay Kaya Date: Fri, 6 Mar 2020 12:04:18 +0300 Subject: [PATCH 29/61] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b358c25..1f0f16d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# OneSignal Push Notifications for Laravel 5+ +# OneSignal Push Notifications for Laravel [![Latest Stable Version](https://poser.pugx.org/berkayk/onesignal-laravel/v/stable)](https://packagist.org/packages/berkayk/onesignal-laravel) [![Total Downloads](https://poser.pugx.org/berkayk/onesignal-laravel/downloads)](https://packagist.org/packages/berkayk/onesignal-laravel) [![License](https://poser.pugx.org/berkayk/onesignal-laravel/license)](https://packagist.org/packages/berkayk/onesignal-laravel) From 3a6c0d7ab98d1c7e72ca6e37324c5c36bc37a144 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Santos Date: Sat, 7 Mar 2020 01:08:40 -0300 Subject: [PATCH 30/61] Remove broken links the link https://documentation.onesignal.com/docs/web-push-tagging-guide is not valid, it was replaced by https://documentation.onesignal.com/docs/add-user-data-tags --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1f0f16d..b7ada5d 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ After storing a user's tokens in a table, you can simply send a message with ``` `$userId` is the user's unique id where he/she is registered for notifications. -Read https://documentation.onesignal.com/docs/web-push-tagging-guide for additional details. +Read https://documentation.onesignal.com/docs/add-user-data-tags for additional details. `$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. @@ -159,7 +159,7 @@ After storing a user's tokens in a table, you can simply send a message with ``` `$userId` is the user's unique external id (custom id) added by the user where he/she is registered for notifications. -Read https://documentation.onesignal.com/docs/web-push-tagging-guide for additional details. +Read https://documentation.onesignal.com/docs/add-user-data-tags for additional details. `$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url. From 430eeaef4e2ee92d31978e25ca7349bdf4edc2a6 Mon Sep 17 00:00:00 2001 From: Pedro Santiago Date: Mon, 30 Mar 2020 22:19:24 -0300 Subject: [PATCH 31/61] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e507666..20c19d8 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=5.4.0", "guzzlehttp/guzzle": "^6.2", "illuminate/support": "4.*|5.*|6.*|7.*", - "symfony/psr-http-message-bridge": "1.*" + "symfony/psr-http-message-bridge": "1.*|2.*" }, "require-dev": { "vlucas/phpdotenv": "^2.2" From 2ddb009ed19127f5f03870f6501a4b42037a8489 Mon Sep 17 00:00:00 2001 From: Berkay Kaya Date: Wed, 1 Jul 2020 16:41:10 +0300 Subject: [PATCH 32/61] Fixed README. --- README.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d18f998..8a95d37 100644 --- a/README.md +++ b/README.md @@ -184,8 +184,6 @@ You can send a custom message with OneSignal::sendNotificationCustom($parameters); ``` -### Sending a Custom Notification - ### Sending a async Custom Notification You can send a async custom message with @@ -195,3 +193,83 @@ You can send a async custom message with Please refer to https://documentation.onesignal.com/reference for all customizable parameters. +## Examples + +Some people found examples confusing, so I am going to provide some detailed examples that I use in my applications. These examples will probably guide you on customizing your notifications. For custom parameters, please refer to https://documentation.onesignal.com/reference/create-notification. + +### 1) Sending a message to a segment with custom icon and custom icon color + +You need to customize `android_accent_color` and `small_icon` values before sending your notifications. These are `parameters` that you need to specify while sending your notifications. + +```` +use OneSignal; + +$params = []; +$params['android_accent_color'] = 'FFCCAA72'; // argb color value +$params['small_icon'] = 'ic_stat_distriqt_default'; // icon res name specified in your app + +$message = "Test message to send"; +$segment = "Testers"; +OneSignal::addParams($params)->sendNotificationToSegment( + $message, + $segment + ); + +// or to all users +OneSignal::addParams($params)->sendNotificationToAll($message); + +```` + +### 2. Sending a message with high priority + +This time, we will specify parameters one by one. + +```` +use OneSignal; + +$message = "Test message to send"; +$segment = "Testers"; +OneSignal::setParam('priority', 10)->sendNotificationToSegment( + $message, + $segment + ); + +// You can chain as many parameters as you wish + +OneSignal::setParam('priority', 10)->setParam('small_icon', 'ic_stat_onesignal_default')->setParam('led_color', 'FFAACCAA')->sendNotificationToAll($message); + +```` + +### 3. Sending a message with custom heading and subtitle + +```` +use OneSignal; + +OneSignal::sendNotificationToSegment( + "Test message with custom heading and subtitle", + "Testers", + null, null, null, null, + "Custom Heading", + "Custom subtitle" + ); +```` + +### 4. Sending a delayed message to a specific user with many custom parameters + +```` +use OneSignal; + +$userId = "3232331-1722-4fee-943d-23123asda123"; +$params = []; +$params['include_player_ids'] = [$userId]; +$contents = [ + "en" => "Some English Message", + "tr" => "Some Turkish Message" +]; +$params['contents'] = $contents; +$params['delayed_option'] = "timezone"; // Will deliver on user's timezone +$params['delivery_time_of_day'] = "2:30PM"; // Delivery time + +OneSignal::sendNotificationCustom($params); + +```` From f3bf8fd0c3cca1a8f1d12010be40fab07eb2c458 Mon Sep 17 00:00:00 2001 From: Berkay Kaya Date: Wed, 1 Jul 2020 17:03:53 +0300 Subject: [PATCH 33/61] Fixed README. --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 925502d..6ec122e 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ Some people found examples confusing, so I am going to provide some detailed exa You need to customize `android_accent_color` and `small_icon` values before sending your notifications. These are `parameters` that you need to specify while sending your notifications. -```` +```php use OneSignal; $params = []; @@ -224,13 +224,13 @@ OneSignal::addParams($params)->sendNotificationToSegment( // or to all users OneSignal::addParams($params)->sendNotificationToAll($message); -```` +``` ### 2. Sending a message with high priority This time, we will specify parameters one by one. -```` +```php use OneSignal; $message = "Test message to send"; @@ -244,11 +244,11 @@ OneSignal::setParam('priority', 10)->sendNotificationToSegment( OneSignal::setParam('priority', 10)->setParam('small_icon', 'ic_stat_onesignal_default')->setParam('led_color', 'FFAACCAA')->sendNotificationToAll($message); -```` +``` ### 3. Sending a message with custom heading and subtitle -```` +```php use OneSignal; OneSignal::sendNotificationToSegment( @@ -258,11 +258,11 @@ OneSignal::sendNotificationToSegment( "Custom Heading", "Custom subtitle" ); -```` +``` ### 4. Sending a delayed message to a specific user with many custom parameters -```` +```php use OneSignal; $userId = "3232331-1722-4fee-943d-23123asda123"; @@ -278,4 +278,4 @@ $params['delivery_time_of_day'] = "2:30PM"; // Delivery time OneSignal::sendNotificationCustom($params); -```` +``` From 97eb3186ebfcdd6aa1daa0618b2f7a6acce3e678 Mon Sep 17 00:00:00 2001 From: ExpDev07 Date: Tue, 8 Sep 2020 20:11:19 +0200 Subject: [PATCH 34/61] add laravel 8 compatability by upgrading guzzle to ^7.0.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 20c19d8..c79b5c5 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "type": "library", "require": { "php": ">=5.4.0", - "guzzlehttp/guzzle": "^6.2", + "guzzlehttp/guzzle": "^7.0.1", "illuminate/support": "4.*|5.*|6.*|7.*", "symfony/psr-http-message-bridge": "1.*|2.*" }, From e97fc914d8c15e852c350b6f0adff6652cd441ca Mon Sep 17 00:00:00 2001 From: ExpDev Date: Wed, 9 Sep 2020 01:25:18 +0200 Subject: [PATCH 35/61] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c79b5c5..a9bede5 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,8 @@ "type": "library", "require": { "php": ">=5.4.0", - "guzzlehttp/guzzle": "^7.0.1", - "illuminate/support": "4.*|5.*|6.*|7.*", + "guzzlehttp/guzzle": "^6.2|^7.0.1", + "illuminate/support": "~5.5||~6.0||~7.0||~8.0", "symfony/psr-http-message-bridge": "1.*|2.*" }, "require-dev": { From 01ef52f1238acc728d1c7515faf504e433651dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Meirinaldo=20J=C3=BAnior?= Date: Wed, 9 Sep 2020 13:56:56 -0300 Subject: [PATCH 36/61] Update README.md fixing missing parameters. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6ec122e..f581f63 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,8 @@ You can send a message based on a set of tags with the command OneSignal::sendNotificationUsingTags( "Some Message", array( - ["key" => "email", "relation" => "=", "value" => "email21@example.com"], - ["key" => "email", "relation" => "=", "value" => "email1@example.com"], + ["field" => "tag", "key" => "email", "relation" => "=", "value" => "email21@example.com"], + ["field" => "tag", "key" => "email", "relation" => "=", "value" => "email1@example.com"], ... ), $url = null, @@ -111,8 +111,8 @@ You can send a message based on a set of tags with the command OneSignal::sendNotificationUsingTags( "Some Message", array( - ["key" => "session_count", "relation" => ">", "value" => '2'], - ["key" => "first_session", "relation" => ">", "value" => '2000'], + ["field" => "tag", "key" => "session_count", "relation" => ">", "value" => '2'], + ["field" => "tag", "key" => "first_session", "relation" => ">", "value" => '2000'], ), $url = null, $data = null, From 4d9fd6c3d3b7a544bf648596bf460abbf17b7202 Mon Sep 17 00:00:00 2001 From: Berkay Kaya Date: Sat, 12 Sep 2020 09:01:34 +0300 Subject: [PATCH 37/61] Fixed Laravel 8 support. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a9bede5..9c2fdde 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "php": ">=5.4.0", "guzzlehttp/guzzle": "^6.2|^7.0.1", - "illuminate/support": "~5.5||~6.0||~7.0||~8.0", + "illuminate/support": "~5.5|~6.0|~7.0|~8.0", "symfony/psr-http-message-bridge": "1.*|2.*" }, "require-dev": { From fddd618517fba463dc0f1c83b6a63e08b95f6679 Mon Sep 17 00:00:00 2001 From: Stephen Jude <31182887+stephenjude@users.noreply.github.com> Date: Sat, 19 Sep 2020 22:08:06 +0100 Subject: [PATCH 38/61] Update config publish command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f581f63..b1eb922 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Then, register class alias by adding an entry in aliases section Finally, from the command line again, run ``` -php artisan vendor:publish --tag=config +php artisan vendor:publish --provider="Berkayk\OneSignal\OneSignalServiceProvider" --tag="config" ``` to publish the default configuration file. From aa6f6fb1884b28e98052049668de2f40949bf912 Mon Sep 17 00:00:00 2001 From: Stephen Jude <31182887+stephenjude@users.noreply.github.com> Date: Sat, 19 Sep 2020 22:21:48 +0100 Subject: [PATCH 39/61] use dotenv for onesignal keys and id --- config/onesignal.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/onesignal.php b/config/onesignal.php index 8eb3448..1cf7d92 100644 --- a/config/onesignal.php +++ b/config/onesignal.php @@ -8,7 +8,7 @@ | | */ - 'app_id' => 'YOUR-APP-ID-HERE', + 'app_id' => env('ONESIGNAL_APP_ID'), /* |-------------------------------------------------------------------------- @@ -18,6 +18,6 @@ | | */ - 'rest_api_key' => 'YOUR-REST-API-KEY-HERE', - 'user_auth_key' => 'YOUR-USER-AUTH-KEY' -); \ No newline at end of file + 'rest_api_key' => env('ONESIGNAL_REST_API_KEY'), + 'user_auth_key' => env('USER_AUTH_KEY') +); From bce5e97fdfe13d3c317794414606285be8cdd55c Mon Sep 17 00:00:00 2001 From: Stephen Jude <31182887+stephenjude@users.noreply.github.com> Date: Sat, 19 Sep 2020 22:28:46 +0100 Subject: [PATCH 40/61] update package configuration guide on the readme --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f581f63..faa8c69 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,12 @@ your OneSignal authorization keys. ## Configuration -You need to fill in `onesignal.php` file that is found in your applications `config` directory. -`app_id` is your *OneSignal App ID* and `rest_api_key` is your *REST API Key*. +You need to fill in your OneSignal *App ID* and *REST API Key* inside your +.env file like this: +``` +ONESIGNAL_APP_ID=xxxxxxxxxxxxxxxxxxxx +ONESIGNAL_REST_API_KEY=xxxxxxxxxxxxxxxxxx +``` ## Usage From afcef12052ccaf83e9a7dc649c6f4bf34c64bac6 Mon Sep 17 00:00:00 2001 From: tomaszthreadable Date: Tue, 10 Aug 2021 13:00:52 +0100 Subject: [PATCH 41/61] add timeout option to Guzzle Client --- config/onesignal.php | 12 +++++++++++- src/OneSignalClient.php | 9 ++++++++- src/OneSignalServiceProvider.php | 4 +--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/config/onesignal.php b/config/onesignal.php index 1cf7d92..b1c3b9b 100644 --- a/config/onesignal.php +++ b/config/onesignal.php @@ -19,5 +19,15 @@ | */ 'rest_api_key' => env('ONESIGNAL_REST_API_KEY'), - 'user_auth_key' => env('USER_AUTH_KEY') + 'user_auth_key' => env('USER_AUTH_KEY'), + + /* + |-------------------------------------------------------------------------- + | Guzzle Timeout + |-------------------------------------------------------------------------- + | + | + | + */ + 'guzzle_client_timeout' => env('ONESIGNAL_GUZZLE_CLIENT_TIMEOUT', 0), ); diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 4d600c6..d4fadbe 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -69,7 +69,13 @@ public function callback(Callable $requestCallback) return $this; } - public function __construct($appId, $restApiKey, $userAuthKey) + /** + * @param $appId + * @param $restApiKey + * @param $userAuthKey + * @param int $guzzleClientTimeout + */ + public function __construct($appId, $restApiKey, $userAuthKey, $guzzleClientTimeout = 0) { $this->appId = $appId; $this->restApiKey = $restApiKey; @@ -77,6 +83,7 @@ public function __construct($appId, $restApiKey, $userAuthKey) $this->client = new Client([ 'handler' => $this->createGuzzleHandler(), + 'timeout' => $guzzleClientTimeout, ]); $this->headers = ['headers' => []]; $this->additionalParams = []; diff --git a/src/OneSignalServiceProvider.php b/src/OneSignalServiceProvider.php index 828219a..ee4f072 100644 --- a/src/OneSignalServiceProvider.php +++ b/src/OneSignalServiceProvider.php @@ -36,9 +36,7 @@ public function register() $config = $app['config']['onesignal'] ?: $app['config']['onesignal::config']; } - $client = new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key']); - - return $client; + return new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key'] , $config['guzzle_client_timeout']); }); $this->app->alias('onesignal', 'Berkayk\OneSignal\OneSignalClient'); From cc7c14264d8f63cdd17cee0877d26344614bbaaf Mon Sep 17 00:00:00 2001 From: tomaszthreadable Date: Tue, 10 Aug 2021 13:11:23 +0100 Subject: [PATCH 42/61] update docs --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 5bd8302..6c2a05a 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,11 @@ You need to fill in your OneSignal *App ID* and *REST API Key* inside your ONESIGNAL_APP_ID=xxxxxxxxxxxxxxxxxxxx ONESIGNAL_REST_API_KEY=xxxxxxxxxxxxxxxxxx ``` +You can control timeout of the Guzzle client used by OnesignalClient by adding following into your .env file +``` +ONESIGNAL_GUZZLE_CLIENT_TIMEOUT=integer_value +``` +This param is useful when you are planning to send push notification via [Laravel queues](https://divinglaravel.com/always-set-a-timeout-for-guzzle-requests-inside-a-queued-job) ## Usage From b88d0ad88b8906e1fb121e1323f61797e350ec25 Mon Sep 17 00:00:00 2001 From: tomaszthreadable Date: Tue, 10 Aug 2021 13:12:26 +0100 Subject: [PATCH 43/61] update docs - fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c2a05a..9d53b49 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ You need to fill in your OneSignal *App ID* and *REST API Key* inside your ONESIGNAL_APP_ID=xxxxxxxxxxxxxxxxxxxx ONESIGNAL_REST_API_KEY=xxxxxxxxxxxxxxxxxx ``` -You can control timeout of the Guzzle client used by OnesignalClient by adding following into your .env file +You can control timeout of the Guzzle client used by OneSignalClient by adding following into your .env file ``` ONESIGNAL_GUZZLE_CLIENT_TIMEOUT=integer_value ``` From db7bbd2c5f61436573693d1a67be07b61b90b965 Mon Sep 17 00:00:00 2001 From: Samuel HASSID Date: Thu, 24 Feb 2022 15:38:01 +0100 Subject: [PATCH 44/61] Update OneSignalClient.php Fix #155 --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 4d600c6..f24646c 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -382,7 +382,7 @@ public function sendNotificationCustom($parameters = []){ // Make sure to use included_segments if (empty($parameters['included_segments']) && empty($parameters['include_player_ids'])) { - $parameters['included_segments'] = ['all']; + $parameters['included_segments'] = ['All']; } $parameters = array_merge($parameters, $this->additionalParams); From 20c8ac1c643bb1d8c84630e167b85c7a8d79043c Mon Sep 17 00:00:00 2001 From: philipnjuguna66 Date: Fri, 11 Mar 2022 09:40:26 +0300 Subject: [PATCH 45/61] Update composer.json support for laravel 9 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 9c2fdde..1c438b8 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,8 @@ "type": "library", "require": { "php": ">=5.4.0", - "guzzlehttp/guzzle": "^6.2|^7.0.1", - "illuminate/support": "~5.5|~6.0|~7.0|~8.0", + "guzzlehttp/guzzle": "^6.2|^7.*", + "illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0", "symfony/psr-http-message-bridge": "1.*|2.*" }, "require-dev": { From 8c99fbdc591aa39194433a519683c32698f840fd Mon Sep 17 00:00:00 2001 From: philipnjuguna66 Date: Fri, 11 Mar 2022 09:51:55 +0300 Subject: [PATCH 46/61] update gazzle htp --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1c438b8..bd3264d 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "type": "library", "require": { "php": ">=5.4.0", - "guzzlehttp/guzzle": "^6.2|^7.*", + "guzzlehttp/guzzle": "^6.2|^7.4.1", "illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0", "symfony/psr-http-message-bridge": "1.*|2.*" }, From e9d84e26781fd87ca4ec417029759f5620e313be Mon Sep 17 00:00:00 2001 From: Samuel Cecilio Date: Tue, 22 Mar 2022 21:12:40 -0300 Subject: [PATCH 47/61] fix: ignore segments if include external user ids --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index f24646c..6df4d75 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -381,7 +381,7 @@ public function sendNotificationCustom($parameters = []){ } // Make sure to use included_segments - if (empty($parameters['included_segments']) && empty($parameters['include_player_ids'])) { + if (empty($parameters['included_segments']) && empty($parameters['include_player_ids']) && empty('include_external_user_ids')) { $parameters['included_segments'] = ['All']; } From 13a43997babc701558c6d35b14142b3ecdcd730c Mon Sep 17 00:00:00 2001 From: Samuel HASSID Date: Mon, 25 Apr 2022 16:26:38 +0200 Subject: [PATCH 48/61] Fix array index access --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 1a18adf..a9bae1a 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -388,7 +388,7 @@ public function sendNotificationCustom($parameters = []){ } // Make sure to use included_segments - if (empty($parameters['included_segments']) && empty($parameters['include_player_ids']) && empty('include_external_user_ids')) { + if (empty($parameters['included_segments']) && empty($parameters['include_player_ids']) && empty($parameters['include_external_user_ids'])) { $parameters['included_segments'] = ['All']; } From 241ce8885b72a63ec972789cbbcbb23fc557f08b Mon Sep 17 00:00:00 2001 From: Shift Date: Tue, 31 Jan 2023 19:48:26 +0000 Subject: [PATCH 49/61] Bump dependencies for Laravel 10 --- composer.json | 88 +++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index bd3264d..d047daa 100644 --- a/composer.json +++ b/composer.json @@ -1,44 +1,50 @@ { - "name": "berkayk/onesignal-laravel", - "description": "OneSignal Push Wrapper Laravel", - "keywords": ["onesignal", "webpush", "push", "laravel", "laravel 5"], - "type": "library", - "require": { - "php": ">=5.4.0", - "guzzlehttp/guzzle": "^6.2|^7.4.1", - "illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0", - "symfony/psr-http-message-bridge": "1.*|2.*" - }, - "require-dev": { - "vlucas/phpdotenv": "^2.2" - }, - "autoload": { - "psr-4": { - "Berkayk\\OneSignal\\": "src/" - } - }, - "extra": { - "laravel": { - "providers": [ - "Berkayk\\OneSignal\\OneSignalServiceProvider" - ], - "aliases": { - "OneSignal": "Berkayk\\OneSignal\\OneSignalFacade" - } - } - }, - "license": "MIT", - "authors": [ - { - "name": "Berkay Kaya", - "email": "berkayk@gmail.com", - "homepage": "http://berkaykaya.com" + "name": "berkayk/onesignal-laravel", + "description": "OneSignal Push Wrapper Laravel", + "keywords": [ + "onesignal", + "webpush", + "push", + "laravel", + "laravel 5" + ], + "type": "library", + "require": { + "php": ">=5.4.0", + "guzzlehttp/guzzle": "^6.2|^7.4.1|^7.2", + "illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0|^10.0", + "symfony/psr-http-message-bridge": "1.*|2.*" }, - { - "name": "Maykonn Welington Candido", - "email": "maykonn@outlook.com" - } - ], - "minimum-stability": "dev", - "prefer-stable": true + "require-dev": { + "vlucas/phpdotenv": "^2.2|^5.5" + }, + "autoload": { + "psr-4": { + "Berkayk\\OneSignal\\": "src/" + } + }, + "extra": { + "laravel": { + "providers": [ + "Berkayk\\OneSignal\\OneSignalServiceProvider" + ], + "aliases": { + "OneSignal": "Berkayk\\OneSignal\\OneSignalFacade" + } + } + }, + "license": "MIT", + "authors": [ + { + "name": "Berkay Kaya", + "email": "berkayk@gmail.com", + "homepage": "http://berkaykaya.com" + }, + { + "name": "Maykonn Welington Candido", + "email": "maykonn@outlook.com" + } + ], + "minimum-stability": "dev", + "prefer-stable": true } From 95322bdcb015c96db24914f337bd4be20abe0455 Mon Sep 17 00:00:00 2001 From: Michel Bardelmeijer Date: Mon, 17 Jul 2023 19:23:37 +0200 Subject: [PATCH 50/61] Add `ConnectException` as a valid type in retry middleware --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 1a18adf..acdf8f1 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -91,7 +91,7 @@ public function __construct($appId, $restApiKey, $userAuthKey, $guzzleClientTime private function createGuzzleHandler() { return tap(HandlerStack::create(new CurlHandler()), function (HandlerStack $handlerStack) { - $handlerStack->push(Middleware::retry(function ($retries, Psr7Request $request, Psr7Response $response = null, RequestException $exception = null) { + $handlerStack->push(Middleware::retry(function ($retries, Psr7Request $request, Psr7Response $response = null, RequestException|ConnectException $exception = null) { if ($retries >= $this->maxRetries) { return false; } From 3d46a5ee55d7a4d234dbf0a5473fd7c1cc159ab3 Mon Sep 17 00:00:00 2001 From: Lazar Dudic Date: Thu, 28 Sep 2023 15:46:33 +0200 Subject: [PATCH 51/61] Fix sendNotificationCustom $parameters['include_external_user_ids'] is not used --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 1a18adf..a9bae1a 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -388,7 +388,7 @@ public function sendNotificationCustom($parameters = []){ } // Make sure to use included_segments - if (empty($parameters['included_segments']) && empty($parameters['include_player_ids']) && empty('include_external_user_ids')) { + if (empty($parameters['included_segments']) && empty($parameters['include_player_ids']) && empty($parameters['include_external_user_ids'])) { $parameters['included_segments'] = ['All']; } From 5b8d27538ae197c5989acff6fc9d6774b1926b35 Mon Sep 17 00:00:00 2001 From: Dela Akakpo Date: Sun, 11 Feb 2024 06:41:57 +0000 Subject: [PATCH 52/61] Update README.md Corrects some grammatical errors --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9d53b49..0d1aee7 100644 --- a/README.md +++ b/README.md @@ -89,8 +89,8 @@ You can easily send a message to all registered users with the command ); ``` -`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you -provide a `$url` parameter, users will be redirecting to that url. +`$url` , `$data` , `$buttons` and `$schedule` fields are optional. If you +provide a `$url` parameter, users will be redirected to that url. ### Sending a Notification based on Tags/Filters @@ -132,7 +132,7 @@ You can send a message based on a set of tags with the command ### Sending a Notification To A Specific User -After storing a user's tokens in a table, you can simply send a message with +After storing a user's token in a table, you can simply send a message with ```php OneSignal::sendNotificationToUser( @@ -147,14 +147,14 @@ After storing a user's tokens in a table, you can simply send a message with `$userId` is the user's unique id where he/she is registered for notifications. Read https://documentation.onesignal.com/docs/add-user-data-tags for additional details. -`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide -a `$url` parameter, users will be redirecting to that url. +`$url` , `$data` , `$buttons` and `$schedule` fields are optional. If you provide +a `$url` parameter, users will be redirected to that url. ### Sending a Notification To A Specific external User (custom user id added by user) -After storing a user's tokens in a table, you can simply send a message with +After storing a user's token in a table, you can simply send a message with ```php OneSignal::sendNotificationToExternalUser( @@ -170,7 +170,7 @@ After storing a user's tokens in a table, you can simply send a message with `$userId` is the user's unique external id (custom id) added by the user where he/she is registered for notifications. Read https://documentation.onesignal.com/docs/add-user-data-tags for additional details. `$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide -a `$url` parameter, users will be redirecting to that url. +a `$url` parameter, users will be redirected to that url. ### Sending a Notification To Segment @@ -187,8 +187,8 @@ You can simply send a notification to a specific segment with ); ``` -`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you -provide a `$url` parameter, users will be redirecting to that url. +`$url` , `$data` , `$buttons` and `$schedule` fields are optional. If you +provide a `$url` parameter, users will be redirected to that url. ### Sending a Custom Notification @@ -237,7 +237,7 @@ OneSignal::addParams($params)->sendNotificationToAll($message); ### 2. Sending a message with high priority -This time, we will specify parameters one by one. +This time, we will specify parameters one after the other. ```php use OneSignal; From 9fe6522aa765a1b4afcb4844826fa5dbb2796f3a Mon Sep 17 00:00:00 2001 From: Shift Date: Sat, 2 Mar 2024 00:46:38 +0000 Subject: [PATCH 53/61] Bump dependencies for Laravel 11 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d047daa..68531de 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,8 @@ "require": { "php": ">=5.4.0", "guzzlehttp/guzzle": "^6.2|^7.4.1|^7.2", - "illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0|^10.0", - "symfony/psr-http-message-bridge": "1.*|2.*" + "illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0|^10.0|^11.0", + "symfony/psr-http-message-bridge": "1.*|2.*|^7.0" }, "require-dev": { "vlucas/phpdotenv": "^2.2|^5.5" From 224c5122849c853831307f5d98ae8d35964e89f2 Mon Sep 17 00:00:00 2001 From: Diogo Coutinho Date: Wed, 17 Apr 2024 11:52:01 -0300 Subject: [PATCH 54/61] Removing a double "$" in a offset variable --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index a9bae1a..ce48966 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -427,7 +427,7 @@ public function getNotifications($app_id = null, $limit = null, $offset = null) } if($offset) { - $endpoint.="&offset=".$$offset; + $endpoint.="&offset=".$offset; } return $this->get($endpoint); From f345efab387bbf0dcda3f89e61eeaa3a612bb6c4 Mon Sep 17 00:00:00 2001 From: Syamsoul Azrien Date: Mon, 3 Jun 2024 12:09:11 +0800 Subject: [PATCH 55/61] fix issue send to all even already include_aliases --- src/OneSignalClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index a9bae1a..f8c99e6 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -388,7 +388,7 @@ public function sendNotificationCustom($parameters = []){ } // Make sure to use included_segments - if (empty($parameters['included_segments']) && empty($parameters['include_player_ids']) && empty($parameters['include_external_user_ids'])) { + if (empty($parameters['included_segments']) && empty($parameters['include_player_ids']) && empty($parameters['include_external_user_ids']) && empty($parameters['include_aliases'])) { $parameters['included_segments'] = ['All']; } From 87f328299f4a0e2cdb644a1aa6c2bb9b26c86ab0 Mon Sep 17 00:00:00 2001 From: mass5 Date: Fri, 13 Dec 2024 17:39:56 -0800 Subject: [PATCH 56/61] add rest_api_url as a config option --- README.md | 3 ++- config/onesignal.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d1aee7..7e3924d 100644 --- a/README.md +++ b/README.md @@ -61,9 +61,10 @@ your OneSignal authorization keys. ## Configuration -You need to fill in your OneSignal *App ID* and *REST API Key* inside your +You need to fill in your OneSignal *REST API URL* *App ID* and *REST API Key* inside your .env file like this: ``` +ONESIGNAL_REST_API_URL=https://api.onesignal.com ONESIGNAL_APP_ID=xxxxxxxxxxxxxxxxxxxx ONESIGNAL_REST_API_KEY=xxxxxxxxxxxxxxxxxx ``` diff --git a/config/onesignal.php b/config/onesignal.php index b1c3b9b..e242ca0 100644 --- a/config/onesignal.php +++ b/config/onesignal.php @@ -18,6 +18,7 @@ | | */ + 'rest_api_url' => env('ONESIGNAL_REST_API_URL', 'https://api.onesignal.com'), 'rest_api_key' => env('ONESIGNAL_REST_API_KEY'), 'user_auth_key' => env('USER_AUTH_KEY'), From 1845de3311e11a57e27168f74695fae97226a9d1 Mon Sep 17 00:00:00 2001 From: mass5 Date: Fri, 13 Dec 2024 17:41:16 -0800 Subject: [PATCH 57/61] Refactor code to use the new `rest_api_url` variable to create a client --- src/OneSignalClient.php | 20 +++++++++++--------- src/OneSignalServiceProvider.php | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index a9bae1a..a94328e 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -13,7 +13,6 @@ class OneSignalClient { - const API_URL = "https://onesignal.com/api/v1"; const ENDPOINT_NOTIFICATIONS = "/notifications"; const ENDPOINT_PLAYERS = "/players"; @@ -22,6 +21,7 @@ class OneSignalClient protected $client; protected $headers; protected $appId; + protected $restApiUrl; protected $restApiKey; protected $userAuthKey; protected $additionalParams; @@ -71,13 +71,15 @@ public function callback(Callable $requestCallback) /** * @param $appId + * @param $restApiUrl * @param $restApiKey * @param $userAuthKey * @param int $guzzleClientTimeout */ - public function __construct($appId, $restApiKey, $userAuthKey, $guzzleClientTimeout = 0) + public function __construct($appId, $restApiUrl, $restApiKey, $userAuthKey, $guzzleClientTimeout = 0) { $this->appId = $appId; + $this->restApiUrl = $restApiUrl; $this->restApiKey = $restApiKey; $this->userAuthKey = $userAuthKey; @@ -506,29 +508,29 @@ private function sendPlayer(Array $parameters, $method, $endpoint) public function post($endPoint) { if($this->requestAsync === true) { - $promise = $this->client->postAsync(self::API_URL . $endPoint, $this->headers); + $promise = $this->client->postAsync($this->restApiUrl . $endPoint, $this->headers); return (is_callable($this->requestCallback) ? $promise->then($this->requestCallback) : $promise); } - return $this->client->post(self::API_URL . $endPoint, $this->headers); + return $this->client->post($this->restApiUrl . $endPoint, $this->headers); } public function put($endPoint) { if($this->requestAsync === true) { - $promise = $this->client->putAsync(self::API_URL . $endPoint, $this->headers); + $promise = $this->client->putAsync($this->restApiUrl . $endPoint, $this->headers); return (is_callable($this->requestCallback) ? $promise->then($this->requestCallback) : $promise); } - return $this->client->put(self::API_URL . $endPoint, $this->headers); + return $this->client->put($this->restApiUrl . $endPoint, $this->headers); } public function get($endPoint) { - return $this->client->get(self::API_URL . $endPoint, $this->headers); + return $this->client->get($this->restApiUrl . $endPoint, $this->headers); } public function delete($endPoint) { if($this->requestAsync === true) { - $promise = $this->client->deleteAsync(self::API_URL . $endPoint, $this->headers); + $promise = $this->client->deleteAsync($this->restApiUrl . $endPoint, $this->headers); return (is_callable($this->requestCallback) ? $promise->then($this->requestCallback) : $promise); } - return $this->client->delete(self::API_URL . $endPoint, $this->headers); + return $this->client->delete($this->restApiUrl . $endPoint, $this->headers); } } diff --git a/src/OneSignalServiceProvider.php b/src/OneSignalServiceProvider.php index ee4f072..6ff23e2 100644 --- a/src/OneSignalServiceProvider.php +++ b/src/OneSignalServiceProvider.php @@ -36,7 +36,7 @@ public function register() $config = $app['config']['onesignal'] ?: $app['config']['onesignal::config']; } - return new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key'] , $config['guzzle_client_timeout']); + return new OneSignalClient($config['app_id'], $config['rest_api_url'], $config['rest_api_key'], $config['user_auth_key'] , $config['guzzle_client_timeout']); }); $this->app->alias('onesignal', 'Berkayk\OneSignal\OneSignalClient'); From 7785ba684fafd09016c0ce7b8c6088f270722457 Mon Sep 17 00:00:00 2001 From: mass5 Date: Fri, 13 Dec 2024 17:44:05 -0800 Subject: [PATCH 58/61] update test to use the new env variable --- tests/test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test.php b/tests/test.php index 2e7ea7a..9345d17 100644 --- a/tests/test.php +++ b/tests/test.php @@ -7,6 +7,7 @@ $client = new Berkayk\OneSignal\OneSignalClient( getenv('APP_ID'), + getenv('REST_API_URL'), getenv('REST_API_KEY'), getenv('USER_AUTH_KEY')); From 3c0703f6335133b0414a82c548b743ca7477469d Mon Sep 17 00:00:00 2001 From: throcha3 Date: Wed, 29 Jan 2025 22:33:29 -0300 Subject: [PATCH 59/61] fix: make rest api url optional in client constructor --- src/OneSignalClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index ae955d4..0b560f5 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -76,10 +76,10 @@ public function callback(Callable $requestCallback) * @param $userAuthKey * @param int $guzzleClientTimeout */ - public function __construct($appId, $restApiUrl, $restApiKey, $userAuthKey, $guzzleClientTimeout = 0) + public function __construct($appId, $restApiKey, $userAuthKey, $guzzleClientTimeout = 0, $restApiUrl = null) { $this->appId = $appId; - $this->restApiUrl = $restApiUrl; + $this->restApiUrl = $restApiUrl ?? config('onesignal.rest_api_url'); $this->restApiKey = $restApiKey; $this->userAuthKey = $userAuthKey; From 1ff3acfc1d00b0c8c1a088fc7e1c83129ee961ea Mon Sep 17 00:00:00 2001 From: throcha3 Date: Tue, 4 Feb 2025 18:31:10 -0300 Subject: [PATCH 60/61] fix: reorder client parameters for singleton --- src/OneSignalServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OneSignalServiceProvider.php b/src/OneSignalServiceProvider.php index 6ff23e2..c862b2c 100644 --- a/src/OneSignalServiceProvider.php +++ b/src/OneSignalServiceProvider.php @@ -36,7 +36,7 @@ public function register() $config = $app['config']['onesignal'] ?: $app['config']['onesignal::config']; } - return new OneSignalClient($config['app_id'], $config['rest_api_url'], $config['rest_api_key'], $config['user_auth_key'] , $config['guzzle_client_timeout']); + return new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key'] , $config['guzzle_client_timeout'], $config['rest_api_url']); }); $this->app->alias('onesignal', 'Berkayk\OneSignal\OneSignalClient'); From dacf8354e41811b638b496af03e51ce476286221 Mon Sep 17 00:00:00 2001 From: Shift Date: Sun, 16 Feb 2025 19:30:20 +0000 Subject: [PATCH 61/61] Bump dependencies for Laravel 12 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 68531de..dc98923 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": ">=5.4.0", "guzzlehttp/guzzle": "^6.2|^7.4.1|^7.2", - "illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0|^10.0|^11.0", + "illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0|^10.0|^11.0|^12.0", "symfony/psr-http-message-bridge": "1.*|2.*|^7.0" }, "require-dev": {