Skip to content

scthakuri/onesignal-send-notification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple PHP Library to list and send Push Notification with OneSignal Service

Installation

composer require sureshchand/onesignal-notification

Examples

Initial Setup

<?php
require "vendor/autoload.php";

$api_id = 'API_ID';
$rest_api_key = 'REST_API_KEY';

$pushNotification = new \Suresh\Onesignal\Notification($api_id, $rest_api_key);

Create notification

Send to all subscribers

<?php
$pushNotification->setBody('English Message')
                 ->setSegments('All')
                 ->prepare()
                 ->send();

Send to a specific segment

<?php
$pushNotification->setBody('English Message')
                 ->setSegments('Active Users')
                 ->prepare()
                 ->send();

Send based on filters/tags

<?php
$pushNotification->setBody('English Message')
                 ->setFilter([
                     ['field' => 'tag', 'key' => 'level', 'relation' => '>', 'value' => '10'],
                     ['operator' => 'OR'],
                     ['field' => 'amount_spent', 'relation' => '>', 'value' => '0']
                 ])
                 ->prepare()
                 ->send();

Send based on OneSignal PlayerIds

<?php
$pushNotification->setBody('English Message')
                 ->setPlayersId([
                    'PLAYER_ID',
                    'ANOTHER_PLAYER_ID' 
                 ])
                 ->prepare()
                 ->send();

Reference guideline

OneSignal API Reference

About

Simple PHP Library to list and send Push Notification with OneSignal Service

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages