Developed with love by KnpLabs Hire us for your project!
18

NotificationsBundle

by mradmrad

A simple notification bundle using Pusher API

NotificationsBundle

A simple implementation for Pusher API that helps you integrate a notifications
system in a few simple steps.

Installation

  1. composer require mrad/notifications-bundle
  2. Enable the bundle in AppKernel.php new SBC\NotificationsBundle\NotificationsBundle(),

Usage

Step 1:

First thing you need to create an account with Pusher and then in Your apps menu create
a new app.

Step 2:

Add you app configuration to the app/config.yml:
```

NotificationsBundle configuration

notifications:
app_id: your_id
app_key: your_key
app_secret: secret
cluster: cluster
# Optional
# Default false: work without ssl encryption
# Set it to true to work with ssl encryption
encrypted: false
```
Of course you can find those details in your app in the dashboard.
alt text

Step 3:

Now in your view.html.twig (your client side) add this:

{# Call NotificationsBundles's assets #}
{{ notifications_assets() }}
<script>
/**
* This function will be triggered each time a data comes from the server
* Make sure you call it otherwise you won't get any data
* @param data contains your data sent from the server
*/
function onNotificationsPushed(data){
console.log('data', data);
}
</script>

And that's it :smiley:, now to make sure that your client is receiving the data correctly you can test it by calling this
console command:
php bin/console notifications:trigger "Your message"
If you open the browser's console you should see something like this:
alt text

Broadcast custom messages from Backend

To broadcast messages from your backend you can simply do this:
php
// From your controller or service
$data = array(
'my-message' => "My custom message",
);
$pusher = $this->get('mrad.pusher.notificaitons');
$pusher->trigger($data);

Next Step

Now I will show how to create and save notifications in database.
* Create and persist notifications

License

This project is under the MIT license

Thanks

Thanks to SlimenTN for his help in this project

The MIT License (MIT)

Copyright (c) 2010-2018 Haithem Mrad

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
notifications:
cluster: ~
app_id: ~
app_key: ~
app_secret: ~
encrypted: false
  • updated README file
    By , 8 months ago
  • Updated README file
    By SlimenTN, 8 months ago
  • 'EnabledEncryptionOption'
    By mradmrad, 8 months ago
  • 'firstcommit'
    By mradmrad, 8 months ago