diff --git a/README.md b/README.md index 5bd8302..02a505f 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,10 @@ 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. +### Adding more parameters on root level + +You can add a body parameter on all above functions if you want to add more parameters (see [Common Parameters section in OneSignal documentation](https://documentation.onesignal.com/reference/create-notification#common-parameters) for more information). + ### Sending a Custom Notification You can send a custom message with diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 4d600c6..810ca52 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -132,7 +132,7 @@ public function setParam($key, $value) return $this; } - public function sendNotificationToUser($message, $userId, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { + public function sendNotificationToUser($message, $userId, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null, $body = null) { $contents = array( "en" => $message ); @@ -171,6 +171,10 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n ); } + if(isset($body)){ + $params = array_merge($params, $body); + } + $this->sendNotificationCustom($params); } @@ -184,7 +188,7 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n * @param null $headings * @param null $subtitle */ - public function sendNotificationToExternalUser($message, $userId, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { + public function sendNotificationToExternalUser($message, $userId, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null, $body = null) { $contents = array( "en" => $message ); @@ -223,9 +227,13 @@ public function sendNotificationToExternalUser($message, $userId, $url = null, $ ); } + if(isset($body)){ + $params = array_merge($params, $body); + } + $this->sendNotificationCustom($params); } - public function sendNotificationUsingTags($message, $tags, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { + public function sendNotificationUsingTags($message, $tags, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null, $body = null) { $contents = array( "en" => $message ); @@ -264,10 +272,14 @@ public function sendNotificationUsingTags($message, $tags, $url = null, $data = ); } + if(isset($body)){ + $params = array_merge($params, $body); + } + $this->sendNotificationCustom($params); } - public function sendNotificationToAll($message, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { + public function sendNotificationToAll($message, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null, $body = null) { $contents = array( "en" => $message ); @@ -306,10 +318,14 @@ public function sendNotificationToAll($message, $url = null, $data = null, $butt ); } + if(isset($body)){ + $params = array_merge($params, $body); + } + $this->sendNotificationCustom($params); } - public function sendNotificationToSegment($message, $segment, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null) { + public function sendNotificationToSegment($message, $segment, $url = null, $data = null, $buttons = null, $schedule = null, $headings = null, $subtitle = null, $body = null) { $contents = array( "en" => $message ); @@ -348,6 +364,10 @@ public function sendNotificationToSegment($message, $segment, $url = null, $data ); } + if(isset($body)){ + $params = array_merge($params, $body); + } + $this->sendNotificationCustom($params); }