diff --git a/src/Attachment.php b/src/Attachment.php index d0810d8..82c3659 100644 --- a/src/Attachment.php +++ b/src/Attachment.php @@ -18,6 +18,13 @@ class Attachment { */ protected $text; + /** + * Optional image that should appear within the attachment + * + * @var string + */ + protected $image_url; + /** * Optional text that should appear above the formatted data * @@ -59,6 +66,8 @@ public function __construct(array $attributes) if (isset($attributes['text'])) $this->setText($attributes['text']); + if (isset($attributes['image_url'])) $this->setImageUrl($attributes['image_url']); + if (isset($attributes['pretext'])) $this->setPretext($attributes['pretext']); if (isset($attributes['color'])) $this->setColor($attributes['color']); @@ -114,6 +123,29 @@ public function setText($text) return $this; } + /** + * Get the optional image to appear within the attachment + * + * @return string + */ + public function getImageUrl() + { + return $this->image_url; + } + + /** + * Set the optional image to appear within the attachment + * + * @param string $image_url + * @return $this + */ + public function setImageUrl($image_url) + { + $this->image_url = $image_url; + + return $this; + } + /** * Get the text that should appear above the formatted data * @@ -262,7 +294,8 @@ public function toArray() 'text' => $this->getText(), 'pretext' => $this->getPretext(), 'color' => $this->getColor(), - 'mrkdwn_in' => $this->getMarkdownFields() + 'mrkdwn_in' => $this->getMarkdownFields(), + 'image_url' => $this->getImageUrl() ]; $data['fields'] = $this->getFieldsAsArrays(); diff --git a/tests/AttachmentUnitTest.php b/tests/AttachmentUnitTest.php index 4bfe188..356b2dc 100644 --- a/tests/AttachmentUnitTest.php +++ b/tests/AttachmentUnitTest.php @@ -66,6 +66,7 @@ public function testAttachmentToArray() 'pretext' => 'Pretext', 'color' => 'bad', 'mrkdwn_in' => ['pretext', 'text'], + 'image_url' => 'http://fake.host/image.png', 'fields' => [ [ 'title' => 'Title 1', diff --git a/tests/ClientFunctionalTest.php b/tests/ClientFunctionalTest.php index b62a6f3..dd9840d 100644 --- a/tests/ClientFunctionalTest.php +++ b/tests/ClientFunctionalTest.php @@ -35,6 +35,7 @@ public function testMessageWithAttachments() 'pretext' => null, 'color' => 'bad', 'mrkdwn_in' => ['pretext', 'text'], + 'image_url' => 'http://fake.host/image.png', 'fields' => [] ]; @@ -73,6 +74,7 @@ public function testMessageWithAttachmentsAndFields() 'pretext' => null, 'color' => 'bad', 'mrkdwn_in' => [], + 'image_url' => 'http://fake.host/image.png', 'fields' => [ [ 'title' => 'Field 1',