From 178d402441beb2e8efbbcebab84c09a5f2189adb Mon Sep 17 00:00:00 2001 From: mpawley Date: Thu, 6 Jul 2017 11:57:04 +0100 Subject: [PATCH] Adds ability to set any parameter to notification --- README.md | 1 + src/OneSignalMessage.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 1902a93..d2133e7 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ public function routeNotificationForOneSignal() - `webButton(OneSignalWebButton $button)`: Allows you to add action buttons to the notification (Chrome 48+ (web push) only). - `button(OneSignalButton $button)`: Allows you to add buttons to the notification (Supported by iOS 8.0 and Android 4.1+ devices. Icon only works for Android). - `setData($key, $value)`: Allows you to set additional data for the message payload. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference). +- `setParameter($key, $value)`: Allows you to set additional parameters for the message payload that are available for the REST API. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference). ### Button usage diff --git a/src/OneSignalMessage.php b/src/OneSignalMessage.php index f87b669..c3569e7 100644 --- a/src/OneSignalMessage.php +++ b/src/OneSignalMessage.php @@ -27,6 +27,9 @@ class OneSignalMessage /** @var array */ protected $webButtons = []; + /** @var array */ + protected $extraParameters = []; + /** * @param string $body * @@ -116,6 +119,21 @@ public function setData($key, $value) return $this; } + /** + * Set additional parameters. + * + * @param string $key + * @param string $value + * + * @return $this + */ + public function setParameter($key, $value) + { + $this->extraParameters[$key] = $value; + + return $this; + } + /** * Add a web button to the message. * @@ -161,6 +179,10 @@ public function toArray() 'small_icon' => $this->icon, ]; + foreach ($this->extraParameters as $key => $value) { + Arr::set($message, $key, $value); + } + foreach ($this->data as $data => $value) { Arr::set($message, 'data.'.$data, $value); }