ronte-ltd/push-bundle

Use to send push notifications

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 0

Open Issues: 0

Type:symfony-bundle

dev-master 2017-09-13 09:31 UTC

This package is not auto-updated.

Last update: 2024-04-23 21:26:26 UTC


README

Provide functions to send push notifications.

Features include:

  • Send single notification
  • Send notifications on background
  • Send bulk notifications

Note: For now supports only APNS.

Install

Composer

composer require ronte-ltd/push-bundle

Init

AppKernel.php

new RonteLtd\PushBundle\RonteLtdPushBundle(),

config.yml

ronte_ltd_push:
    push_env: "%push_env%"
    push_sound: true // bool
    push_expiry: 12000 // message expiry, int value in seconds
    bg_worker_id: "%bg_worker_id%"
    gearman_server: "%gearman_server%"
    gearman_port: "%gearman_port%"

parameters.yml

push_env: "valid values: 'prod', 'dev'"
gearman_server: "Add gearman server here"
gearman_port: "Add gearman port here"
bg_worker_id: test //This will be a prefix for a background function in case multiple projects on a server using this command.

Certificates

Puth APNS sertificates files to 'var/apns' folder

Use

Send single notification

/**
 * @param string $deviceId - recipient device token
 * @param string $text - text message
 * @param array $payload - payload array
 */
 $payload = [
     'project' => $id,    // int|string name or id of an app, required
     'pushType' => $type, // int type, required
     'badge' => null,     // int|null, optional
     'headers' => [],     // array of headers, optional
     'extra' => [],       // additional info array, optional
 ];

 $credentials = [
     'certificate' => $fullPathToCertificate, // required
     'passPhrase' => $passPhrase,
     'certificationAuthorityFile' => $fullPathToCertificationAuthorityFile,
 ];
$container->get('push.pusher')->send($deviceId, $text, $payload, $creadentials);

###Send notifications on background Run push:worker:run command on background.

$payload = [
     'project' => $id,    // int|string name or id of an app, required
     'pushType' => $type, // int type, required
     'badge' => null,     // int|null, optional
     'headers' => [],     // array of headers, optional
     'extra' => [],       // additional info array, optional
 ];

$credentials = [
  'certificate' => $fullPathToCertificate, // required
  'passPhrase' => $passPhrase,
  'certificationAuthorityFile' => $fullPathToCertificationAuthorityFile,
];

$pusher = $container->get('push.pusher');
$pusher->addPush($deviceId, $text, $payload, , $creadentials);

###Send bulk notifications

$payload = [
     'project' => $id,    // int|string name or id of an app, required
     'pushType' => $type, // int type, required
     'badge' => null,     // int|null, optional
     'headers' => [],     // array of headers, optional
     'extra' => [],       // additional info array, optional
 ];
$pusher = $container->get('push.apns');
$pusher->addMessage(
    $pusher->createMessage($deviceId, $text, $payload)
);
// Use addMessage as much as needed

$credentials = [
  'certificate' => $fullPathToCertificate, // required
  'passPhrase' => $passPhrase,
  'certificationAuthorityFile' => $fullPathToCertificationAuthorityFile,
];

$pusher->runQueue($credentials);