Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Version 1.0.0

Compare
Choose a tag to compare
@herpaderpaldent herpaderpaldent released this 30 Dec 14:43
· 90 commits to master since this release
8a242b1

seat-notifications

Installation

  1. cd to /var/www/seat
  2. enter composer require herpaderpaldent/seat-notifications
  3. run migration php artisan migrate

Enable Notification Channel

To enable seat-notifications functionality of sending notifications. Create a bot for your notification channel. By default seat-notifications offers two notification channels which could be extended by other packages: slack and discord:
configuration

a more detailed guide on oAuth creation will follow for now the blow table must suffice:

Notification Channel Redirect URLs Comment
Discord {seat_url}/seatnotifications/discord/configuration/callback/server This callback url is needed for the configuration of your discord bot.
Discord {seat_url}/seatnotifications/discord/callback/user This callback url is needed for the authentication of a discord user.
Slack {seat_url}/seatnotifications/slack/configuration/callback/server This callback url is needed for the configuration of your slack bot.
Slack {seat_url}/seatnotifications/slack/callback/user This callback url is needed for the authentication of a slack user.

Note: you may only configure one notification channel at your will. However, for discord you must create a bot in your application. For Slack you need to add the bot permission to your oauth scope.

Setup Roles

To be able to subsripe to a notification the user needs the appropriate permission. Please setup a role that carries the needed permission and assign it to users that should be able to receive the notification.

Authenticate

Users need to authenticate for your setup notification channel prior to receiving notifications. they may do this in the registration box on the notification page.

What does the package do at the moment

  • Send RefreshTokenDeleted Notification to Discord and/or Slack when a refresh_token is deleted.
  • Using Model Observer to dispatch Notifications
  • Notifications are queueable and send out via the queue.
  • The RefreshTokenNotification is able to be delivered to Channels or via DM on the users preference.

Example:
image
picture

Developing

Most importantly: take note of laravel's notification documentation. The provided example of RefreshTokenDeletedNotification is based upon it. Notifications are being send by using the Notification facade:

Notification::send($receipients, (new RefreshTokenDeletedNotification($refresh_token)));

where $receipients are a collection of modal that should receive the notification and $refresh_token is the deleted refresh_token that is passed to the constructor. In this example we use an Observer to send notifications: Observer.

Add new channels

If you have written a new notification channel that you would like to use for sending notifications to your users you might extend config/services.php similar to the provided example:

'seat-notification-channel' => [
        'discord'   => Herpaderpaldent\Seat\SeatNotifications\Http\Controllers\Discord\DiscordNotificationChannel::class,
    ],

Your channel should extend BaseNotificationChannel

namespace Herpaderpaldent\Seat\SeatNotifications\Http\Controllers;
use Seat\Web\Http\Controllers\Controller;
abstract class BaseNotificationChannel extends Controller
{
    abstract protected function getSettingsView();
    abstract protected function getRegistrationView();
}

Add new notifications

If you want to extend the available notifications you need to extend the seat-notification array in config/services.php:

'seat-notification' => [
        'refresh_token' => Herpaderpaldent\Seat\SeatNotifications\Http\Controllers\Notifications\RefreshTokenController::class,
    ],

Your custom notification must contain the following public functions to add your notification to the users notification list:

public function getNotification()
    {
        return 'seatnotifications::refresh_token.notification';
    }
    public function getPrivateView()
    {
        return 'seatnotifications::refresh_token.private';
    }
    public function getChannelView()
    {
        return 'seatnotifications::refresh_token.channel';
    }

the functions should return a string containing the name of your view that should be rendered per column.