diff --git a/notifications.md b/notifications.md index 0530f20a7a..22dfc43038 100644 --- a/notifications.md +++ b/notifications.md @@ -521,6 +521,41 @@ The example above will create a Slack message that looks like the following: +#### Customizing the recipient + +Slack is fairly flexible, which allows us to override the custom webhook's channel by using the `to` method. This method accepts both `#channel` and `@username` notation. The latter will send the notification to a specific user. + + /** + * Get the Slack representation of the notification. + * + * @param mixed $notifiable + * @return SlackMessage + */ + public function toSlack($notifiable) + { + return (new SlackMessage) + ->to('#laravel-other'); + ->content('This will be posted in #laravel-other') + } + + +#### Customizing the bot's username and icon + +By default, the incoming webhook will use the default identity that you have configured in Slack, but with the `from` method it's trivial to set a custom username and icon: + + /** + * Get the Slack representation of the notification. + * + * @param mixed $notifiable + * @return SlackMessage + */ + public function toSlack($notifiable) + { + return (new SlackMessage) + ->from('Ghostbot', ':ghost:'); + ->content('Hello from Ghostbot!') + } + ### Routing Slack Notifications