Giter Club home page Giter Club logo

sns-push's Introduction

SNS Push (for AWS SNS API)

This package provides a bunch of helper methods to aid interacting with the Amazon (AWS) SNS API.

Packagist

SNS Push is a simple SNS SDK wrapper with a collection of methods to aid in interacting with the AWS SNS API. It works directly with Laravel or can be used as a standalone PHP package.

Prerequisites

Supports Version
PHP 7.0
Platforms ios/android

Installing

You need to use Composer to install SNS Push into your project:

composer require redu/sns-push

Configuring (Laravel)

Now you have to include SNSPushServiceProvider in your config/app.php:

'providers' => [
    /*
     * Package Service Providers...
     */
    SNSPush\SNSPushServiceProvider::class,
]

Add 'sns' config keys to the config/services.php

'sns' => [
    'account_id' => env('SNS_ACCOUNT_ID', ''),
    'access_key' => env('SNS_ACCESS_KEY', ''),
    'secret_key' => env('SNS_SECRET_KEY', ''),
    'scheme' => env('SNS_SCHEME', 'https'),
    'region' => env('SNS_REGION', 'eu-west-1'),
    'platform_applications' => [
        'ios' => '<application-endpoint-arn>',
        'android' => '<application-endpoint-arn>'
    ]
],

Other PHP Framework (not Laravel) Setup

You should include the Composer autoload.php file if not already loaded:

require __DIR__ . '/vendor/autoload.php';

Instantiate the SNSPush class with the following required config values:

  • account_id
  • access_key
  • secret_key
  • platform_applications

Also configurable:

  • region [default: eu-west-1]
  • api_version [default: 2010-03-31]
  • scheme [default: https]
$sns = new SNSPush([
    'account_id' => '<aws-account-id>', // Required
    'access_key' => '<aws-iam-user-access-key>', // Required 
    'secret_key' => '<aws-iam-user-secret-key>', // Required
    'scheme' => 'http', // Defaults to https
    'platform_applications' => [ // Required
        'ios' => '...',
        'android' => '...'
    ]
]);

Add Device to Application

Add a device to a platform application (ios/android) by passing the device token and application key to addDevice().

$sns->addDevice('<device-token>, 'ios');

Remove Device from Application

Remove a device from AWS SNS by passing the Endpoint ARN to removeDevice().

$sns->removeDevice('<endpoint-arn>');

Subscribe Device to Topic

Subscribe a device to a Topic by passing the Endpoint Arn and Topic Arn to subscribeDeviceToTopic().

$sns->subscribeDeviceToTopic('<endpoint-arn>', '<topic-arn>');

Remove Device from Topic

Remove a device from a Topic by passing the Subscription Arn to removeDeviceFromTopic().

$sns->removeDeviceFromTopic('<subscription-arn>');

Sending Push Notifications

SNS Push supports sending notifications to both Topic Endpoint or directly to an Endpoint ARN (Device).

Send to Device

$message = 'Push notification message.';

$sns->sendPushNotificationToDevice(
    '<endpoint-arn>', 
    $message
);

You can also optionally send a custom payload along with the message.

$sns->sendPushNotificationToDevice('<endpoint-arn>', $message, [
    'payload' => [
        'id' => 9
    ]
]);

The message structure is sent as JSON and will be properly formatted per device. This is a requirement if sending to multiple platforms and/or sending a custom payload.

If you are only sending a simple message to a single platform and would like to save on bytes you can set the message structure to a string.

$sns->sendPushNotificationToDevice('<endpoint-arn>', $message, [
    'message_structure' => 'string'
]);

Send to Topic

$message = 'Push notification message.';

$sns->send->sendPushNotificationToTopic(
    '<topic-arn>', 
    $message
);

Similarly, you can set the message structure and payload.

To do

  • Support more endpoints
  • Test, test, test... (still in early development, use with caution)

Licence

MIT License © Redu Group Ltd

sns-push's People

Contributors

jrhenderson1988 avatar mforcer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

acurrieclark

sns-push's Issues

Could not install with composer

Hi,

i try to install with

composer require redu/sns-push

but i receive this warning:

[InvalidArgumentException]
Could not find a version of package redu/sns-push matching your minimum-stability (stable). Require it with an explicit version constraint allowing its desired stability.

how can i fix it?

The future

I have been looking for a php package which serves this very purpose, but with an emphasis on transactional messages. I was just wondering what your intentions were as this is developed? I would love to contribute if it might benefit us both?
For clarification, i would be looking to broaden the message content ability, perhaps with a message interface and class.
Look forward to hearing what you guys have planned.

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.