Git Product home page Git Product logo

one-signal's Introduction

Laravel One Signal

Laravel One Signal is Laravel Wrapper for One Signal. One Signal is a great platform for send a push notification to your users. This package mentions in One Signal's official Document. you can see here

Total Downloads Daily Downloads Monthly Downloads License

Give a Star if this package realy usefull to you. it's free ๐Ÿ˜†

๐ŸŽž๏ธ here are video tutorials

How to install and how to implement notifications and devices APIs.

how to implement Segment and Apps APIs.

Contents

Watch Other Lavavel tutorial here

)

Installation

Install the package by the following command,

composer require ladumor/one-signal:1.0.0

Publish the config file

Run the following command to publish config file,

php artisan vendor:publish --provider="Ladumor\OneSignal\OneSignalServiceProvider"

Add Provider

Add the provider to your config/app.php into provider section if using lower version of laravel,

Ladumor\OneSignal\OneSignalServiceProvider::class,

Add Facade

Add the Facade to your config/app.php into aliases section,

'OneSignal' => \Ladumor\OneSignal\OneSignal::class,

Add ENV data

Add your api keys and OneSignal app id to your .env,

ONE_SIGNAL_APP_ID=XXXXXX-XXXXXX-XXXXXX-XXXXXX  (YOUR APP ID)
ONE_SIGNAL_AUTHORIZE=XXXXXX                    (REST API KEY)
ONE_SIGNAL_AUTH_KEY=XXXXXXX                    (YOUR USER AUTH KEY)

You can call them into your code with,

Usage

Send Push Notification

For send push notification, use the sendPush method by calling,

