Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to set any parameter to notification #23

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions src/OneSignalMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class OneSignalMessage
/** @var array */
protected $webButtons = [];

/** @var array */
protected $extraParameters = [];

/**
* @param string $body
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
Expand Down