Adding extra notification channels | laravel-backup-server | Spatie

 SPATIE

  Laravel Backup Server
========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-backup-server](https://spatie.be/docs/laravel-backup-server/v2)  Sending-notifications  Adding extra notification channels

 Version   v4   v3   v2   v1

 Other versions for crawler [v4](https://spatie.be/docs/laravel-backup-server/v4) [v3](https://spatie.be/docs/laravel-backup-server/v3) [v2](https://spatie.be/docs/laravel-backup-server/v2) [v1](https://spatie.be/docs/laravel-backup-server/v1)

- [ Introduction ](https://spatie.be/docs/laravel-backup-server/v2/introduction)
- [ Getting a license ](https://spatie.be/docs/laravel-backup-server/v2/getting-a-license)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-backup-server/v2/installation-setup)
- [ Requirements ](https://spatie.be/docs/laravel-backup-server/v2/requirements)
- [ Upgrading ](https://spatie.be/docs/laravel-backup-server/v2/upgrading)
- [ Questions and issues ](https://spatie.be/docs/laravel-backup-server/v2/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-backup-server/v2/changelog)
- [ About us ](https://spatie.be/docs/laravel-backup-server/v2/about-us)
- [ License ](https://spatie.be/docs/laravel-backup-server/v2/license)

Taking backups
--------------

- [ Creating a destination ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/creating-a-destination)
- [ Creating a source ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/creating-a-source)
- [ Taking backups ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/taking-backups)
- [ The backup process ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/the-backup-process)
- [ Events ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/events)
- [ Listing sources and destinations ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/listing-sources-and-destinations)
- [ Working with backups ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/working-with-backups)
- [ Creating database backups ](https://spatie.be/docs/laravel-backup-server/v2/taking-backups/creating-database-backups)

Cleaning up backups
-------------------

- [ The clean up process ](https://spatie.be/docs/laravel-backup-server/v2/cleaning-up-backups/the-cleanup-process)
- [ Determining old backups ](https://spatie.be/docs/laravel-backup-server/v2/cleaning-up-backups/determining-old-backups)
- [ Events ](https://spatie.be/docs/laravel-backup-server/v2/cleaning-up-backups/events)

Monitoring the health of all backups
------------------------------------

- [ The monitoring process ](https://spatie.be/docs/laravel-backup-server/v2/monitoring-the-health-of-all-backups/the-monitoring-process)
- [ Checking health of sources ](https://spatie.be/docs/laravel-backup-server/v2/monitoring-the-health-of-all-backups/checking-health-of-sources)
- [ Checking health of destinations ](https://spatie.be/docs/laravel-backup-server/v2/monitoring-the-health-of-all-backups/checking-health-of-destinations)
- [ Events ](https://spatie.be/docs/laravel-backup-server/v2/monitoring-the-health-of-all-backups/events)

Sending notifications
---------------------

- [ Sending notifications ](https://spatie.be/docs/laravel-backup-server/v2/sending-notifications/sending-notifications)
- [ Adding extra notification channels ](https://spatie.be/docs/laravel-backup-server/v2/sending-notifications/adding-extra-notification-channels)
- [ Customizing the notifiable ](https://spatie.be/docs/laravel-backup-server/v2/sending-notifications/customizing-the-notifiable)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-backup-server                                                                                                                                                                                                                                    `

Adding extra notification channels
==================================

By default the package send notifications via email or Slack. You can add an extra notification channels such as Telegram or native mobile push notification, etc.

The community already has built notification channels package for a lot of services: .

In the following example we're going to add the Pusher push notifications channel. Other notification drivers can be added in the same way.

### 1. Install the notification channel driver

For Pusher Push notifications, require this package

```
laravel-notification-channels/pusher-push-notifications
```

After composer has pulled in the package, just follow [the installation instructions of the package](https://github.com/laravel-notification-channels#installation) to complete the installation.

### 2. Creating your own custom notification

Let say you want to be notified via Pusher push notifications when a backup fails. To make this happen you'll need to create your own `BackupFailed` notification class like the one below:

```
namespace App\Notifications;

use Spatie\BackupServer\Notifications\Notifications\BackupFailedNotification as BaseNotification;
use NotificationChannels\PusherPushNotifications\Message;

class BackupFailedNotification extends BaseNotification
{
    public function toPushNotification($notifiable)
    {
        return Message::create()
            ->iOS()
            ->badge(1)
            ->sound('fail')
            ->body("The backup of {$this->sourceName()} has failed");
    }
}
```

### 3. Register your custom notification in the config file

The last thing you need to do is register your custom notification in the config file.

```
// config/backup.php
use \NotificationChannels\PusherPushNotifications\Channel as PusherChannel

...

    'notifications' => [

        'notifications' => [
            \App\Notifications\BackupHasFailed::class => ['mail', 'slack', PusherChannel::class],
            ...
```
