Skip to content

Commit

Permalink
Merge pull request #16451 from standaniels/slack-improvements
Browse files Browse the repository at this point in the history
[5.3] Slack improvements
  • Loading branch information
taylorotwell authored Nov 18, 2016
2 parents 8248c14 + 6d572ef commit d2bc064
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Illuminate/Notifications/Channels/SlackWebhookChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
82 changes: 82 additions & 0 deletions src/Illuminate/Notifications/Messages/SlackAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Notifications\Messages;

use Carbon\Carbon;

class SlackAttachment
{
/**
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
}
12 changes: 11 additions & 1 deletion tests/Notifications/NotificationSlackChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public function testCorrectPayloadIsSentToSlack()
'short' => true,
],
],
'mrkdwn_in' => ['text'],
'footer' => 'Laravel',
'footer_icon' => 'https://laravel.com/fake.png',
'ts' => 1234567890,
],
],
],
Expand Down Expand Up @@ -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);
});
}
}
Expand Down

0 comments on commit d2bc064

Please sign in to comment.