Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/irishdan/notificationbundle
A bundle for creating notifications and dispatching them to user through various channels
https://github.com/irishdan/notificationbundle
mail nexmo notifications pusher slack-webhook sms symfony3 twig
Last synced: 3 months ago
JSON representation
A bundle for creating notifications and dispatching them to user through various channels
- Host: GitHub
- URL: https://github.com/irishdan/notificationbundle
- Owner: irishdan
- License: mit
- Created: 2017-05-29T12:21:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-16T02:23:51.000Z (almost 6 years ago)
- Last Synced: 2024-09-30T16:03:09.241Z (3 months ago)
- Topics: mail, nexmo, notifications, pusher, slack-webhook, sms, symfony3, twig
- Language: PHP
- Size: 190 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Security: Security/PusherChannelVoter.php
Awesome Lists containing this project
README
# NotificationBundle
[![Build Status](https://travis-ci.org/irishdan/NotificationBundle.svg?branch=master)](https://travis-ci.org/irishdan/NotificationBundle)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/irishdan/NotificationBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/irishdan/NotificationBundle/?branch=master)## Overview
This NotificationBundle allows for the easy creation and and sending of messages to users or other sources, via multiple channels.
Its also enables easy broadcasting of data or messages via.Out of the box with minimal configuration notifications can be sent to single or groups of users,
via, email, SMS, slack and websockets (pusher).Combine this bundle with FoundationInk Bundle to send beautiful html emails for any event
Combine a pusher channel with [taostr](https://codeseven.github.io/toastr/) for instant and attractive notifications
Combine a pusher channel and a database channel for simple direct messaging.## Basic setup
Out of the box, NotificationImage bundle should work with minimal configuration.
### Step 1: Download and enable the bundle
Download with composer
```
composer require irishdan/notification-bundle
```
Enable the bundle in the kernel
```php
// app/AppKernel.phppublic function registerBundles()
{
$bundles = array(
// ...
new IrishDan\NotificationBundle\NotificationBundle(),
);
}
```
### Step 2: Configure some Notification ChannelsOut of the box the bundle supports several channels, including:
- [mail](Resources/doc/channels.md#mail) (Email)
- [database](Resources/doc/channels.md#database)
- [slack](Resources/doc/channels.md#slack)
- [nexmo](Resources/doc/channels.md#nexmo) (SMS)
- [pusher](Resources/doc/channels.md#pusher) (Websockets)
- [logger](Resources/doc/channels.md#logger)To enable a channel simple add its configuration to your config.yml
```yml
# app/config/config.yml
notification:
mail:
default_sender: '[email protected]'
database:
entity: 'AppBundle:Notification'
pusher:
app_id: "12"
auth_key: "1111SECURE222KEY"
secret: "SeCrEt"
cluster: "eu"
encrypted: true
event: 'notification'
channel_name: 'private-direct_' # This is a private channel
slack:
nexmo:
api_key: 7654321
api_secret: oiCHOIoi
from: "YourApp"
logger:
severity: 'info'
```It's also possible to create [custom channels](Resources/doc/channels.md) or [alter an existing channel's behavior](Resources/doc/channels.md)
### Step 4: Database, Pusher, Nexmo, and Slack channels have additional steps.
Some channels require additional steps
#### Database channel
The Database channel essentially persists a Doctrine entity to the database.
A generator is provided to create the entity.```bash
php bin/console notification:create-database-notification
```
#### Pusher channel
[Pusher](https://pusher.com/) is a a third party service with a decent free package. You need valid pusher credendials to use the channel.The pusher PHP library is required also. Install with composer
```bash
composer require pusher/pusher-php-server```
If you are using private channels (HIGHLY RECOMMENDED), the pusher authentication route is needed.
Import the route into your project```yml
# app/config/routing.yml
notification_pusher_auth:
resource: "@NotificationBundle/Resources/config/routing.yml"```
Pusher requires a javascript library and additional to interact with pusher channel you have defined.
Twig functions are provided which generate the required javascript```twig
{% block javascripts %}
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;{{ notification_new_pusher_js() }}
{{ notification_new_pusher_channel_js(app.user) }}
channel.bind('{{ notification_pusher_event }}', function (data) {
// The data object contains your notification data
console.log(data);
// Add custom js to react to the the notifcation.
// A good solution is to use toastr to display the notification.
});
{% endblock %}```
#### Nexmo channel
[Nexmo](https://www.nexmo.com) Is a third party SMS service. You need valid credentials to use this channel.
#### Slack shannel
[Slack](https://slack.com)
### Step 5: Subscribe Users to one or more channels
In order for users to be sent notifications through the channels you have configured they must be subscribed to each channel.
Assuming your User class is AppBundle\Entity\User, implement the required interfaces:
@TODO: Improve this```
getUser();/** $notification NotificationInterface */
$notification = new NewMemberNotification();// The notification.manager service is used to send notifications
$this->get('notification.manager')->send($notification, $user);// You can send to multiple users also.
$this->get('notification.manager')->send($notification, [$user1, $user2]);// You can pass extra data into the notification also
// This will be available in the data array
// and also in twig templates as {{ data.date }}
$data = [
'date' => new \DateTime(),
];
$this->get('notification.manager')->send($notification, $user, $data);
```## Documentation
For more advanced setup read the Documentation
- [Installation and Setup](Resources/doc/installation.md)
- [Channels](Resources/doc/channels.md)
- [Adapters](Resources/doc/adapters.md)
- [Broadcast](Resources/doc/broadcast.md)
- [Events & Qeueing](Resources/doc/events_queueing.md)
- [Commands](Resources/doc/commands.md)
- [Tests](Resources/doc/tests.md)
## Attribution- This bundle was inspired by the [Laravel](https://laravel.com/) notification system