Add callback_id to BlockActions, fix block::sections can also only have an accessory

This commit is contained in:
Deon George 2022-06-27 22:25:57 +10:00
parent 1e5281de29
commit bb5539f158
3 changed files with 17 additions and 3 deletions

View File

@ -9,6 +9,7 @@ final class Button extends Element
{ {
protected const LIMITS = [ protected const LIMITS = [
'action_id' => 255, 'action_id' => 255,
'callback_id' => 255,
'text' => 75, 'text' => 75,
'url' => 3000, 'url' => 3000,
'value' => 2000, 'value' => 2000,
@ -40,6 +41,13 @@ final class Button extends Element
/* OPTIONAL ITEMS */ /* OPTIONAL ITEMS */
public function callback_id(string $string): self
{
$this->callback_id = $string;
return $this;
}
public function confirm(Confirm $confirm): self public function confirm(Confirm $confirm): self
{ {
$this->confirm = $confirm; $this->confirm = $confirm;

View File

@ -43,8 +43,8 @@ final class Section extends Blocks
public function jsonSerialize() public function jsonSerialize()
{ {
if (! $this->text && ! $this->fields) if (! $this->text && ! $this->fields && ! $this->accessory)
throw new Exception('Must define text or fields'); throw new Exception('Must define text, accessory or fields');
return parent::jsonSerialize(); return parent::jsonSerialize();
} }

View File

@ -74,7 +74,13 @@ class BlockActions extends Base
return object_get($this->_data,$key); return object_get($this->_data,$key);
case 'callback_id': case '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'); return object_get($this->_data,'view.callback_id');
}
case 'channel_id': case 'channel_id':
return object_get($this->_data,'channel.id') ?: Channel::findOrFail($this->action('value'))->channel_id; return object_get($this->_data,'channel.id') ?: Channel::findOrFail($this->action('value'))->channel_id;