carlcs/craft-pushovernotificationchannel

A Pushover notification channel for the Craft Notifications plugin

1.0.0 2018-03-09 08:11 UTC

This package is auto-updated.

Last update: 2024-11-20 04:56:13 UTC


README

A Pushover notification channel for the Craft Notifications plugin

Requirements

The plugin requires Craft CMS 3.0 or later, and the Craft Notifications plugin.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:
cd /path/to/project
  1. Then tell Composer to load the plugin:
composer require carlcs/craft-pushovernotificationchannel
  1. In the Control Panel, go to Settings → Plugins and click the “Install” button for Pushover Notification Channel.

Usage

To configure a notification to be sent via Pushover, make sure your via() method on the Notification class returns a key with pushover.

<?php
namespace app\notifications;

use carlcs\pushovernotificationchannel\models\PushoverMessage;
use carlcs\pushovernotificationchannel\models\PushoverReceiver;
use rias\notifications\models\Notification;

class ElementSaved extends Notification
{
    public function via()
    {
        return [
            'pushover' => '<PUSHOVER_USER_OR_GROUP_KEY>',
        ];
    }

    public function toPushover($notifiable)
    {
        $element = $this->event->sender;

        return PushoverMessage::create("Element saved {$element->title}")
            ->sound('incoming')
            ->lowPriority()
            ->url($element->getUrl(), 'Go to element page');
    }
}

The pushover value in the via() method can also be a PushoverReceiver object. This allows to specify devices, or to overrule the API Token set in the plugin settings.

return [
    'pushover' => PushoverReceiver::withUserKey('<PUSHOVER_USER_OR_GROUP_KEY>')
        ->toDevice('iphone')
        ->withApplicationToken('<PUSHOVER_API_TOKEN>');,
];

Credits

Laravel Notifications Channel - Pushover