Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class Attachment
*/
protected $fallback;

/**
* The callback_id for the button group.
*
* @var string
*/
protected $callback_id;

/**
* Optional text that should appear within the attachment.
*
Expand Down Expand Up @@ -139,6 +146,10 @@ public function __construct(array $attributes)
$this->setFallback($attributes['fallback']);
}

if (isset($attributes['callback_id'])) {
$this->setCallback($attributes['callback_id']);
}

if (isset($attributes['text'])) {
$this->setText($attributes['text']);
}
Expand Down Expand Up @@ -227,6 +238,29 @@ public function setFallback($fallback)
return $this;
}

/**
* Get the callback_id text.
*
* @return string
*/
public function getCallback()
{
return $this->callback_id;
}

/**
* Set the callback_id.
*
* @param string $callback_id
* @return $this
*/
public function setCallback($callback_id)
{
$this->callback_id = $callback_id;

return $this;
}

/**
* Get the optional text to appear within the attachment.
*
Expand Down Expand Up @@ -680,6 +714,7 @@ public function toArray()
{
$data = [
'fallback' => $this->getFallback(),
'callback_id' => $this->getCallback(),
'text' => $this->getText(),
'pretext' => $this->getPretext(),
'color' => $this->getColor(),
Expand Down
30 changes: 22 additions & 8 deletions src/AttachmentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ public function setConfirm($confirm)
} elseif (is_array($confirm)) {
$this->confirm = new ActionConfirmation($confirm);

return $this;
} elseif (! isset($confirm)) {
$this->confirm = null;

return $this;
}

Expand All @@ -216,13 +220,23 @@ public function setConfirm($confirm)
*/
public function toArray()
{
return [
'name' => $this->getName(),
'text' => $this->getText(),
'style' => $this->getStyle(),
'type' => $this->getType(),
'value' => $this->getValue(),
'confirm' => $this->getConfirm()->toArray(),
];
if ($this->getConfirm() != null) {
return [
'name' => $this->getName(),
'text' => $this->getText(),
'style' => $this->getStyle(),
'type' => $this->getType(),
'value' => $this->getValue(),
'confirm' => $this->getConfirm()->toArray(),
];
} else {
return [
'name' => $this->getName(),
'text' => $this->getText(),
'style' => $this->getStyle(),
'type' => $this->getType(),
'value' => $this->getValue(),
];
}
}
}