Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
874df71
getNotification and get method
ksvendsen Dec 4, 2017
2072e3d
hotfix typo
ksvendsen Dec 4, 2017
45ca12c
Allow array of userIds to be passed instead of just a single userId
ryanedgar Jan 23, 2018
8dd2dc0
Merge pull request #62 from ryanedgar/feature/array-users
berkayk Feb 14, 2018
b21da57
Merge pull request #59 from ksdevelopment/master
berkayk Feb 23, 2018
563ff64
Fixed filters/tags not working
Mohammad-Alavi Feb 24, 2018
04a0f53
updated read me
Mohammad-Alavi Feb 24, 2018
543a9f7
Updated read me
Mohammad-Alavi Feb 24, 2018
587c9a3
cahnged email to soemthing else
Mohammad-Alavi Feb 27, 2018
b1ae555
Merge pull request #70 from Mohammad-Alavi/bug-fix
berkayk Feb 28, 2018
3dbf904
Add guzzle retry middleware
mbardelmeijer Mar 3, 2018
84ff0da
Retry the exact '500' status code as well
mbardelmeijer Mar 3, 2018
3a0c64b
Code style
mbardelmeijer Mar 3, 2018
8c6a5c8
adding heading and subtitle
mohammad6006 Mar 7, 2018
c2ae68f
Merge pull request #73 from mohammad6006/master
berkayk May 29, 2018
1cd0a93
Added a method to delete notifications
zzeebbii Jun 12, 2018
790b51f
Adding support for getApp / getApps in OneSignalClient
ckin-loox Jul 5, 2018
6dcf431
adding requiresUserAuth method
ckin-loox Jul 5, 2018
b3830e1
Adding getNotifications method to OneSignalClient
ckin-loox Jul 6, 2018
2d051fa
Adding CSV export
ckin-loox Jul 10, 2018
6d4214f
Merge pull request #72 from enflow-nl/retryMiddleware
berkayk Sep 23, 2018
125e963
Merge pull request #81 from zzeebbii/master
berkayk Sep 23, 2018
8a1be27
Add 5.5 AutoDiscover support
Sep 24, 2018
c814e9e
Merge pull request #86 from Scarwolf/master
berkayk Sep 26, 2018
1978329
fix the broken readme render
samundra Oct 2, 2018
7d1354b
Merge pull request #87 from samundra/feature/readme-update
berkayk Oct 2, 2018
f33e27e
Alias the 'onesignal' service
mbabker Oct 23, 2018
a3c0de6
Merge pull request #91 from mbabker/patch-1
berkayk Nov 8, 2018
5e880ba
Merge pull request #82 from ckin-it/master
berkayk Nov 8, 2018
5e25505
Send notification by external user ids
Jan 22, 2019
6837be5
Fixed verification to call method configure
MatheusNaldi Jan 30, 2019
44dfa1d
Removed incorrect method called
MatheusNaldi Jan 30, 2019
104d2a6
Merge pull request #97 from ayazshakoor/issue/send_notification_to_ex…
berkayk Apr 27, 2019
e61fe3a
Merge pull request #99 from MatheusNaldi/master
berkayk Apr 27, 2019
858c28c
Fixed README.
berkayk Aug 18, 2019
c04c229
Allow Laravel 6
JayBizzle Aug 28, 2019
3bffaec
Merge pull request #113 from JayBizzle/patch-1
berkayk Sep 4, 2019
69158ee
Update README.md
berkayk Jan 15, 2020
5d0e986
Update README.md
berkayk Jan 15, 2020
2fb36f9
Update README.md
berkayk Jan 20, 2020
47f24ba
Add Laravel 7 support
aykutfarsak Mar 5, 2020
8eb7959
Merge pull request #124 from aykutfarsak/laravel-7
berkayk Mar 5, 2020
6120721
Update README.md
berkayk Mar 6, 2020
3a6c0d7
Remove broken links
phfoxer Mar 7, 2020
430eeae
Update composer.json
pedro-santiago Mar 31, 2020
3f15369
Merge pull request #128 from pedro-santiago/master
berkayk Apr 1, 2020
92d7eab
Merge pull request #127 from phfoxer/patch-1
berkayk Apr 1, 2020
2ddb009
Fixed README.
berkayk Jul 1, 2020
d5930fd
Merge remote-tracking branch 'origin/master'
berkayk Jul 1, 2020
f3bf8fd
Fixed README.
berkayk Jul 1, 2020
97eb318
add laravel 8 compatability by upgrading guzzle to ^7.0.1
Sep 8, 2020
e97fc91
Update composer.json
ExpDev07 Sep 8, 2020
01ef52f
Update README.md
meirinaldojunior Sep 9, 2020
7bc99a5
Merge pull request #135 from ExpDev07/laravel-8-upgrade
berkayk Sep 12, 2020
4d9fd6c
Fixed Laravel 8 support.
berkayk Sep 12, 2020
5f84434
Merge pull request #137 from meirinaldojunior/patch-1
berkayk Sep 12, 2020
fddd618
Update config publish command
stephenjude Sep 19, 2020
aa6f6fb
use dotenv for onesignal keys and id
stephenjude Sep 19, 2020
bce5e97
update package configuration guide on the readme
stephenjude Sep 19, 2020
18cc411
Merge pull request #1 from stephenjude/stephenjude-patch-1
stephenjude Sep 19, 2020
11a3015
Merge pull request #140 from stephenjude/master
berkayk Jan 28, 2021
afcef12
add timeout option to Guzzle Client
tomaszthreadable Aug 10, 2021
cc7c142
update docs
tomaszthreadable Aug 10, 2021
b88d0ad
update docs - fix typo
tomaszthreadable Aug 10, 2021
db7bbd2
Update OneSignalClient.php
Sml995 Feb 24, 2022
4f826a2
Merge pull request #160 from Sml995/master
berkayk Feb 25, 2022
20c8ac1
Update composer.json
philipnjuguna66 Mar 11, 2022
8c99fbd
update gazzle htp
philipnjuguna66 Mar 11, 2022
3d9f851
Merge pull request #162 from appsoriginke/master
berkayk Mar 21, 2022
e9d84e2
fix: ignore segments if include external user ids
Mar 23, 2022
495f87b
Merge pull request #163 from samuelcecilio/ignore-segments-if-include…
berkayk Mar 25, 2022
4b3bc2f
Merge pull request #154 from tomaszmrozinski/master
berkayk Mar 25, 2022
13a4399
Fix array index access
Sml995 Apr 25, 2022
241ce88
Bump dependencies for Laravel 10
laravel-shift Jan 31, 2023
e37aaf4
Merge pull request #176 from laravel-shift/l10-compatibility
berkayk Feb 21, 2023
95322bd
Add `ConnectException` as a valid type in retry middleware
mbardelmeijer Jul 17, 2023
3d46a5e
Fix sendNotificationCustom $parameters['include_external_user_ids'] i…
Sep 28, 2023
2eeca4d
Merge pull request #183 from LazarDudic/master
berkayk Feb 9, 2024
5b8d275
Update README.md
dela-dels Feb 11, 2024
24751a2
Merge pull request #186 from dela-dels/patch-1
berkayk Feb 11, 2024
9fe6522
Bump dependencies for Laravel 11
laravel-shift Mar 2, 2024
292973c
Merge pull request #187 from laravel-shift/l11-compatibility
berkayk Mar 26, 2024
224c512
Removing a double "$" in a offset variable
Apr 17, 2024
f345efa
fix issue send to all even already include_aliases
syamsoul Jun 3, 2024
87f3282
add rest_api_url as a config option
mass5 Dec 14, 2024
1845de3
Refactor code to use the new `rest_api_url` variable to create a client
mass5 Dec 14, 2024
7785ba6
update test to use the new env variable
mass5 Dec 14, 2024
4482ef4
Merge pull request #169 from Sml995/fix-custom-notification
berkayk Dec 27, 2024
b41d522
Merge pull request #190 from diogocoutinho/Bug-in-getNotifications-me…
berkayk Dec 27, 2024
d2bde3b
Merge pull request #194 from syamsoul/hotfix/custom-notification-send…
berkayk Dec 27, 2024
0fa625a
Merge pull request #181 from mbardelmeijer/patch-1
berkayk Dec 27, 2024
ce1c399
Merge pull request #197 from mass5/add_rest_api_url_to_config
berkayk Dec 30, 2024
3c0703f
fix: make rest api url optional in client constructor
throcha3 Jan 30, 2025
b9cd06c
Merge pull request #198 from throcha3/fix/onesignal-url-optional
berkayk Feb 3, 2025
1ff3acf
fix: reorder client parameters for singleton
throcha3 Feb 4, 2025
7ad1254
Merge pull request #199 from throcha3/fix/singleton-parameters-order
berkayk Feb 5, 2025
dacf835
Bump dependencies for Laravel 12
laravel-shift Feb 16, 2025
e140faa
Merge pull request #202 from laravel-shift/l12-compatibility
berkayk Mar 19, 2025
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
226 changes: 206 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# OneSignal Push Notifications for Laravel 5
# OneSignal Push Notifications for Laravel
[![Latest Stable Version](https://poser.pugx.org/berkayk/onesignal-laravel/v/stable)](https://packagist.org/packages/berkayk/onesignal-laravel)
[![Total Downloads](https://poser.pugx.org/berkayk/onesignal-laravel/downloads)](https://packagist.org/packages/berkayk/onesignal-laravel)
[![License](https://poser.pugx.org/berkayk/onesignal-laravel/license)](https://packagist.org/packages/berkayk/onesignal-laravel)



## Introduction

This is a simple OneSignal wrapper library for Laravel. It simplifies the basic notification flow with the defined methods. You can send a message to all users or you can notify a single user.
Before you start installing this service, please complete your OneSignal setup at https://onesignal.com and finish all the steps that is necessary to obtain an application id and REST API Keys.
This is a simple OneSignal wrapper library for Laravel. It simplifies the basic
notification flow with the defined methods. You can send a message to all users
or you can notify a single user. Before you start installing this service,
please complete your OneSignal setup at https://onesignal.com and finish all
the steps that is necessary to obtain an application id and REST API Keys.


## Installation
Expand All @@ -14,7 +22,9 @@ First, you'll need to require the package with Composer:
composer require berkayk/onesignal-laravel
```

Aftwards, run `composer update` from your command line.
Afterwards, run `composer update` from your command line.

**You only need to do the following if your Laravel version is below 5.5**:

Then, update `config/app.php` by adding an entry for the service provider.

Expand All @@ -25,7 +35,6 @@ Then, update `config/app.php` by adding an entry for the service provider.
];
```


Then, register class alias by adding an entry in aliases section

```php
Expand All @@ -39,67 +48,244 @@ Then, register class alias by adding an entry in aliases section
Finally, from the command line again, run

```
php artisan vendor:publish --tag=config
php artisan vendor:publish --provider="Berkayk\OneSignal\OneSignalServiceProvider" --tag="config"
```

to publish the default configuration file.
This will publish a configuration file named `onesignal.php` which includes your OneSignal authorization keys.
This will publish a configuration file named `onesignal.php` which includes
your OneSignal authorization keys.

> **Note:** If the previous command does not publish the config file successfully, please check the steps involving *providers* and *aliases* in the `config/app.php` file.
> **Note:** If the previous command does not publish the config file successfully,
> please check the steps involving *providers* and *aliases* in the `config/app.php` file.


## Configuration

You need to fill in `onesignal.php` file that is found in your applications `config` directory.
`app_id` is your *OneSignal App ID* and `rest_api_key` is your *REST API Key*.
You need to fill in your OneSignal *REST API URL* *App ID* and *REST API Key* inside your
.env file like this:
```
ONESIGNAL_REST_API_URL=https://api.onesignal.com
ONESIGNAL_APP_ID=xxxxxxxxxxxxxxxxxxxx
ONESIGNAL_REST_API_KEY=xxxxxxxxxxxxxxxxxx
```
You can control timeout of the Guzzle client used by OneSignalClient by adding following into your .env file
```
ONESIGNAL_GUZZLE_CLIENT_TIMEOUT=integer_value
```
This param is useful when you are planning to send push notification via [Laravel queues](https://divinglaravel.com/always-set-a-timeout-for-guzzle-requests-inside-a-queued-job)

## Usage

### Sending a Notification To All Users

You can easily send a message to all registered users with the command

OneSignal::sendNotificationToAll("Some Message", $url = null, $data = null, $buttons = null, $schedule = null);
```php
OneSignal::sendNotificationToAll(
"Some Message",
$url = null,
$data = null,
$buttons = null,
$schedule = null
);
```

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


### Sending a Notification based on Tags/Filters

You can send a message based on a set of tags with the command

OneSignal::sendNotificationUsingTags("Some Message", array("key" => "device_uuid", "relation" => "=", "value" => 123e4567-e89b-12d3-a456-426655440000), $url = null, $data = null, $buttons = null, $schedule = null);
##### Example 1:

```php
OneSignal::sendNotificationUsingTags(
"Some Message",
array(
["field" => "tag", "key" => "email", "relation" => "=", "value" => "email21@example.com"],
["field" => "tag", "key" => "email", "relation" => "=", "value" => "email1@example.com"],
...
),
$url = null,
$data = null,
$buttons = null,
$schedule = null
);
```

##### Example 2:

```php
OneSignal::sendNotificationUsingTags(
"Some Message",
array(
["field" => "tag", "key" => "session_count", "relation" => ">", "value" => '2'],
["field" => "tag", "key" => "first_session", "relation" => ">", "value" => '2000'],
),
$url = null,
$data = null,
$buttons = null,
$schedule = null
);
```

### Sending a Notification To A Specific User

After storing a user's tokens in a table, you can simply send a message with
After storing a user's token in a table, you can simply send a message with

OneSignal::sendNotificationToUser("Some Message", $userId, $url = null, $data = null, $buttons = null, $schedule = null);
```php
OneSignal::sendNotificationToUser(
"Some Message",
$userId,
$url = null,
$data = null,
$buttons = null,
$schedule = null
);
```

`$userId` is the user's unique id where he/she is registered for notifications. Read https://documentation.onesignal.com/docs/web-push-tagging-guide for additional details.
`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide a `$url` parameter, users will be redirecting to that url.
`$userId` is the user's unique id where he/she is registered for notifications.
Read https://documentation.onesignal.com/docs/add-user-data-tags for additional details.
`$url` , `$data` , `$buttons` and `$schedule` fields are optional. If you provide
a `$url` parameter, users will be redirected to that url.



### Sending a Notification To A Specific external User (custom user id added by user)

After storing a user's token in a table, you can simply send a message with

```php
OneSignal::sendNotificationToExternalUser(
"Some Message",
$userId,
$url = null,
$data = null,
$buttons = null,
$schedule = null
);
```

`$userId` is the user's unique external id (custom id) added by the user where he/she is registered for notifications.
Read https://documentation.onesignal.com/docs/add-user-data-tags for additional details.
`$url` , `$data` , `$buttons` and `$schedule` fields are exceptional. If you provide
a `$url` parameter, users will be redirected to that url.

### Sending a Notification To Segment

You can simply send a notification to a specific segment with

OneSignal::sendNotificationToSegment("Some Message", $segment, $url = null, $data = null, $buttons = null, $schedule = null);
```php
OneSignal::sendNotificationToSegment(
"Some Message",
$segment,
$url = null,
$data = null,
$buttons = null,
$schedule = null
);
```

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

### Sending a Custom Notification

You can send a custom message with

```php
OneSignal::sendNotificationCustom($parameters);
```


### Sending a Custom Notification
### Sending a async Custom Notification
You can send a async custom message with

```php
OneSignal::async()->sendNotificationCustom($parameters);
```

Please refer to https://documentation.onesignal.com/reference for all customizable parameters.

## Examples

Some people found examples confusing, so I am going to provide some detailed examples that I use in my applications. These examples will probably guide you on customizing your notifications. For custom parameters, please refer to https://documentation.onesignal.com/reference/create-notification.

### 1) Sending a message to a segment with custom icon and custom icon color

You need to customize `android_accent_color` and `small_icon` values before sending your notifications. These are `parameters` that you need to specify while sending your notifications.

```php
use OneSignal;

$params = [];
$params['android_accent_color'] = 'FFCCAA72'; // argb color value
$params['small_icon'] = 'ic_stat_distriqt_default'; // icon res name specified in your app

$message = "Test message to send";
$segment = "Testers";
OneSignal::addParams($params)->sendNotificationToSegment(
$message,
$segment
);

// or to all users
OneSignal::addParams($params)->sendNotificationToAll($message);

```

### 2. Sending a message with high priority

This time, we will specify parameters one after the other.

```php
use OneSignal;

$message = "Test message to send";
$segment = "Testers";
OneSignal::setParam('priority', 10)->sendNotificationToSegment(
$message,
$segment
);

// You can chain as many parameters as you wish

OneSignal::setParam('priority', 10)->setParam('small_icon', 'ic_stat_onesignal_default')->setParam('led_color', 'FFAACCAA')->sendNotificationToAll($message);

```

### 3. Sending a message with custom heading and subtitle

```php
use OneSignal;

OneSignal::sendNotificationToSegment(
"Test message with custom heading and subtitle",
"Testers",
null, null, null, null,
"Custom Heading",
"Custom subtitle"
);
```

### 4. Sending a delayed message to a specific user with many custom parameters

```php
use OneSignal;

$userId = "3232331-1722-4fee-943d-23123asda123";
$params = [];
$params['include_player_ids'] = [$userId];
$contents = [
"en" => "Some English Message",
"tr" => "Some Turkish Message"
];
$params['contents'] = $contents;
$params['delayed_option'] = "timezone"; // Will deliver on user's timezone
$params['delivery_time_of_day'] = "2:30PM"; // Delivery time

OneSignal::sendNotificationCustom($params);

```
78 changes: 47 additions & 31 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,50 @@
{
"name": "berkayk/onesignal-laravel",
"description": "OneSignal Push Wrapper Laravel",
"keywords": ["onesignal", "webpush", "push", "laravel", "laravel 5"],
"type": "library",
"require": {
"php": ">=5.4.0",
"guzzlehttp/guzzle": "^6.2",
"illuminate/support": "4.*|5.*",
"symfony/psr-http-message-bridge": "1.*"
},
"require-dev": {
"vlucas/phpdotenv": "^2.2"
},
"autoload": {
"psr-4": {
"Berkayk\\OneSignal\\": "src/"
}
},
"license": "MIT",
"authors": [
{
"name": "Berkay Kaya",
"email": "berkayk@gmail.com",
"homepage": "http://berkaykaya.com"
"name": "berkayk/onesignal-laravel",
"description": "OneSignal Push Wrapper Laravel",
"keywords": [
"onesignal",
"webpush",
"push",
"laravel",
"laravel 5"
],
"type": "library",
"require": {
"php": ">=5.4.0",
"guzzlehttp/guzzle": "^6.2|^7.4.1|^7.2",
"illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0|^10.0|^11.0|^12.0",
"symfony/psr-http-message-bridge": "1.*|2.*|^7.0"
},
{
"name": "Maykonn Welington Candido",
"email": "maykonn@outlook.com"
}
],
"minimum-stability": "dev",
"prefer-stable": true
"require-dev": {
"vlucas/phpdotenv": "^2.2|^5.5"
},
"autoload": {
"psr-4": {
"Berkayk\\OneSignal\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Berkayk\\OneSignal\\OneSignalServiceProvider"
],
"aliases": {
"OneSignal": "Berkayk\\OneSignal\\OneSignalFacade"
}
}
},
"license": "MIT",
"authors": [
{
"name": "Berkay Kaya",
"email": "berkayk@gmail.com",
"homepage": "http://berkaykaya.com"
},
{
"name": "Maykonn Welington Candido",
"email": "maykonn@outlook.com"
}
],
"minimum-stability": "dev",
"prefer-stable": true
}
Loading