Skip to content

Commit

Permalink
add support for new author fields in slack message attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghanlin committed Jan 2, 2018
1 parent 95407bd commit 0202391
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Illuminate/Notifications/Channels/SlackWebhookChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
38 changes: 38 additions & 0 deletions src/Illuminate/Notifications/Messages/SlackAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
}
4 changes: 4 additions & 0 deletions tests/Notifications/NotificationSlackChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
],
Expand Down Expand Up @@ -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);
});
}
Expand Down

0 comments on commit 0202391

Please sign in to comment.