Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Commit

Permalink
dded support for footer, footer_icon, ts and actions fields in attach…
Browse files Browse the repository at this point in the history
…ments (#34)
  • Loading branch information
pmishev authored and DZunke committed Sep 26, 2018
1 parent 2c760a6 commit ddd5792
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 17 deletions.
147 changes: 142 additions & 5 deletions Slack/Entity/MessageAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,50 @@ class MessageAttachment
protected $pretext;

/**
* A Bunch of Fields that should be displayed as Attachement. They consist of the Fields:
* Optional footer text
*
* @var string
*/
protected $footer;

/**
* Optional footer icon
*
* @var string
*/
protected $footerIcon;

/**
* Optional timestamp
*
* @var int
*/
protected $ts;

/**
* A Bunch of fields that should be displayed as Attachment. They consist of the fields:
*
* "title": The Header for this Field
* "value": The Textg for this Field, can be multiline
* "value": The Text for this Field, can be multiline
* "short": boolean to indicate if the field is short enough to be displayed side-by-side
*
* @var array
*/
protected $fields = [];

/**
* A Bunch of fields that should be displayed as button Attachment. They consist of the fields:
*
* "text": A UTF-8 string label for this button. Be brief but descriptive and actionable.
* "url": The fully qualified http or https URL to deliver users to. Invalid URLs will result in a message posted with the button omitted.
* "style": Optional - Setting to primary turns the button green and indicates the best forward action to take.
* Providing danger turns the button red and indicates it some kind of destructive action.
* Use sparingly. By default, buttons will use the UI's default text color.
*
* @var array
*/
protected $actions = [];

/**
* @return string
*/
Expand All @@ -103,6 +137,7 @@ public function getAuthorIcon()

/**
* @param string $authorIcon
*
* @return $this
*/
public function setAuthorIcon($authorIcon)
Expand All @@ -122,6 +157,7 @@ public function getAuthorLink()

/**
* @param string $authorLink
*
* @return $this
*/
public function setAuthorLink($authorLink)
Expand All @@ -141,6 +177,7 @@ public function getAuthorName()

/**
* @param string $authorName
*
* @return $this
*/
public function setAuthorName($authorName)
Expand All @@ -152,6 +189,7 @@ public function setAuthorName($authorName)

/**
* @param string $color
*
* @return $this
*/
public function setColor($color)
Expand All @@ -171,6 +209,7 @@ public function getColor()

/**
* @param string $fallback
*
* @return $this
*/
public function setFallback($fallback)
Expand Down Expand Up @@ -198,6 +237,7 @@ public function getImageUrl()

/**
* @param string $imageUrl
*
* @return $this
*/
public function setImageUrl($imageUrl)
Expand All @@ -209,6 +249,7 @@ public function setImageUrl($imageUrl)

/**
* @param array $fields
*
* @return $this
*/
public function setFields(array $fields)
Expand All @@ -228,9 +269,9 @@ public function setFields(array $fields)
public function addField($title, $text, $scale = false)
{
$this->fields[] = [
'title' => (string)$title,
'value' => (string)$text,
'short' => $scale
'title' => (string) $title,
'value' => (string) $text,
'short' => $scale,
];

return $this;
Expand All @@ -244,8 +285,48 @@ public function getFields()
return $this->fields;
}

/**
* @param array $actions
*
* @return $this
*/
public function setActions(array $actions)
{
$this->actions = $actions;

return $this;
}

/**
* @param string $text
* @param string $url
* @param string $style
*
* @return $this
*/
public function addAction($text, $url, $style = null)
{
$this->actions[] = [
'type' => 'button',
'text' => (string) $text,
'url' => (string) $url,
'style' => (string) $style,
];

return $this;
}

/**
* @return array
*/
public function getActions()
{
return $this->actions;
}

/**
* @param string $pretext
*
* @return $this
*/
public function setPretext($pretext)
Expand All @@ -265,6 +346,7 @@ public function getPretext()

/**
* @param string $text
*
* @return $this
*/
public function setText($text)
Expand Down Expand Up @@ -292,6 +374,7 @@ public function getTitle()

/**
* @param string $title
*
* @return $this
*/
public function setTitle($title)
Expand All @@ -311,6 +394,7 @@ public function getTitleLink()

/**
* @param string $titleLink
*
* @return $this
*/
public function setTitleLink($titleLink)
Expand All @@ -330,6 +414,7 @@ public function getThumbUrl()

/**
* @param string $thumbUrl
*
* @return $this
*/
public function setThumbUrl($thumbUrl)
Expand All @@ -339,6 +424,54 @@ public function setThumbUrl($thumbUrl)
return $this;
}

/**
* @return string
*/
public function getFooter()
{
return $this->footer;
}

/**
* @param string $footer
*/
public function setFooter($footer)
{
$this->footer = $footer;
}

/**
* @return string
*/
public function getFooterIcon()
{
return $this->footerIcon;
}

/**
* @param string $footerIcon
*/
public function setFooterIcon($footerIcon)
{
$this->footerIcon = $footerIcon;
}

/**
* @return int
*/
public function getTs()
{
return $this->ts;
}

/**
* @param int $ts
*/
public function setTs($ts)
{
$this->ts = $ts;
}

/**
* @return array
*/
Expand All @@ -357,6 +490,10 @@ public function toArray()
'fields' => $this->getFields(),
'image_url' => $this->getImageUrl(),
'thumb_url' => $this->getThumbUrl(),
'footer' => $this->getFooter(),
'footer_icon' => $this->getFooterIcon(),
'ts' => $this->getTs(),
'actions' => $this->getActions(),
];
}
}
27 changes: 15 additions & 12 deletions Slack/Messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Messaging
* @param Client $client
* @param IdentityBag $identityBag
*/
public function __construct(Client $client, IdentityBag $identityBag)
public function __construct(Client $client, IdentityBag $identityBag)
{
$this->client = $client;
$this->identityBag = $identityBag;
Expand All @@ -49,34 +49,37 @@ public function getClient()
* @param string $message
* @param string $identity
* @param Attachment[] $attachments
* @param array $clientOptions
*
* @return Client\Response|bool
*
* @throws \InvalidArgumentException
*/
public function message($channel, $message, $identity, array $attachments = [])
public function message($channel, $message, $identity, array $attachments = [], array $clientOptions = [])
{
if (!$this->identityBag->has($identity)) {
throw new \InvalidArgumentException('identity "' . $identity . '" is not registered');
throw new \InvalidArgumentException(sprintf('identity "%s" is not registered', $identity));
}

return $this->client->send(
Actions::ACTION_POST_MESSAGE,
[
array_merge([
'identity' => $this->identityBag->get($identity),
'channel' => $channel,
'text' => $message,
'attachments' => $attachments
],
$identity
'attachments' => $attachments,
], $clientOptions)
);
}


/**
* @param string|array $channel # String is DEPRECATED scince v1.3 - Deliver Array
* @param string $title
* @param string $file
* @param string|null $comment
* @return Client\Response
* @param string|array $channel # String is DEPRECATED scince v1.3 - Deliver Array
* @param string $title
* @param string $file
* @param string|null $comment
*
* @return Client\Response|false
*/
public function upload($channel, $title, $file, $comment = null)
{
Expand Down

0 comments on commit ddd5792

Please sign in to comment.