From bb5539f158f05a10881b82089230ab09f212c900 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 27 Jun 2022 22:25:57 +1000 Subject: [PATCH] Add callback_id to BlockActions, fix block::sections can also only have an accessory --- src/Blockkit/Blocks/Elements/Button.php | 8 ++++++++ src/Blockkit/Blocks/Section.php | 4 ++-- src/Interactive/BlockActions.php | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Blockkit/Blocks/Elements/Button.php b/src/Blockkit/Blocks/Elements/Button.php index 65cc630..fd65a3f 100644 --- a/src/Blockkit/Blocks/Elements/Button.php +++ b/src/Blockkit/Blocks/Elements/Button.php @@ -9,6 +9,7 @@ final class Button extends Element { protected const LIMITS = [ 'action_id' => 255, + 'callback_id' => 255, 'text' => 75, 'url' => 3000, 'value' => 2000, @@ -40,6 +41,13 @@ final class Button extends Element /* OPTIONAL ITEMS */ + public function callback_id(string $string): self + { + $this->callback_id = $string; + + return $this; + } + public function confirm(Confirm $confirm): self { $this->confirm = $confirm; diff --git a/src/Blockkit/Blocks/Section.php b/src/Blockkit/Blocks/Section.php index 18daf81..9728505 100644 --- a/src/Blockkit/Blocks/Section.php +++ b/src/Blockkit/Blocks/Section.php @@ -43,8 +43,8 @@ final class Section extends Blocks public function jsonSerialize() { - if (! $this->text && ! $this->fields) - throw new Exception('Must define text or fields'); + if (! $this->text && ! $this->fields && ! $this->accessory) + throw new Exception('Must define text, accessory or fields'); return parent::jsonSerialize(); } diff --git a/src/Interactive/BlockActions.php b/src/Interactive/BlockActions.php index 61db4dc..a547536 100644 --- a/src/Interactive/BlockActions.php +++ b/src/Interactive/BlockActions.php @@ -74,7 +74,13 @@ class BlockActions extends Base return object_get($this->_data,$key); case 'callback_id': - return object_get($this->_data,'view.callback_id'); + switch (object_get($this->_data,'type')) { + case 'block_actions': + return object_get(Arr::get(object_get($this->_data,'actions'),$this->index),$key); + // @todo Dont assume this is a view + default: + return object_get($this->_data,'view.callback_id'); + } case 'channel_id': return object_get($this->_data,'channel.id') ?: Channel::findOrFail($this->action('value'))->channel_id;