laravel / slack-notification-channel

Slack Notification Channel for laravel.
https://laravel.com/docs/notifications#slack-notifications
MIT License
869 stars 61 forks source link

Support disabling slack route dynamically when using `SlackWebhookChannel` #87

Closed marijoo closed 9 months ago

marijoo commented 9 months ago

As described in this issue there is a problem when using slack webhook handler and returning null dynamically in routeNotificationForSlack() i. e. if a slack webhook url can be configured on a user-level.

When returning null the application assumes SlackWebApiChannel should be used instead of SlackWebhookChannel which then leads to an error:

Illuminate\Notifications\Channels\SlackWebhookChannel::buildJsonPayload(): Argument #1 ($message) must be of type Illuminate\Notifications\Messages\SlackMessage, Illuminate\Notifications\Slack\SlackMessage given, called in vendor/laravel/slack-notification-channel/src/Channels/SlackWebhookChannel.php on line 43.

Returning a URL like https://hooks.slack.com/ would work, but would still send a post request to the given URL.

This PR allows returning false in routeNotificationForSlack() and would then stop the send process.