149 lines
2.5 KiB
PHP
149 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Slack\Message;
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Slack\BlockKit;
|
|
use Slack\Blockkit\Blocks;
|
|
|
|
final class Attachment extends BlockKit
|
|
{
|
|
public const LIMITS = [
|
|
'footer' => 300,
|
|
];
|
|
|
|
public static function item(): self
|
|
{
|
|
return new self();
|
|
}
|
|
|
|
/* OPTIONAL ITEMS */
|
|
|
|
/**
|
|
* @note These are now legacy - use blocks instead
|
|
* @note more information on this available https://api.slack.com/legacy/interactive-message-field-guide
|
|
*/
|
|
public function addAction(AttachmentAction $action): self
|
|
{
|
|
if (! Arr::get($this->_data,'actions'))
|
|
$this->actions = collect();
|
|
|
|
$this->actions->push($action);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function addBlock(Blocks $block): self
|
|
{
|
|
if (! Arr::get($this->_data,'blocks'))
|
|
$this->blocks = collect();
|
|
|
|
$this->blocks->push($block);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function addField(string $title,string $value,bool $short): self
|
|
{
|
|
if (! Arr::get($this->_data,'fields'))
|
|
$this->fields = collect();
|
|
|
|
$this->fields->push(['title'=>$title,'value'=>$value,'short'=>$short]);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param string $string
|
|
* @return $this
|
|
* @note Can either be one of good (green), warning (yellow), danger (red), or any hex color code (eg. #439FE0)
|
|
*/
|
|
public function color(string $string): self
|
|
{
|
|
$this->color = $string;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param string $string
|
|
* @return $this
|
|
* @note Appears to be only used with actions
|
|
*/
|
|
public function callback_id(string $string): self
|
|
{
|
|
$this->callback_id = $string;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function fallback(string $string): self
|
|
{
|
|
$this->fallback = $string;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function footer(string $string): self
|
|
{
|
|
$this->footer = $this->validate('footer',$string);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function footer_icon(string $string): self
|
|
{
|
|
$this->footer_icon = $string;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set where markdown should be parsed by slack
|
|
*
|
|
* @param array $array
|
|
*/
|
|
public function mrkdwn_in(array $array): self
|
|
{
|
|
// @todo Add array check to make sure it has valid items
|
|
$this->mrkdwn_in = $array;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function pretext(string $string): self
|
|
{
|
|
$this->pretext = $string;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function text(string $string): self
|
|
{
|
|
$this->text = $string;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function title(string $string): self
|
|
{
|
|
$this->title = $string;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function title_link(string $string): self
|
|
{
|
|
$this->title_link = $string;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function ts(string $string): self
|
|
{
|
|
$this->ts = $string;
|
|
|
|
return $this;
|
|
}
|
|
} |