$fields['include_player_ids'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
$message = 'hey!! this is test push.!'   

OneSignal::sendPush($fields, $message);

Optionally, you can obtain the id of the notification like this,

$notificationID = OneSignal::sendPush($fields, $message);
echo $notificationID["id"];

Cancel Notification

To cancel a notification, use the cancelNotification method by calling,

$notificationID = 'xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy';

OneSignal::cancelNotification($notificationID);

Customise Contents

You can customise a contents and pass it in fields. message does not required when you pass contents

$fields['include_player_ids'] = ['xxxxxxxx-xxxx-xxx-xxxx-yyyyyyyyy'];
$fields['contents'] = array(
                          "en" => 'English Message',
                          "es" => 'Spanish Message',
                      );
OneSignal::sendPush($fields);

Get All Notifications

For retrieve all notifications, use the getNotifications method by calling,

OneSignal::getNotifications();

You can check here return response format.

Get Single Notification

For retrieve single notification, use the getNotification method with id param by calling,

OneSignal::getNotification($notificationId);    

You can check here return response format.

Get All Devices

For retrieve all user devices, use the getDevices method by calling,

OneSignal::getDevices();

You can check here return response format.

Get Single Device

For retrieve single Devices, use the getDevice method with id param by calling,

OneSignal::getDevice($deviceId);    

You can check here return response format.

Create Device

For add a device in your application, use the addDevice method by calling, if you want to create device in different application than you can specify app_id in $fields array.

 $fields = [
        'device_type'  => 0,
        'identifier'   => '7abcd558f29d0b1f048083e2834ad8ea4b3d87d8ad9c088b33c132706ff445f0',
        'timezone'     => '-28800',
        'game_version' => '1.1',
        'device_os'    => '7.0.4',
        'test_type'    => 1,
        'device_model' => "iPhone 8,2",
        'tags'         => array("foo" => "bar")
    ];
    
 return OneSignal::addDevice($fields);   

You can check here supported parameters and guide.

Update Device

For update a device in your application, use the addDevice method by calling, if you want to update device in different application than you can specify app_id in $fields array.

 $fields = [
        'device_type'  => 0,
        'identifier'   => '7abcd558f29d0b1f048083e2834ad8ea4b3d87d8ad9c088b33c132706ff445f0',
        'timezone'     => '-28800',
        'game_version' => '1.1',
        'device_os'    => '7.0.4',
        'test_type'    => 1,
        'device_model' => "iPhone 8,2",
        'tags'         => array("foo" => "bar")
    ];
    
 $playerId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    
 return OneSignal::updateDevice($fields, $playerId);   

You can check here supported parameters and guide.

Delete Device

Delete existing device on your application

OneSignal::deleteDevice($deviceId);

Create Segment

NOTE: REQUIRED ONE-SIGNAL PAID PLAN

For add a new segment in your application, use the createSegment method by calling,

 $fields = [
         'name' => 'iOS, Android, Web',
         "filters" => array("field" => "device_type", "relation" => "=", "value" => "Android"),
     ];

return OneSignal::createSegment($fields); 

You can check here supported parameters and guide.

OneSignal::deleteSegment('YOUR_SEGMENT_ID')

Delete Segment

NOTE: REQUIRED ONE-SIGNAL PAID PLAN

You can check here for more guide.

Apps

Note*: Auth key must be set in one-signal.php how to get auth_key?

View Apps

View the details of all of your current OneSignal apps

 $apps = OneSignal::getApps();

You can check here api response.

View App

View the details of single of your current OneSignal app or other app by passing app id.

 // It's return default site which is configured in config.
 $app = OneSignal::getApp();
 
 // you can specify app id as wel but it's optional
 $app = OneSignal::getApp('YOUR_APP_ID');

You can check here api response.

Create App

Creates a new OneSignal app.

 $fields = array(
        'name' => "TestByMe"
    );

 OneSignal::createApp($fields);

You can check here supported parameters and guide.

Update App

Update a new OneSignal app.

 $fields = array(
        'name' => "TestByMe"
    );

 OneSignal::updateApp($fields);
 // you can pass second param as a appId if you want to update other app.. default take from config.

You can check here supported parameters and guide.

View Outcomes

Update a new OneSignal app.

 $fields = array(
        'outcome_names'       => "os__click.count",
        'outcome_time_range'  => '1h',
        'outcome_platform'    => 0,
        'outcome_attribution' => 'direct'
    );

 OneSignal::getOutcomes($fields);   // with params
 OneSignal::getOutcomes();  // without any params
 // you can pass params in this method, it's optional.

You can check here supported parameters and guide.

User Device

You can generate a User Device APIs with just one command,

php artisan one-signal.userDevice:publish

this command generate following files,

  • UserDeviceAPIController
  • UserDeviceAPIRepository
  • UserDevice (model)
  • Migration

Also, do not forget to add following routes in to the api.php file.

use App\Http\Controllers\API\UserDeviceAPIController;
  Route::post('user-device/register', [UserDeviceAPIController::class, 'registerDevice']);
  Route::get('user-device/{playerId}/update-status', [UserDeviceAPIController::class, 'updateNotificationStatus']);

Change Log

Please see Change Log here

License

The MIT License (MIT). Please see License File for more information

one-signal's People

Contributors

fajarsulaksono avatar itsskynet avatar khidirdotid avatar shailesh-ladumor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

one-signal's Issues

Laravel 11 compatibility

Hello, i have this error when installing packages with composer:

Problem 1
    - illuminate/support[v6.0.0, ..., v6.19.1] require php ^7.2 -> your php version (8.3.1) does not satisfy that requirement.
    - illuminate/support[v7.0.0, ..., v7.28.4] require php ^7.2.5 -> your php version (8.3.1) does not satisfy that requirement.
    - illuminate/support[v8.0.0, ..., v8.11.2] require php ^7.3 -> your php version (8.3.1) does not satisfy that requirement.
    - Root composer.json requires ladumor/one-signal 1.0.0 -> satisfiable by ladumor/one-signal[v1.0.0].
    - Conclusion: don't install laravel/framework v11.0.2 (conflict analysis result)
    - Conclusion: don't install laravel/framework v11.0.3 (conflict analysis result)
    - Conclusion: don't install laravel/framework v11.0.4 (conflict analysis result)
    - Conclusion: don't install laravel/framework v11.0.5 (conflict analysis result)
    - Conclusion: don't install laravel/framework v11.0.6 (conflict analysis result)
    - Conclusion: don't install laravel/framework v11.0.7 (conflict analysis result)
    - Conclusion: don't install laravel/framework v11.0.8 (conflict analysis result)
    - Conclusion: don't install laravel/framework v11.0.1 (conflict analysis result)
    - ladumor/one-signal v1.0.0 requires illuminate/support ^10.0|^9.0|^8.0|^7.0|^6.0 -> satisfiable by illuminate/support[v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6, v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.16, v10.0.0, ..., v10.48.4].
    - Only one of these can be installed: illuminate/support[v4.0.0, ..., v4.2.17, v5.3.0, ..., v5.8.36, v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6, v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.16, v10.0.0, ..., v10.48.4, v11.0.0, ..., v11.0.8], laravel/framework[v11.0.0, ..., v11.0.8]. laravel/framework replaces illuminate/support and thus cannot coexist with it.
    - Root composer.json requires laravel/framework ^11.0 -> satisfiable by laravel/framework[v11.0.0, ..., v11.0.8].

I think it's a dependency issue in your package.

Thanks!

All one.signal.php config arguments are null

It does not work, in the initConfig function the parameters config returns null. I did not get .env

dd(config('one-signal.app_id')) // is null.  On .env set ONE_SIGNAL_APP_ID=4585XXXX-a0XX-XX31-9X7X-3XXXX0dXXXXa9
$this->setUrl(config('one-signal.url')); 
$this->setAppId(config('one-signal.app_id'));
$this->setAuthorization(config('one-signal.authorize'));
$this->setAuthKey(config('one-signal.auth_key'));
 $this->setMutableContent(config('one-signal.mutable_content'));

Multiple apps?

I have two different apps that I want to send notifications from my Laravel app. How can I switch the app_id and auth before the sendPush?

Image attachment

I want to attach image with push notification. Does this package providing facility of image attachment?

problem with installation

Problem 1
- php-http/guzzle6-adapter[v2.0.0, ..., 2.x-dev] require guzzlehttp/guzzle ^6.0 -> found guzzlehttp/guzzle[6.0.0, ..., 6.5.x-dev] but it conflicts with your root composer.json require (^7.0.1).
- Root composer.json requires php-http/guzzle6-adapter ^2.0 -> satisfiable by php-http/guzzle6-adapter[v2.0.0, v2.0.1, v2.0.2, 2.x-dev].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Problem with installation: Laravel Framework 10.9.0

I get the following error when I try installation inside Laravel 10 app running on PHP 8.2

Problem 1
    - Root composer.json requires ladumor/one-signal ^0.4.4 -> satisfiable by ladumor/one-signal[v0.4.4].
    - ladumor/one-signal v0.4.4 requires illuminate/support ^9.0|^8.0|^7.0|^6.0 -> found illuminate/support[v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6, v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.7] but these were not loaded, likely because it conflicts with another require.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require ladumor/one-signal:*" to figure out if any version is installable, or "composer require ladumor/one-signal:^2.1" if you know which you need.

Lumen support

Hi, I am using lumen and I need to know if this package has support for lumen.

Your requirements could not be resolved to an installable set of packages.

i can't install.
please advice.
im using the lates laravel version.

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires ladumor/one-signal ^3.0 -> satisfiable by ladumor/one-signal[v3.0.2].
- ladumor/one-signal v3.0.2 requires illuminate/support ~5.0|^6.0|^7.0 -> found illuminate/support[v5.0.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev] but it conflicts with another require.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.