diff --git a/src/Attachment.php b/src/Attachment.php index 3ff4424..d0c3960 100644 --- a/src/Attachment.php +++ b/src/Attachment.php @@ -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. * @@ -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']); } @@ -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. * @@ -680,6 +714,7 @@ public function toArray() { $data = [ 'fallback' => $this->getFallback(), + 'callback_id' => $this->getCallback(), 'text' => $this->getText(), 'pretext' => $this->getPretext(), 'color' => $this->getColor(), diff --git a/src/AttachmentAction.php b/src/AttachmentAction.php index fe38073..77aa647 100644 --- a/src/AttachmentAction.php +++ b/src/AttachmentAction.php @@ -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; } @@ -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(), + ]; + } } }