Skip to content

Commit

Permalink
Merge pull request #7 from princealikhan/master
Browse files Browse the repository at this point in the history
Support for including buttons in the notification
  • Loading branch information
berkayk authored Sep 26, 2016
2 parents 07806bd + 7f5db5e commit 437b2b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ You can easily send a message to all registered users with the command
OneSignal::sendNotificationToAll("Some Message");
OneSignal::sendNotificationToAll("Some Message", $url);
OneSignal::sendNotificationToAll("Some Message", $url, $data);
OneSignal::sendNotificationToAll("Some Message", $url, $data, $buttons);

`$url` and `$data` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url.
`$url` , `$data` and `$buttons` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url.


### Sending a Notification To A Specific User
Expand All @@ -65,9 +66,10 @@ After storing a user's tokens in a table, you can simply send a message with
OneSignal::sendNotificationToUser("Some Message", $userId);
OneSignal::sendNotificationToUser("Some Message", $userId, $url);
OneSignal::sendNotificationToUser("Some Message", $userId, $url, $data);
OneSignal::sendNotificationToUser("Some Message", $userId, $url, $data, $buttons);

`$userId` is the user's unique id where he/she is registered for notifications. Read https://documentation.onesignal.com/docs/website-sdk-api#getUserId for additional details.
`$url` and `$data` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url.
`$url` , `$data` and `$buttons` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url.


### Sending a Notification To Segment
Expand All @@ -77,8 +79,9 @@ You can simply send a notification to a specific segment with
OneSignal::sendNotificationToSegment("Some Message", $segment);
OneSignal::sendNotificationToSegment("Some Message", $segment, $url);
OneSignal::sendNotificationToSegment("Some Message", $segment, $url, $data);
OneSignal::sendNotificationToSegment("Some Message", $segment, $url, $data, $buttons);

`$url` and `$data` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url.
`$url` , `$data` and `$buttons` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url.

### Sending a Custom Notification

Expand Down
19 changes: 16 additions & 3 deletions src/OneSignalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private function usesJSON() {
$this->headers['headers']['Content-Type'] = 'application/json';
}

public function sendNotificationToUser($message, $userId, $url = null, $data = null) {
public function sendNotificationToUser($message, $userId, $url = null, $data = null, $buttons = null) {
$contents = array(
"en" => $message
);
Expand All @@ -54,10 +54,14 @@ public function sendNotificationToUser($message, $userId, $url = null, $data = n
$params['data'] = $data;
}

if (isset($button)) {
$params['buttons'] = $buttons;
}

$this->sendNotificationCustom($params);
}

public function sendNotificationToAll($message, $url = null, $data = null) {
public function sendNotificationToAll($message, $url = null, $data = null, $buttons = null) {
$contents = array(
"en" => $message
);
Expand All @@ -76,10 +80,14 @@ public function sendNotificationToAll($message, $url = null, $data = null) {
$params['data'] = $data;
}

if (isset($button)) {
$params['buttons'] = $buttons;
}

$this->sendNotificationCustom($params);
}

public function sendNotificationToSegment($message, $segment, $url = null, $data = null) {
public function sendNotificationToSegment($message, $segment, $url = null, $data = null, $buttons = null) {
$contents = array(
"en" => $message
);
Expand All @@ -98,6 +106,10 @@ public function sendNotificationToSegment($message, $segment, $url = null, $data
$params['data'] = $data;
}

if (isset($button)) {
$params['buttons'] = $buttons;
}

$this->sendNotificationCustom($params);
}

Expand All @@ -120,6 +132,7 @@ public function sendNotificationCustom($parameters = []){
}

$this->headers['body'] = json_encode($parameters);
$this->headers['buttons'] = json_encode($parameters);
$this->headers['verify'] = false;
return $this->post("notifications");
}
Expand Down

0 comments on commit 437b2b5

Please sign in to comment.