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.

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()
    }

Register the Channel

Auto discovery is planned but till that gets implemented, you will need to add the new Notification Channel to the getChannels Collection in the Channel Service

    /**
     * @return Collection
     */
    protected static function getChannels(): Collection
    {
        return new Collection([
            new Discord(),
            new Slack()
        ]);
    }

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.