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

Add a body parameters in all functions (root-level parameters). #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 25 additions & 5 deletions src/OneSignalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -171,6 +171,10 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n
);
}

if(isset($body)){
$params = array_merge($params, $body);
}

$this->sendNotificationCustom($params);
}

Expand All @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -348,6 +364,10 @@ public function sendNotificationToSegment($message, $segment, $url = null, $data
);
}

if(isset($body)){
$params = array_merge($params, $body);
}

$this->sendNotificationCustom($params);
}

Expand Down