diff --git a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php index d58635ed85c4..afe370f7d11a 100644 --- a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php +++ b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php @@ -82,6 +82,9 @@ protected function attachments(SlackMessage $message) { return collect($message->attachments)->map(function ($attachment) use ($message) { return array_filter([ + 'author_icon' => $attachment->authorIcon, + 'author_link' => $attachment->authorLink, + 'author_name' => $attachment->authorName, 'color' => $attachment->color ?: $message->color(), 'fallback' => $attachment->fallback, 'fields' => $this->fields($attachment), diff --git a/src/Illuminate/Notifications/Messages/SlackAttachment.php b/src/Illuminate/Notifications/Messages/SlackAttachment.php index 20abbc2a516c..eed309f70f2e 100644 --- a/src/Illuminate/Notifications/Messages/SlackAttachment.php +++ b/src/Illuminate/Notifications/Messages/SlackAttachment.php @@ -92,6 +92,27 @@ class SlackAttachment */ public $timestamp; + /** + * The attachment's author name. + * + * @var string + */ + public $authorName; + + /** + * The attachment's author link. + * + * @var string + */ + public $authorLink; + + /** + * The attachment's author icon. + * + * @var string + */ + public $authorIcon; + /** * Set the title of the attachment. * @@ -260,4 +281,21 @@ public function timestamp($timestamp) return $this; } + + /** + * Set the author. + * + * @param string $name + * @param string $link + * @param string $icon + * @return $this + */ + public function author($name, $link = null, $icon = null) + { + $this->authorName = $name; + $this->authorLink = $link; + $this->authorIcon = $icon; + + return $this; + } } diff --git a/tests/Notifications/NotificationSlackChannelTest.php b/tests/Notifications/NotificationSlackChannelTest.php index 996914e61ef2..9903b9cc90ae 100644 --- a/tests/Notifications/NotificationSlackChannelTest.php +++ b/tests/Notifications/NotificationSlackChannelTest.php @@ -57,6 +57,9 @@ public function testCorrectPayloadIsSentToSlack() 'mrkdwn_in' => ['text'], 'footer' => 'Laravel', 'footer_icon' => 'https://laravel.com/fake.png', + 'author_name' => 'Author', + 'author_link' => 'https://laravel.com/fake_author', + 'author_icon' => 'https://laravel.com/fake_author.png', 'ts' => 1234567890, ], ], @@ -187,6 +190,7 @@ public function toSlack($notifiable) ->footer('Laravel') ->footerIcon('https://laravel.com/fake.png') ->markdown(['text']) + ->author('Author', 'https://laravel.com/fake_author', 'https://laravel.com/fake_author.png') ->timestamp($timestamp); }); }