PHPackages                             irishdan/notification-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. irishdan/notification-bundle

ActiveLibrary[Templating &amp; Views](/categories/templating)

irishdan/notification-bundle
============================

A notification bundle for the Symfony framework

v1.0.0(7y ago)5421[1 issues](https://github.com/irishdan/NotificationBundle/issues)[1 PRs](https://github.com/irishdan/NotificationBundle/pulls)MITPHPPHP &gt;=7.1CI failing

Since Jun 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/irishdan/NotificationBundle)[ Packagist](https://packagist.org/packages/irishdan/notification-bundle)[ Docs](https://danbyrne.me/notification-bundle)[ RSS](/packages/irishdan-notification-bundle/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (9)Versions (9)Used By (0)

NotificationBundle
==================

[](#notificationbundle)

[![Build Status](https://camo.githubusercontent.com/f54abbc0e1e3e6ba831450a1c81599e16a75c83c80ebc4b78925ac840fb2d75d/68747470733a2f2f7472617669732d63692e6f72672f697269736864616e2f4e6f74696669636174696f6e42756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/irishdan/NotificationBundle)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b20585ddb1b4bb4fbcf48ca69847def21bbbbc39381d897b4357939cc15bdbec/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f697269736864616e2f4e6f74696669636174696f6e42756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/irishdan/NotificationBundle/?branch=master)

Overview
--------

[](#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
-----------

[](#basic-setup)

Out of the box, NotificationImage bundle should work with minimal configuration.

### Step 1: Download and enable the bundle

[](#step-1-download-and-enable-the-bundle)

Download with composer

```
composer require irishdan/notification-bundle

```

Enable the bundle in the kernel

```
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new IrishDan\NotificationBundle\NotificationBundle(),
    );
}
```

### Step 2: Configure some Notification Channels

[](#step-2-configure-some-notification-channels)

Out 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

```
# app/config/config.yml
notification:
    mail:
        default_sender: 'hi@jim.bob'
    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.

[](#step-4-database-pusher-nexmo-and-slack-channels-have-additional-steps)

Some channels require additional steps

#### Database channel

[](#database-channel)

The Database channel essentially persists a Doctrine entity to the database. A generator is provided to create the entity.

```
php bin/console notification:create-database-notification
```

#### Pusher channel

[](#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

```
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

```
# 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

```
{% 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-channel)

[Nexmo](https://www.nexmo.com) Is a third party SMS service. You need valid credentials to use this channel.

#### Slack shannel

[](#slack-shannel)

[Slack](https://slack.com)

### Step 5: Subscribe Users to one or more channels

[](#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

```
