diff --git a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php index 0f4953174ec9..ab014d5ba4eb 100644 --- a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php +++ b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php @@ -82,6 +82,10 @@ protected function attachments(SlackMessage $message) 'text' => $attachment->content, 'title_link' => $attachment->url, 'fields' => $this->fields($attachment), + 'mrkdwn_in' => $attachment->markdown, + 'footer' => $attachment->footer, + 'footer_icon' => $attachment->footerIcon, + 'ts' => $attachment->timestamp, ]); })->all(); } diff --git a/src/Illuminate/Notifications/Messages/SlackAttachment.php b/src/Illuminate/Notifications/Messages/SlackAttachment.php index 11c740347512..2bf12d091381 100644 --- a/src/Illuminate/Notifications/Messages/SlackAttachment.php +++ b/src/Illuminate/Notifications/Messages/SlackAttachment.php @@ -2,6 +2,8 @@ namespace Illuminate\Notifications\Messages; +use Carbon\Carbon; + class SlackAttachment { /** @@ -39,6 +41,34 @@ class SlackAttachment */ public $fields; + /** + * The fields containing markdown. + * + * @var array + */ + public $markdown; + + /** + * The attachment's footer. + * + * @var string + */ + public $footer; + + /** + * The attachment's footer icon. + * + * @var string + */ + public $footerIcon; + + /** + * The attachment's timestamp. + * + * @var int + */ + public $timestamp; + /** * Set the title of the attachment. * @@ -92,4 +122,56 @@ public function fields(array $fields) return $this; } + + /** + * Set the fields containing markdown. + * + * @param array $fields + * @return $this + */ + public function markdown(array $fields) + { + $this->markdown = $fields; + + return $this; + } + + /** + * Set the footer content. + * + * @param string $footer + * @return $this + */ + public function footer($footer) + { + $this->footer = $footer; + + return $this; + } + + /** + * Set the footer icon. + * + * @param string $icon + * @return $this + */ + public function footerIcon($icon) + { + $this->footerIcon = $icon; + + return $this; + } + + /** + * Set the timestamp. + * + * @param Carbon $timestamp + * @return $this + */ + public function timestamp(Carbon $timestamp) + { + $this->timestamp = $timestamp->getTimestamp(); + + return $this; + } } diff --git a/tests/Notifications/NotificationSlackChannelTest.php b/tests/Notifications/NotificationSlackChannelTest.php index c169b944e700..d6ac7bdec196 100644 --- a/tests/Notifications/NotificationSlackChannelTest.php +++ b/tests/Notifications/NotificationSlackChannelTest.php @@ -49,6 +49,10 @@ public function testCorrectPayloadIsSentToSlack() 'short' => true, ], ], + 'mrkdwn_in' => ['text'], + 'footer' => 'Laravel', + 'footer_icon' => 'https://laravel.com/fake.png', + 'ts' => 1234567890, ], ], ], @@ -102,11 +106,17 @@ public function toSlack($notifiable) ->to('#ghost-talk') ->content('Content') ->attachment(function ($attachment) { + $timestamp = Mockery::mock('Carbon\Carbon'); + $timestamp->shouldReceive('getTimestamp')->andReturn(1234567890); $attachment->title('Laravel', 'https://laravel.com') ->content('Attachment Content') ->fields([ 'Project' => 'Laravel', - ]); + ]) + ->footer('Laravel') + ->footerIcon('https://laravel.com/fake.png') + ->markdown(['text']) + ->timestamp($timestamp); }); } }