diff --git a/src/Blockkit/Blocks/Elements/ExternalSelect.php b/src/Blockkit/Blocks/Elements/ExternalSelect.php new file mode 100644 index 0000000..dbbd314 --- /dev/null +++ b/src/Blockkit/Blocks/Elements/ExternalSelect.php @@ -0,0 +1,77 @@ + 255, + 'placeholder' => 150, + ]; + + /** + * @param Text $placeholder + * @param string $action_id + * @throws Exception + */ + public function __construct(Text $placeholder,string $action_id) + { + parent::__construct(); + + // Defaults + $this->type = 'external_select'; + + if ($placeholder->type != 'plain_text') + throw new Exception(sprintf('Text must be plain_text not %s',$placeholder->type)); + + if (strlen($placeholder->text) > self::LIMITS['placeholder']) + throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['placeholder'])); + + $this->placeholder = $placeholder; + + $this->action_id = $this->validate('action_id',$action_id); + } + + public static function item(Text $placeholder,string $action_id): self + { + return new self($placeholder,$action_id); + } + + /* OPTIONAL ITEMS */ + + public function confirm(Confirm $confirm): self + { + $this->confirm = $confirm; + + return $this; + } + + // @note only 1 element in a view can have this set to true + public function focus_on_load(bool $bool): self + { + $this->focus_on_load = $bool; + + return $this; + } + + public function initial_option(string $option): self + { + $this->initial_option = $option; + + return $this; + } + + public function min_query_length(int $int): self + { + if ($int < 1) + throw new Exception('Minimum 1 options must be configured'); + + $this->min_query_length = $int; + + return $this; + } +} \ No newline at end of file diff --git a/src/Blockkit/Blocks/Elements/MultiExternalSelect.php b/src/Blockkit/Blocks/Elements/MultiExternalSelect.php index beb5808..21e9876 100644 --- a/src/Blockkit/Blocks/Elements/MultiExternalSelect.php +++ b/src/Blockkit/Blocks/Elements/MultiExternalSelect.php @@ -76,7 +76,7 @@ final class MultiExternalSelect extends Element if ($int < 1) throw new Exception('Minimum 1 options must be configured'); - $this->max_selected_items = $int; + $this->min_query_length = $int; return $this; } diff --git a/src/Blockkit/Blocks/Elements/PlaintTextInput.php b/src/Blockkit/Blocks/Elements/PlainTextInput.php similarity index 97% rename from src/Blockkit/Blocks/Elements/PlaintTextInput.php rename to src/Blockkit/Blocks/Elements/PlainTextInput.php index 4478673..812e585 100644 --- a/src/Blockkit/Blocks/Elements/PlaintTextInput.php +++ b/src/Blockkit/Blocks/Elements/PlainTextInput.php @@ -7,7 +7,7 @@ use Slack\Blockkit\Element; /** * This is an element of an input dialog */ -final class PlaintTextInput extends Element +final class PlainTextInput extends Element { protected const LIMITS = [ 'action_id' => 255, // @todo Should be unique for each message diff --git a/src/Blockkit/Blocks/Input.php b/src/Blockkit/Blocks/Input.php index 46f4c70..e6da7ec 100644 --- a/src/Blockkit/Blocks/Input.php +++ b/src/Blockkit/Blocks/Input.php @@ -15,7 +15,7 @@ final class Input extends Blocks ]; private const VALID_ELEMENTS = [ - Elements\PlaintTextInput::class, + Elements\PlainTextInput::class, Elements\MultiStaticSelect::class ]; diff --git a/src/Interactive/BlockActions.php b/src/Interactive/BlockActions.php index aa25961..09b1fc7 100644 --- a/src/Interactive/BlockActions.php +++ b/src/Interactive/BlockActions.php @@ -148,7 +148,7 @@ final class BlockActions extends Base * Separate out an action command to the id that the command relates to * * @param string $key - * @return string + * @return string|null * @throws SlackException */ private function action(string $key): ?string diff --git a/src/Interactive/ViewSubmission.php b/src/Interactive/ViewSubmission.php index bc89a8f..ee41176 100644 --- a/src/Interactive/ViewSubmission.php +++ b/src/Interactive/ViewSubmission.php @@ -7,6 +7,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; use Slack\Blockkit\Modal; +use Slack\Exceptions\SlackException; use Slack\Models\Team; /** @@ -27,8 +28,14 @@ class ViewSubmission extends Base case 'blocks': return collect(object_get($this->_data,'view.'.$key)); + case 'callback': + return object_get($this->_data,'view.callback_id'); + case 'callback_id': - return object_get($this->_data,'view.'.$key); + return $this->callback('id'); + + case 'callback_value': + return $this->callback('value'); case 'meta': return object_get($this->_data,'view.private_metadata'); @@ -44,6 +51,35 @@ class ViewSubmission extends Base } } + /** + * Separate out an callback command to the id that the command relates to + * + * @param string $key + * @return string|null + * @throws SlackException + */ + private function callback(string $key): ?string + { + $regex = '/^([a-z_]+)\|([0-9]+)$/'; + $id = NULL; + $value = NULL; + + if (preg_match($regex,$this->callback)) { + $id = preg_replace($regex,'$1',$this->callback); + $value = preg_replace($regex,'$2',$this->callback); + } + + switch ($key) { + case 'id': + return $id ?: $this->callback; + case 'value': + return $value; + + default: + throw new SlackException('Unknown key: '.$key); + } + } + /** * This method should be overridden by a local implementation * diff --git a/src/Options/Base.php b/src/Options/Base.php index 34c448f..9740a05 100644 --- a/src/Options/Base.php +++ b/src/Options/Base.php @@ -43,6 +43,10 @@ abstract class Base extends SlackBase return object_get($this->_data,'team.id'); case 'channel_id': return object_get($this->_data,'channel.id'); + + case 'enterprise_id': + return object_get($this->_data,'team.'.$key); + case 'user_id': return object_get($this->_data,'user.id');