Skip to content

Commit 934faf2

Browse files
mattpawleyLukas Kämmerling
authored andcommitted
Adds ability to set any parameter to notification
1 parent 9e87947 commit 934faf2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function routeNotificationForOneSignal()
122122
- `webButton(OneSignalWebButton $button)`: Allows you to add action buttons to the notification (Chrome 48+ (web push) only).
123123
- `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).
124124
- `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).
125+
- `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).
125126

126127
### Button usage
127128

src/OneSignalMessage.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class OneSignalMessage
2727
/** @var array */
2828
protected $webButtons = [];
2929

30+
/** @var array */
31+
protected $extraParameters = [];
32+
3033
/**
3134
* @param string $body
3235
*
@@ -116,6 +119,21 @@ public function setData($key, $value)
116119
return $this;
117120
}
118121

122+
/**
123+
* Set additional parameters.
124+
*
125+
* @param string $key
126+
* @param string $value
127+
*
128+
* @return $this
129+
*/
130+
public function setParameter($key, $value)
131+
{
132+
$this->extraParameters[$key] = $value;
133+
134+
return $this;
135+
}
136+
119137
/**
120138
* Add a web button to the message.
121139
*
@@ -161,6 +179,10 @@ public function toArray()
161179
'small_icon' => $this->icon,
162180
];
163181

182+
foreach ($this->extraParameters as $key => $value) {
183+
Arr::set($message, $key, $value);
184+
}
185+
164186
foreach ($this->data as $data => $value) {
165187
Arr::set($message, 'data.'.$data, $value);
166188
}

0 commit comments

Comments
 (0)