mcfedr / awspushbundle
A set of services to simplify using Aws to send push notifications
Installs: 344 974
Dependents: 1
Suggesters: 0
Security: 0
Stars: 40
Watchers: 6
Forks: 24
Open Issues: 2
Type:symfony-bundle
Requires
- php: >=8.1
- ext-json: *
- aws/aws-sdk-php: ^3.0
- symfony/framework-bundle: ^5.4|^6.0|^7.0
- symfony/polyfill-mbstring: ^1.1
Requires (Dev)
- fakerphp/faker: ^1.10
- friendsofphp/php-cs-fixer: ^3.3
- phpunit/phpunit: ^9.6
- symfony/browser-kit: ^5.4|^6.0|^7.0
- symfony/console: ^5.4|^6.0|^7.0
- symfony/expression-language: ^5.4|^6.0|^7.0
- symfony/monolog-bundle: ^3.0
- symfony/phpunit-bridge: ^5.4|^6.0|^7.0
- symfony/property-info: ^5.4|^6.0|^7.0
- symfony/security-bundle: ^5.4|^6.0|^7.0
- symfony/serializer: ^5.4|^6.0|^7.0
- symfony/validator: ^5.4|^6.0|^7.0
- symfony/yaml: ^5.4|^6.0|^7.0
Suggests
- ext-mbstring: Its polyfilled, but better to use the extension
- sensio/framework-extra-bundle: Required if you want to use the included ApiController
- symfony/expression-language: Required if you want to use the included ApiController
- symfony/property-info: Required if you want to use the included ApiController
- symfony/security-bundle: Required if you want to use the included ApiController
- symfony/serializer: Required if you want to use the included ApiController
- symfony/validator: Required if you want to use the included ApiController
- dev-master
- 6.20.0
- 6.19.0
- 6.18.0
- 6.17.2
- 6.17.1
- 6.17.0
- 6.16.0
- 6.15.1
- 6.15.0
- 6.14.0
- 6.13.0
- 6.12.0
- 6.11.0
- 6.10.0
- 6.9.1
- 6.9.0
- 6.8.3
- 6.8.2
- 6.8.1
- 6.8.0
- 6.7.0
- 6.6.1
- 6.6.0
- 6.5.2
- 6.5.1
- 6.5.0
- 6.4.0
- 6.3.0
- 6.2.1
- 6.2.0
- 6.1.4
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.2
- 6.0.1
- 6.0.0
- v5.x-dev
- 5.1.3
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.1
- 5.0.0
- 4.1.1
- 4.1.0
- 4.0.7
- 4.0.6
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.4.8
- 2.4.7
- 2.4.6
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.0
- 1.0.0
- 0.0.2
- 0.0.1
This package is auto-updated.
Last update: 2024-10-25 10:59:16 UTC
README
A convenient bundle for registering devices and then pushing to them using amazons SNS service.
Install
Composer
php composer.phar require mcfedr/awspushbundle
AppKernel
Include the bundle in your AppKernel
public function registerBundles()
{
$bundles = array(
...
new Mcfedr\AwsPushBundle\McfedrAwsPushBundle()
Config
Put something like this in your config. The arns in the platforms section should be the preconfigured app arns in SNS.
mcfedr_aws_push:
platforms:
ios: 'arn:aws:sns:....'
android: 'arn:aws:sns:....'
topic_arn: 'arn:aws:sns:...'
pushPlatforms: [apns, fcm]
aws:
credentials:
key: 'my key'
secret: 'my secret'
region: 'my region'
You can skip credentials
if you have want the Aws SDK to get credentials indirectly, either from
environment or
ec2 role.
If you don't set the pushPlatforms
setting then android messages will sent in a format compatible with GCM, i.e.
the notification
field will not be set. This is for backwards compatibility of this bundle.
Usage
Basically have a look at how the ApiController does its stuff
-
Register the device token
$arn = $this->get('mcfedr_aws_push.devices')->registerDevice($token, $platform)
-
Send message to one device
$this->get('mcfedr_aws_push.messages')->send($message, $arn)
-
Send message to all devices
$this->get('mcfedr_aws_push.messages')->broadcast($message)
Alternative usage, using topics to send messages to lots of devices
-
Register the device token
$arn = $this->get('mcfedr_aws_push.devices')->registerDevice($token, $platform)
-
Register the device on the topic
$this->get('mcfedr_aws_push.topics')->registerDeviceOnTopic($arn, $topicArn)
-
Send messages
$this->get('mcfedr_aws_push.topics')->broadcast($message, $topicArn)
If you later add a topic_name to the configuration you can run the mcfedr:aws:subscribe
command to add your existing
devices to the topic.
Text in notifications
For GCM and ADM there is no 'standard' key for text data as there is for Apple pushes, so this bundle send text in a key
called message
.
If localized text is sent the keys are
message-loc-key
message-loc-args
'Complicated' data on ADM
ADM only allows strings as values in the push data. This bundle lets you send 'complicated' values and will
automatically json encode these values for ADM. When it does this the key has _json
added so that its easy to handle
this on the app side.
Example
Sending:
$message = new Message();
$message->setCustom(['simple' => 'Hello', 'complicated' => ['inner' => 'value']]);
ADM received data:
{"data": {"simple": "Hello", "complicated_json": "{\"inner\":\"value\"}"}}
To handle this data you should detect keys that end with _json
and decode the values
The applies to message-loc-args
as well, they will always come as message-loc-args_json
via ADM
Commands
There are some commands to help manage the devices
-
mcfedr:aws:enable
This will reenable all the devices
-
mcfedr:aws:remove
This will remove any disabled devices. Its a good idea to do something like this regularly to remove old devices
-
mcfedr:aws:subscribe
This will subscribe all devices to a topic, useful when introducing a topic
Api Controller
Optional.
There is a controller included which makes basic usage of the bundle very easy. You may or may not want to use it, you might find it most useful as an example.
There are some extra dependencies you must add when using the controller
- sensio/framework-extra-bundle
- symfony/validator
- symfony/serializer
- symfony/property-info
- symfony/security-bundle
- symfony/expression-language
They also need enabling in the framework config
framework: validation: { enable_annotations: true } serializer: enabled: true property_info: enabled: true
Add the routes in your routing.yaml
:
mcfedr_aws_push:
resource: "@McfedrAwsPushBundle/Controller/"
type: annotation
prefix: /
Usage
The controller provides two urls, both expect a JSON POST body
-
The first is a way to register a device
POST /devices { "device": { "deviceId": "a push token", "platform": "the platform name in your config file" } }
-
The second is a way to send a broadcast message. If you are using a topic for all devices then don't send the platform parameter.
POST /broadcast { "broadcast": { "platform": "ios" "message": { "text": "The plain text message to send", "badge": 1 } } }