Skip to content

Notification Channels

Yorda edited this page Sep 3, 2022 · 3 revisions

Notification Strategy

Please review and understand that the major lift with adding additional notification channels is already done with the NotificationStrategy class.

Steps to Add new Notification Channels

Modifying the Configuration File

There are two required fields per channel that need to be added to the channels array in the config file.

  • enabled
    • Default this to false
  • hook
    • ensure this is pulling from the env('CHANNEL_HOOK').

Creating the Channel Class

Take a gander at the Discord Channel Notification

Create your new channel class in the YorCreative/Laravel-Query-Watcher/Strategies/NotificationStrategy/Channels namespace.

The new channel class needs to implement the NotificationChannelInterface.

You will need to pull the enabled field from the configuration file as shown.

    /**
     * @return bool
     */
    public function isEnabled(): bool
    {
        return config('querywatcher.channels.NEW_CHANNEL.enabled');
    }

Put your logic into the notify method as shown.

     /**
     * @param QueryModel $model
     */
    public function notify(QueryModel $model): void
    {
        // Build out your Web-hook payload using information in the QueryModel
       
        // Fire off a POST with Http::post()
    }

The NotificationStrategy will handle the rest.

Test Coverage

Please ensure you add at the very least basic test coverage using the current test coverage as an example.

Readme

Update the readme to reflect the new notification channel. Please include an article on how to retrieve the web-hook for the new notification channel.

Clone this wiki locally