From 8e5f0a0b8edb638b1644095344e21223298fd2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C5=A0ime=C4=8Dek?= Date: Wed, 26 Aug 2015 12:51:34 +0200 Subject: [PATCH 1/4] Message attachment extended to match full Slack's format. Fixed exception when wrong type is passed. --- .gitignore | 1 + Slack/Client/Actions/ChatPostMessage.php | 2 +- Slack/Entity/MessageAttachment.php | 196 ++++++++++++++++++++++- 3 files changed, 195 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b0def9a..bafea9d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock composer.phar vendor +.idea diff --git a/Slack/Client/Actions/ChatPostMessage.php b/Slack/Client/Actions/ChatPostMessage.php index 2bd6172..8651acf 100644 --- a/Slack/Client/Actions/ChatPostMessage.php +++ b/Slack/Client/Actions/ChatPostMessage.php @@ -48,7 +48,7 @@ private function parseAttachments() $attachments = []; foreach ($this->parameter['attachments'] as $attachmentObj) { if (!$attachmentObj instanceof Attachment) { - throw new \Exception('atachments must be instance of \DZunke\SlackBundle\Slack\Messaging\Attachment'); + throw new \Exception('atachments must be instance of \DZunke\SlackBundle\Slack\Entity\MessageAttachment'); } $attachments[] = $attachmentObj->toArray(); diff --git a/Slack/Entity/MessageAttachment.php b/Slack/Entity/MessageAttachment.php index 1e5a0a1..2568140 100644 --- a/Slack/Entity/MessageAttachment.php +++ b/Slack/Entity/MessageAttachment.php @@ -4,6 +4,27 @@ class MessageAttachment { + /** + * Optional link to author icon + * + * @var string URL address + */ + protected $authorIcon; + + /** + * Optional link to author + * + * @var string URL address + */ + protected $authorLink; + + /** + * Optional name of author + * + * @var string + */ + protected $authorName; + /** * Can either be one of 'good', 'warning', 'danger', or any hex color code * @@ -19,6 +40,13 @@ class MessageAttachment */ protected $fallback; + /** + * Optional link to image + * + * @var string URL address + */ + protected $imageUrl; + /** * Optional text that should appear within the attachment * @@ -26,6 +54,27 @@ class MessageAttachment */ protected $text; + /** + * Optional title + * + * @var string + */ + protected $title; + + /** + * Optional title link + * + * @var string + */ + protected $titleLink; + + /** + * Optional link to thumbnail + * + * @var string + */ + protected $thumbUrl; + /** * Optional text that should appear above the formatted data * @@ -44,6 +93,63 @@ class MessageAttachment */ protected $fields = []; + /** + * @return string + */ + public function getAuthorIcon() + { + return $this->authorIcon; + } + + /** + * @param string $authorIcon + * @return $this + */ + public function setAuthorIcon($authorIcon) + { + $this->authorIcon = $authorIcon; + + return $this; + } + + /** + * @return string + */ + public function getAuthorLink() + { + return $this->authorLink; + } + + /** + * @param string $authorLink + * @return $this + */ + public function setAuthorLink($authorLink) + { + $this->authorLink = $authorLink; + + return $this; + } + + /** + * @return string + */ + public function getAuthorName() + { + return $this->authorName; + } + + /** + * @param string $authorName + * @return $this + */ + public function setAuthorName($authorName) + { + $this->authorName = $authorName; + + return $this; + } + /** * @param string $color * @return $this @@ -82,6 +188,25 @@ public function getFallback() return $this->fallback; } + /** + * @return string + */ + public function getImageUrl() + { + return $this->imageUrl; + } + + /** + * @param string $imageUrl + * @return $this + */ + public function setImageUrl($imageUrl) + { + $this->imageUrl = $imageUrl; + + return $this; + } + /** * @param array $fields * @return $this @@ -155,6 +280,63 @@ public function getText() return $this->text; } + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return string + */ + public function getTitleLink() + { + return $this->titleLink; + } + + /** + * @param string $titleLink + * @return $this + */ + public function setTitleLink($titleLink) + { + $this->titleLink = $titleLink; + + return $this; + } + + /** + * @return string + */ + public function getThumbUrl() + { + return $this->thumbUrl; + } + + /** + * @param string $thumbUrl + * @return $this + */ + public function setThumbUrl($thumbUrl) + { + $this->thumbUrl = $thumbUrl; + + return $this; + } + /** * @return array */ @@ -162,9 +344,17 @@ public function toArray() { return [ 'fallback' => $this->getFallback(), - 'pretext' => $this->getPretext(), - 'color' => $this->getColor(), - 'fields' => $this->getFields() + 'color' => $this->getColor(), + 'pretext' => $this->getPretext(), + 'author_name' => $this->getAuthorName(), + 'author_link' => $this->getAuthorLink(), + 'author_icon' => $this->getAuthorIcon(), + 'title' => $this->getTitle(), + 'title_link' => $this->getTitleLink(), + 'text' => $this->getText(), + 'fields' => $this->getFields(), + 'image_url' => $this->getImageUrl(), + 'thumb_url' => $this->getThumbUrl(), ]; } } From 545fe1c0cf9d10a5385855a06e0a3f161eae8bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C5=A0ime=C4=8Dek?= Date: Wed, 26 Aug 2015 13:10:21 +0200 Subject: [PATCH 2/4] Fixed missing return tag on MessageAttachment --- Slack/Entity/MessageAttachment.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Slack/Entity/MessageAttachment.php b/Slack/Entity/MessageAttachment.php index 2568140..e4f64a5 100644 --- a/Slack/Entity/MessageAttachment.php +++ b/Slack/Entity/MessageAttachment.php @@ -232,6 +232,8 @@ public function addField($title, $text, $scale = false) 'value' => (string)$text, 'short' => $scale ]; + + return $this; } /** From 0d34984db5768a2873b11eebfb61d78f88019ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C5=A0ime=C4=8Dek?= Date: Wed, 26 Aug 2015 14:09:56 +0200 Subject: [PATCH 3/4] Removed Idea ide folder from gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index bafea9d..b0def9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ composer.lock composer.phar vendor -.idea From 88207a6fbf7de0d17286dd4bf311112ccee8d501 Mon Sep 17 00:00:00 2001 From: Denis Zunke Date: Wed, 26 Aug 2015 18:17:09 +0200 Subject: [PATCH 4/4] Add information about extended message attachment to changelog --- CHANGELOG | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 4c81f7b..a15edc0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ +SlackBundle v1.2.2 +================== +- Patch: MessageAttachment support complete attachment-api (by @shimmi) + SlackBundle v1.2.1 ================== -- Patch Feature: Customize icon_url and icon_emoji on single message-action +- Patch Feature: Customize icon_url and icon_emoji on single message-action (by @tobiassjosten) SlackBundle v1.2.0 ==================