Implemented SlackSyntaxException and removed some deprecated functions
This commit is contained in:
parent
4c7d18c6b0
commit
4ff944cb3a
42
src/API.php
42
src/API.php
@ -74,8 +74,8 @@ final class API
|
|||||||
/**
|
/**
|
||||||
* Delete a message in a channel
|
* Delete a message in a channel
|
||||||
*
|
*
|
||||||
* @param $channel
|
* @param string $channel
|
||||||
* @param $timestamp
|
* @param string $timestamp
|
||||||
* @return Generic
|
* @return Generic
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
@ -104,8 +104,8 @@ final class API
|
|||||||
/**
|
/**
|
||||||
* Get Messages on a channel from a specific timestamp
|
* Get Messages on a channel from a specific timestamp
|
||||||
*
|
*
|
||||||
* @param $channel
|
* @param string $channel
|
||||||
* @param $timestamp
|
* @param string $timestamp
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
* @return Generic
|
* @return Generic
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
@ -120,7 +120,7 @@ final class API
|
|||||||
/**
|
/**
|
||||||
* Get information on a channel.
|
* Get information on a channel.
|
||||||
*
|
*
|
||||||
* @param $channel
|
* @param string $channel
|
||||||
* @return Generic
|
* @return Generic
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
@ -177,7 +177,7 @@ final class API
|
|||||||
/**
|
/**
|
||||||
* Get information on a user
|
* Get information on a user
|
||||||
*
|
*
|
||||||
* @param $user_id
|
* @param string $user_id
|
||||||
* @return ResponseUser
|
* @return ResponseUser
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
@ -191,8 +191,8 @@ final class API
|
|||||||
/**
|
/**
|
||||||
* Get the list of channels for a user (the bot normally)
|
* Get the list of channels for a user (the bot normally)
|
||||||
*
|
*
|
||||||
* @param User $uo
|
* @param User $uo
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
* @param string|null $cursor
|
* @param string|null $cursor
|
||||||
* @return ChannelList
|
* @return ChannelList
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
@ -302,8 +302,8 @@ final class API
|
|||||||
/**
|
/**
|
||||||
* Remove a Pin from a message
|
* Remove a Pin from a message
|
||||||
*
|
*
|
||||||
* @param $channel
|
* @param string $channel
|
||||||
* @param $timestamp
|
* @param string $timestamp
|
||||||
* @return Generic
|
* @return Generic
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
@ -370,18 +370,26 @@ final class API
|
|||||||
* Call the Slack API
|
* Call the Slack API
|
||||||
*
|
*
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param null $parameters
|
* @param null $parameters
|
||||||
* @return object
|
* @return object
|
||||||
* @throws \Exception
|
* @throws SlackAlreadyPinnedException
|
||||||
|
* @throws SlackChannelNotFoundException
|
||||||
|
* @throws SlackException
|
||||||
|
* @throws SlackHashConflictException
|
||||||
|
* @throws SlackMessageNotFoundException
|
||||||
|
* @throws SlackNoAuthException
|
||||||
|
* @throws SlackNoPinException
|
||||||
|
* @throws SlackNotFoundException
|
||||||
|
* @throws SlackNotInChannelException
|
||||||
|
* @throws SlackThreadNotFoundException
|
||||||
|
* @throws SlackTokenScopeException
|
||||||
*/
|
*/
|
||||||
private function execute(string $method,$parameters=NULL): object
|
private function execute(string $method,$parameters=NULL): object
|
||||||
{
|
{
|
||||||
switch (config('app.env')) {
|
switch (config('app.env')) {
|
||||||
case 'dev': $url = 'http://steno:3000';
|
case 'steno': $url = 'http://steno:3000';
|
||||||
break;
|
break;
|
||||||
case 'testing': $url = 'http://localhost:3000';
|
case 'replay': $url = 'http://steno_replay:3000';
|
||||||
break;
|
|
||||||
case 'testing-l': $url = 'http://steno_replay:3000';
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$url = 'https://slack.com';
|
$url = 'https://slack.com';
|
||||||
@ -415,7 +423,7 @@ final class API
|
|||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception('Parameters unknown');
|
throw new SlackException('Parameters unknown');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -5,6 +5,8 @@ namespace Slack;
|
|||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BlockKit - Slack Blockit Objects
|
* Class BlockKit - Slack Blockit Objects
|
||||||
*
|
*
|
||||||
@ -40,7 +42,7 @@ abstract class BlockKit implements \JsonSerializable
|
|||||||
protected function validate(string $key,$value)
|
protected function validate(string $key,$value)
|
||||||
{
|
{
|
||||||
if (Arr::get(static::LIMITS,$key) && (strlen($value) > static::LIMITS[$key]))
|
if (Arr::get(static::LIMITS,$key) && (strlen($value) > static::LIMITS[$key]))
|
||||||
throw new Exception(sprintf('%s must be %d chars or less for buttons %s',$key,self::LIMITS[$key],get_class($this)));
|
throw new SlackSyntaxException(sprintf('%s must be %d chars or less for buttons %s',$key,static::LIMITS[$key],get_class($this)));
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks\Accessories;
|
namespace Slack\Blockkit\Blocks\Accessories;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use Slack\Blockkit\Blocks\Elements\{Confirm,Text};
|
use Slack\Blockkit\Blocks\Elements\{Confirm,Text};
|
||||||
use Slack\Blockkit\Element;
|
use Slack\Blockkit\Element;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class Overflow extends Element
|
final class Overflow extends Element
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ final class Overflow extends Element
|
|||||||
/**
|
/**
|
||||||
* @param string $action_id
|
* @param string $action_id
|
||||||
* @param Collection $options
|
* @param Collection $options
|
||||||
* @throws Exception
|
* @throws SlackSyntaxException
|
||||||
* @todo We dont handle option_groups yet.
|
* @todo We dont handle option_groups yet.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $action_id,Collection $options)
|
public function __construct(string $action_id,Collection $options)
|
||||||
@ -34,10 +34,10 @@ final class Overflow extends Element
|
|||||||
$this->action_id = $this->validate('action_id',$action_id);
|
$this->action_id = $this->validate('action_id',$action_id);
|
||||||
|
|
||||||
if (count($options) < self::MIN_OPTIONS)
|
if (count($options) < self::MIN_OPTIONS)
|
||||||
throw new Exception(sprintf('Must have atleast %d options',self::MIN_OPTIONS));
|
throw new SlackSyntaxException(sprintf('Must have atleast %d options',self::MIN_OPTIONS));
|
||||||
|
|
||||||
if (count($options) > self::MAX_OPTIONS)
|
if (count($options) > self::MAX_OPTIONS)
|
||||||
throw new Exception(sprintf('Can only have maximum %d options',self::MAX_OPTIONS));
|
throw new SlackSyntaxException(sprintf('Can only have maximum %d options',self::MAX_OPTIONS));
|
||||||
|
|
||||||
$this->options = $options->transform(function($item) {
|
$this->options = $options->transform(function($item) {
|
||||||
return ['text'=>Text::item(Arr::get($item,'name'),'plain_text'),'value'=>(string)Arr::get($item,'id')];
|
return ['text'=>Text::item(Arr::get($item,'name'),'plain_text'),'value'=>(string)Arr::get($item,'id')];
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks;
|
namespace Slack\Blockkit\Blocks;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use Slack\Blockkit\Blocks;
|
use Slack\Blockkit\Blocks;
|
||||||
use Slack\Blockkit\Blocks\Elements\{Button,MultiStaticSelect};
|
use Slack\Blockkit\Blocks\Elements\{Button,MultiStaticSelect};
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class Actions extends Blocks
|
final class Actions extends Blocks
|
||||||
{
|
{
|
||||||
@ -38,7 +38,7 @@ final class Actions extends Blocks
|
|||||||
public function jsonSerialize()
|
public function jsonSerialize()
|
||||||
{
|
{
|
||||||
if (! $this->elements)
|
if (! $this->elements)
|
||||||
throw new Exception('Must define at least 1 element');
|
throw new SlackSyntaxException('Must define at least 1 element');
|
||||||
|
|
||||||
return parent::jsonSerialize();
|
return parent::jsonSerialize();
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ final class Actions extends Blocks
|
|||||||
public function elements(Collection $collection): self
|
public function elements(Collection $collection): self
|
||||||
{
|
{
|
||||||
if (count($collection) > self::MAX_ELEMENTS)
|
if (count($collection) > self::MAX_ELEMENTS)
|
||||||
throw new Exception(sprintf('Can only have maximum %d elements',self::MAX_ELEMENTS));
|
throw new SlackSyntaxException(sprintf('Can only have maximum %d elements',self::MAX_ELEMENTS));
|
||||||
|
|
||||||
// @todo Check that a valid element is added. https://api.slack.com/reference/block-kit/blocks#actions
|
// @todo Check that a valid element is added. https://api.slack.com/reference/block-kit/blocks#actions
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks;
|
namespace Slack\Blockkit\Blocks;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use Slack\Blockkit\Blocks;
|
use Slack\Blockkit\Blocks;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class Context extends Blocks
|
final class Context extends Blocks
|
||||||
{
|
{
|
||||||
@ -17,7 +17,7 @@ final class Context extends Blocks
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $collection
|
* @param Collection $collection
|
||||||
* @throws Exception
|
* @throws SlackSyntaxException
|
||||||
* @todo Collection can only be image or text elements
|
* @todo Collection can only be image or text elements
|
||||||
*/
|
*/
|
||||||
public function __construct(Collection $collection)
|
public function __construct(Collection $collection)
|
||||||
@ -28,7 +28,7 @@ final class Context extends Blocks
|
|||||||
$this->type = 'context';
|
$this->type = 'context';
|
||||||
|
|
||||||
if (count($collection) > self::MAX_ELEMENTS)
|
if (count($collection) > self::MAX_ELEMENTS)
|
||||||
throw new Exception(sprintf('Can only have maximum %d elements',self::MAX_ELEMENTS));
|
throw new SlackSyntaxException(sprintf('Can only have maximum %d elements',self::MAX_ELEMENTS));
|
||||||
|
|
||||||
$this->elements = $collection;
|
$this->elements = $collection;
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks\Elements;
|
namespace Slack\Blockkit\Blocks\Elements;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
|
|
||||||
use Slack\Blockkit\Element;
|
use Slack\Blockkit\Element;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class Button extends Element
|
final class Button extends Element
|
||||||
{
|
{
|
||||||
@ -24,10 +23,10 @@ final class Button extends Element
|
|||||||
$this->type = 'button';
|
$this->type = 'button';
|
||||||
|
|
||||||
if ($text->type != 'plain_text')
|
if ($text->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$text->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$text->type));
|
||||||
|
|
||||||
if (strlen($text->text) > self::LIMITS['text'])
|
if (strlen($text->text) > self::LIMITS['text'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['text']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['text']));
|
||||||
|
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ final class Button extends Element
|
|||||||
public function style(string $string): self
|
public function style(string $string): self
|
||||||
{
|
{
|
||||||
if (! in_array($string,['default','primary','danger']))
|
if (! in_array($string,['default','primary','danger']))
|
||||||
throw new Exception(sprintf('Unknown style %s',$string));
|
throw new SlackSyntaxException(sprintf('Unknown style %s',$string));
|
||||||
|
|
||||||
$this->style = $string;
|
$this->style = $string;
|
||||||
|
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks\Elements;
|
namespace Slack\Blockkit\Blocks\Elements;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
|
|
||||||
use Slack\Blockkit\Element;
|
use Slack\Blockkit\Element;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class ExternalSelect extends Element
|
final class ExternalSelect extends Element
|
||||||
{
|
{
|
||||||
@ -16,7 +15,7 @@ final class ExternalSelect extends Element
|
|||||||
/**
|
/**
|
||||||
* @param Text $placeholder
|
* @param Text $placeholder
|
||||||
* @param string $action_id
|
* @param string $action_id
|
||||||
* @throws Exception
|
* @throws SlackSyntaxException
|
||||||
*/
|
*/
|
||||||
public function __construct(Text $placeholder,string $action_id)
|
public function __construct(Text $placeholder,string $action_id)
|
||||||
{
|
{
|
||||||
@ -26,10 +25,10 @@ final class ExternalSelect extends Element
|
|||||||
$this->type = 'external_select';
|
$this->type = 'external_select';
|
||||||
|
|
||||||
if ($placeholder->type != 'plain_text')
|
if ($placeholder->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$placeholder->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$placeholder->type));
|
||||||
|
|
||||||
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
|
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
|
||||||
|
|
||||||
$this->placeholder = $placeholder;
|
$this->placeholder = $placeholder;
|
||||||
|
|
||||||
@ -68,7 +67,7 @@ final class ExternalSelect extends Element
|
|||||||
public function min_query_length(int $int): self
|
public function min_query_length(int $int): self
|
||||||
{
|
{
|
||||||
if ($int < 1)
|
if ($int < 1)
|
||||||
throw new Exception('Minimum 1 options must be configured');
|
throw new SlackSyntaxException('Minimum 1 options must be configured');
|
||||||
|
|
||||||
$this->min_query_length = $int;
|
$this->min_query_length = $int;
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks\Elements;
|
namespace Slack\Blockkit\Blocks\Elements;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use Slack\Blockkit\Element;
|
use Slack\Blockkit\Element;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class MultiExternalSelect extends Element
|
final class MultiExternalSelect extends Element
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ final class MultiExternalSelect extends Element
|
|||||||
/**
|
/**
|
||||||
* @param Text $placeholder
|
* @param Text $placeholder
|
||||||
* @param string $action_id
|
* @param string $action_id
|
||||||
* @throws Exception
|
* @throws SlackSyntaxException
|
||||||
* @todo We dont handle option_groups yet.
|
* @todo We dont handle option_groups yet.
|
||||||
*/
|
*/
|
||||||
public function __construct(Text $placeholder,string $action_id)
|
public function __construct(Text $placeholder,string $action_id)
|
||||||
@ -32,10 +32,10 @@ final class MultiExternalSelect extends Element
|
|||||||
$this->type = 'multi_external_select';
|
$this->type = 'multi_external_select';
|
||||||
|
|
||||||
if ($placeholder->type != 'plain_text')
|
if ($placeholder->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$placeholder->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$placeholder->type));
|
||||||
|
|
||||||
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
|
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
|
||||||
|
|
||||||
$this->placeholder = $placeholder;
|
$this->placeholder = $placeholder;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ final class MultiExternalSelect extends Element
|
|||||||
public function min_query_length(int $int): self
|
public function min_query_length(int $int): self
|
||||||
{
|
{
|
||||||
if ($int < 1)
|
if ($int < 1)
|
||||||
throw new Exception('Minimum 1 options must be configured');
|
throw new SlackSyntaxException('Minimum 1 options must be configured');
|
||||||
|
|
||||||
$this->min_query_length = $int;
|
$this->min_query_length = $int;
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ final class MultiExternalSelect extends Element
|
|||||||
public function max_selected_items(int $int): self
|
public function max_selected_items(int $int): self
|
||||||
{
|
{
|
||||||
if ($int < 1)
|
if ($int < 1)
|
||||||
throw new Exception('Minimum 1 options must be configured');
|
throw new SlackSyntaxException('Minimum 1 options must be configured');
|
||||||
|
|
||||||
$this->max_selected_items = $int;
|
$this->max_selected_items = $int;
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks\Elements;
|
namespace Slack\Blockkit\Blocks\Elements;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use Slack\Blockkit\Element;
|
use Slack\Blockkit\Element;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class MultiStaticSelect extends Element
|
final class MultiStaticSelect extends Element
|
||||||
{
|
{
|
||||||
@ -22,7 +22,7 @@ final class MultiStaticSelect extends Element
|
|||||||
* @param Text $placeholder
|
* @param Text $placeholder
|
||||||
* @param string $action_id
|
* @param string $action_id
|
||||||
* @param Collection $options
|
* @param Collection $options
|
||||||
* @throws Exception
|
* @throws SlackSyntaxException
|
||||||
* @todo We dont handle option_groups yet.
|
* @todo We dont handle option_groups yet.
|
||||||
*/
|
*/
|
||||||
public function __construct(Text $placeholder,string $action_id,Collection $options)
|
public function __construct(Text $placeholder,string $action_id,Collection $options)
|
||||||
@ -33,20 +33,20 @@ final class MultiStaticSelect extends Element
|
|||||||
$this->type = 'multi_static_select';
|
$this->type = 'multi_static_select';
|
||||||
|
|
||||||
if ($placeholder->type != 'plain_text')
|
if ($placeholder->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$placeholder->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$placeholder->type));
|
||||||
|
|
||||||
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
|
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
|
||||||
|
|
||||||
$this->placeholder = $placeholder;
|
$this->placeholder = $placeholder;
|
||||||
|
|
||||||
$this->action_id = $this->validate('action_id',$action_id);
|
$this->action_id = $this->validate('action_id',$action_id);
|
||||||
|
|
||||||
if (! $options->count())
|
if (! $options->count())
|
||||||
throw new Exception('There are no options?');
|
throw new SlackSyntaxException('There are no options?');
|
||||||
|
|
||||||
if ($options->count() > self::MAX_OPTIONS)
|
if ($options->count() > self::MAX_OPTIONS)
|
||||||
throw new Exception(sprintf('Can only have maximum %d options',self::MAX_OPTIONS));
|
throw new SlackSyntaxException(sprintf('Can only have maximum %d options',self::MAX_OPTIONS));
|
||||||
|
|
||||||
$this->options = $options->transform(function($item) {
|
$this->options = $options->transform(function($item) {
|
||||||
return ['text'=>Text::item($item->name,'plain_text'),'value'=>(string)$item->value];
|
return ['text'=>Text::item($item->name,'plain_text'),'value'=>(string)$item->value];
|
||||||
@ -79,10 +79,10 @@ final class MultiStaticSelect extends Element
|
|||||||
// No initial options.
|
// No initial options.
|
||||||
if (count($initial)) {
|
if (count($initial)) {
|
||||||
if (! $this->options)
|
if (! $this->options)
|
||||||
throw new Exception('Cannot set an initial value without options defined first');
|
throw new SlackSyntaxException('Cannot set an initial value without options defined first');
|
||||||
|
|
||||||
if (count($initial) > self::MAX_OPTIONS)
|
if (count($initial) > self::MAX_OPTIONS)
|
||||||
throw new Exception(sprintf('Can only have maximum %d options',self::MAX_OPTIONS));
|
throw new SlackSyntaxException(sprintf('Can only have maximum %d options',self::MAX_OPTIONS));
|
||||||
|
|
||||||
$this->initial_options = $this->options->filter(function($item) use ($initial) { return in_array($item['value'],$initial); });
|
$this->initial_options = $this->options->filter(function($item) use ($initial) { return in_array($item['value'],$initial); });
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ final class MultiStaticSelect extends Element
|
|||||||
public function max_selected_items(int $int): self
|
public function max_selected_items(int $int): self
|
||||||
{
|
{
|
||||||
if ($int < 1)
|
if ($int < 1)
|
||||||
throw new Exception('Minimum 1 options must be configured');
|
throw new SlackSyntaxException('Minimum 1 options must be configured');
|
||||||
|
|
||||||
$this->max_selected_items = $int;
|
$this->max_selected_items = $int;
|
||||||
|
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks\Elements;
|
namespace Slack\Blockkit\Blocks\Elements;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
|
|
||||||
use Slack\Blockkit\Element;
|
use Slack\Blockkit\Element;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @note Overflow, select, and multi-select menus can only use plain_text objects,
|
* @note Overflow, select, and multi-select menus can only use plain_text objects,
|
||||||
@ -24,7 +23,7 @@ final class Options extends Element
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
if (strlen($text->text) > self::LIMITS['text'])
|
if (strlen($text->text) > self::LIMITS['text'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['text']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['text']));
|
||||||
|
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
$this->value = $this->validate('value',$value);
|
$this->value = $this->validate('value',$value);
|
||||||
@ -40,10 +39,10 @@ final class Options extends Element
|
|||||||
public function description(Text $text): self
|
public function description(Text $text): self
|
||||||
{
|
{
|
||||||
if ($text->type != 'plain_text')
|
if ($text->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$text->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$text->type));
|
||||||
|
|
||||||
if (strlen($text->text) > self::LIMITS['description'])
|
if (strlen($text->text) > self::LIMITS['description'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['description']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['description']));
|
||||||
|
|
||||||
$this->description = $text;
|
$this->description = $text;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Slack\Blockkit\Blocks\Elements;
|
namespace Slack\Blockkit\Blocks\Elements;
|
||||||
|
|
||||||
use Slack\Blockkit\Element;
|
use Slack\Blockkit\Element;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an element of an input dialog
|
* This is an element of an input dialog
|
||||||
@ -45,7 +46,7 @@ final class PlainTextInput extends Element
|
|||||||
public function min_length(int $int): self
|
public function min_length(int $int): self
|
||||||
{
|
{
|
||||||
if ($int > self::MAX_MIN_LENGTH)
|
if ($int > self::MAX_MIN_LENGTH)
|
||||||
throw new Exception(sprintf('min_length must be less than %d',self::MAX_MIN_LENGTH));
|
throw new SlackSyntaxException(sprintf('min_length must be less than %d',self::MAX_MIN_LENGTH));
|
||||||
|
|
||||||
$this->min_length = $int;
|
$this->min_length = $int;
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ final class PlainTextInput extends Element
|
|||||||
public function max_length(int $int): self
|
public function max_length(int $int): self
|
||||||
{
|
{
|
||||||
if ($this->min_length && ($int < $this->min_length))
|
if ($this->min_length && ($int < $this->min_length))
|
||||||
throw new Exception('max_length must be greater than min_length');
|
throw new SlackSyntaxException('max_length must be greater than min_length');
|
||||||
|
|
||||||
$this->max_length = $int;
|
$this->max_length = $int;
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ final class PlainTextInput extends Element
|
|||||||
public function placeholder(Text $text): self
|
public function placeholder(Text $text): self
|
||||||
{
|
{
|
||||||
if (strlen($text->text) > self::LIMITS['placeholder'])
|
if (strlen($text->text) > self::LIMITS['placeholder'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
|
||||||
|
|
||||||
$this->placeholder = $text;
|
$this->placeholder = $text;
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks\Elements;
|
namespace Slack\Blockkit\Blocks\Elements;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use Slack\Blockkit\Element;
|
use Slack\Blockkit\Element;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class StaticSelect extends Element
|
final class StaticSelect extends Element
|
||||||
{
|
{
|
||||||
@ -22,7 +22,7 @@ final class StaticSelect extends Element
|
|||||||
* @param Text $placeholder
|
* @param Text $placeholder
|
||||||
* @param string $action_id
|
* @param string $action_id
|
||||||
* @param Collection $options
|
* @param Collection $options
|
||||||
* @throws Exception
|
* @throws SlackSyntaxException
|
||||||
* @todo We dont handle option_groups yet.
|
* @todo We dont handle option_groups yet.
|
||||||
*/
|
*/
|
||||||
public function __construct(Text $placeholder,string $action_id,Collection $options)
|
public function __construct(Text $placeholder,string $action_id,Collection $options)
|
||||||
@ -33,20 +33,20 @@ final class StaticSelect extends Element
|
|||||||
$this->type = 'static_select';
|
$this->type = 'static_select';
|
||||||
|
|
||||||
if ($placeholder->type != 'plain_text')
|
if ($placeholder->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$placeholder->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$placeholder->type));
|
||||||
|
|
||||||
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
|
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
|
||||||
|
|
||||||
$this->placeholder = $placeholder;
|
$this->placeholder = $placeholder;
|
||||||
|
|
||||||
$this->action_id = $this->validate('action_id',$action_id);
|
$this->action_id = $this->validate('action_id',$action_id);
|
||||||
|
|
||||||
if (! $options->count())
|
if (! $options->count())
|
||||||
throw new Exception('There are no options?');
|
throw new SlackSyntaxException('There are no options?');
|
||||||
|
|
||||||
if ($options->count() > self::MAX_OPTIONS)
|
if ($options->count() > self::MAX_OPTIONS)
|
||||||
throw new Exception(sprintf('Can only have maximum %d options',self::MAX_OPTIONS));
|
throw new SlackSyntaxException(sprintf('Can only have maximum %d options',self::MAX_OPTIONS));
|
||||||
|
|
||||||
$this->options = $options->transform(function($item) {
|
$this->options = $options->transform(function($item) {
|
||||||
return ['text'=>Text::item($item->name,'plain_text'),'value'=>(string)$item->value];
|
return ['text'=>Text::item($item->name,'plain_text'),'value'=>(string)$item->value];
|
||||||
@ -77,7 +77,7 @@ final class StaticSelect extends Element
|
|||||||
public function initial_option(string $string=NULL): self
|
public function initial_option(string $string=NULL): self
|
||||||
{
|
{
|
||||||
if (! $this->options)
|
if (! $this->options)
|
||||||
throw new Exception('Cannot set an initial value without options defined first');
|
throw new SlackSyntaxException('Cannot set an initial value without options defined first');
|
||||||
|
|
||||||
if ($string)
|
if ($string)
|
||||||
$this->initial_option = $this->options->first(function($item) use ($string) { return $item['value'] == $string; });
|
$this->initial_option = $this->options->first(function($item) use ($string) { return $item['value'] == $string; });
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks\Elements;
|
namespace Slack\Blockkit\Blocks\Elements;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
|
|
||||||
use Slack\Blockkit\Element;
|
use Slack\Blockkit\Element;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class Text extends Element
|
final class Text extends Element
|
||||||
{
|
{
|
||||||
@ -15,7 +14,7 @@ final class Text extends Element
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
if (! in_array($type,self::TYPES))
|
if (! in_array($type,self::TYPES))
|
||||||
throw new Exception(sprintf('Type [%s] not valid',$type));
|
throw new SlackSyntaxException(sprintf('Type [%s] not valid',$type));
|
||||||
|
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
@ -31,7 +30,7 @@ final class Text extends Element
|
|||||||
public function emoji(bool $bool): self
|
public function emoji(bool $bool): self
|
||||||
{
|
{
|
||||||
if ($x=$this->type != 'plain_text')
|
if ($x=$this->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Cannnot use emoji when type is [%s]',$x));
|
throw new SlackSyntaxException(sprintf('Cannnot use emoji when type is [%s]',$x));
|
||||||
|
|
||||||
$this->emoji = $bool;
|
$this->emoji = $bool;
|
||||||
|
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks;
|
namespace Slack\Blockkit\Blocks;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
|
|
||||||
use Slack\Blockkit\Blocks;
|
use Slack\Blockkit\Blocks;
|
||||||
use Slack\Blockkit\Blocks\Elements\Text;
|
use Slack\Blockkit\Blocks\Elements\Text;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class Header extends Blocks
|
final class Header extends Blocks
|
||||||
{
|
{
|
||||||
@ -16,7 +15,7 @@ final class Header extends Blocks
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Text $text
|
* @param Text $text
|
||||||
* @throws Exception
|
* @throws SlackSyntaxException
|
||||||
*/
|
*/
|
||||||
public function __construct(Text $text)
|
public function __construct(Text $text)
|
||||||
{
|
{
|
||||||
@ -26,10 +25,10 @@ final class Header extends Blocks
|
|||||||
$this->type = 'header';
|
$this->type = 'header';
|
||||||
|
|
||||||
if ($text->type != 'plain_text')
|
if ($text->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$text->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$text->type));
|
||||||
|
|
||||||
if (strlen($text->text) > self::LIMITS['text'])
|
if (strlen($text->text) > self::LIMITS['text'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['text']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['text']));
|
||||||
|
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks;
|
namespace Slack\Blockkit\Blocks;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
|
|
||||||
use Slack\Blockkit\{Blocks,Element};
|
use Slack\Blockkit\{Blocks,Element};
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class Input extends Blocks
|
final class Input extends Blocks
|
||||||
{
|
{
|
||||||
@ -23,20 +22,20 @@ final class Input extends Blocks
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Elements\Text|null $label
|
* @param Elements\Text|null $label
|
||||||
* @throws Exception
|
* @throws SlackSyntaxException
|
||||||
*/
|
*/
|
||||||
public function __construct(Elements\Text $label=NULL)
|
public function __construct(Elements\Text $label=NULL)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
if ($label->type != 'plain_text')
|
if ($label->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$label->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$label->type));
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
$this->type = 'input';
|
$this->type = 'input';
|
||||||
|
|
||||||
if (strlen($label->text) > self::LIMITS['label'])
|
if (strlen($label->text) > self::LIMITS['label'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['label']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['label']));
|
||||||
|
|
||||||
$this->label = $label;
|
$this->label = $label;
|
||||||
}
|
}
|
||||||
@ -49,7 +48,7 @@ final class Input extends Blocks
|
|||||||
public function jsonSerialize()
|
public function jsonSerialize()
|
||||||
{
|
{
|
||||||
if (! $this->element)
|
if (! $this->element)
|
||||||
throw new Exception('Must define an element');
|
throw new SlackSyntaxException('Must define an element');
|
||||||
|
|
||||||
return parent::jsonSerialize();
|
return parent::jsonSerialize();
|
||||||
}
|
}
|
||||||
@ -66,7 +65,7 @@ final class Input extends Blocks
|
|||||||
public function element(Element $object): self
|
public function element(Element $object): self
|
||||||
{
|
{
|
||||||
if (! in_array(get_class($object),self::VALID_ELEMENTS))
|
if (! in_array(get_class($object),self::VALID_ELEMENTS))
|
||||||
throw new Exception(sprintf('Invalid element [%s] added to input',get_class($object)));
|
throw new SlackSyntaxException(sprintf('Invalid element [%s] added to input',get_class($object)));
|
||||||
|
|
||||||
$this->element = $object;
|
$this->element = $object;
|
||||||
|
|
||||||
@ -76,7 +75,7 @@ final class Input extends Blocks
|
|||||||
public function hint(Elements\Text $text): self
|
public function hint(Elements\Text $text): self
|
||||||
{
|
{
|
||||||
if (strlen($text->text) > self::LIMITS['hint'])
|
if (strlen($text->text) > self::LIMITS['hint'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['hint']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['hint']));
|
||||||
|
|
||||||
$this->hint = $text;
|
$this->hint = $text;
|
||||||
|
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit\Blocks;
|
namespace Slack\Blockkit\Blocks;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use Slack\Blockkit\{Blocks,Element};
|
use Slack\Blockkit\{Blocks,Element};
|
||||||
use Slack\BLockKit\Blocks\Elements\Text;
|
use Slack\BLockKit\Blocks\Elements\Text;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
final class Section extends Blocks
|
final class Section extends Blocks
|
||||||
{
|
{
|
||||||
@ -20,7 +20,7 @@ final class Section extends Blocks
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Text|NULL $text not required if fields is provided
|
* @param Text|NULL $text not required if fields is provided
|
||||||
* @throws Exception
|
* @throws SlackSyntaxException
|
||||||
*/
|
*/
|
||||||
public function __construct(Text $text=NULL)
|
public function __construct(Text $text=NULL)
|
||||||
{
|
{
|
||||||
@ -31,7 +31,7 @@ final class Section extends Blocks
|
|||||||
|
|
||||||
if ($text) {
|
if ($text) {
|
||||||
if (strlen($text->text) > self::LIMITS['text'])
|
if (strlen($text->text) > self::LIMITS['text'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['text']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['text']));
|
||||||
|
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ final class Section extends Blocks
|
|||||||
public function jsonSerialize()
|
public function jsonSerialize()
|
||||||
{
|
{
|
||||||
if (! $this->text && ! $this->fields && ! $this->accessory)
|
if (! $this->text && ! $this->fields && ! $this->accessory)
|
||||||
throw new Exception('Must define text, accessory or fields');
|
throw new SlackSyntaxException('Must define text, accessory or fields');
|
||||||
|
|
||||||
return parent::jsonSerialize();
|
return parent::jsonSerialize();
|
||||||
}
|
}
|
||||||
@ -69,10 +69,10 @@ final class Section extends Blocks
|
|||||||
public function fields(Collection $collection): self
|
public function fields(Collection $collection): self
|
||||||
{
|
{
|
||||||
if (count($collection) > self::MAX_FIELDS)
|
if (count($collection) > self::MAX_FIELDS)
|
||||||
throw new Exception(sprintf('Can only have maximum %d fields',self::MAX_FIELDS));
|
throw new SlackSyntaxException(sprintf('Can only have maximum %d fields',self::MAX_FIELDS));
|
||||||
|
|
||||||
if (($x=$collection->map(function($item) { return strlen($item->text); })->max()) > self::MAX_FIELDS_TEXT)
|
if (($x=$collection->map(function($item) { return strlen($item->text); })->max()) > self::MAX_FIELDS_TEXT)
|
||||||
throw new Exception(sprintf('The maximum size of the text in a field is %d (%d)',self::MAX_FIELDS_TEXT,$x));
|
throw new SlackSyntaxException(sprintf('The maximum size of the text in a field is %d (%d)',self::MAX_FIELDS_TEXT,$x));
|
||||||
|
|
||||||
$this->fields = $collection;
|
$this->fields = $collection;
|
||||||
|
|
||||||
|
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
namespace Slack\Blockkit;
|
namespace Slack\Blockkit;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
|
|
||||||
use Slack\BlockKit;
|
use Slack\BlockKit;
|
||||||
use Slack\Blockkit\Blocks\Divider;
|
use Slack\Blockkit\Blocks\Divider;
|
||||||
use Slack\Blockkit\Blocks\Elements\Text;
|
use Slack\Blockkit\Blocks\Elements\Text;
|
||||||
use Slack\Blockkit\Blocks\Section;
|
use Slack\Blockkit\Blocks\Section;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class creates a slack Modal Response
|
* This class creates a slack Modal Response
|
||||||
@ -31,17 +30,17 @@ final class Modal extends BlockKit
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
if (! in_array($type,['modal','home']))
|
if (! in_array($type,['modal','home']))
|
||||||
throw new Exception(sprintf('Unknown type %s',$type));
|
throw new SlackSyntaxException(sprintf('Unknown type %s',$type));
|
||||||
|
|
||||||
if ($type != 'modal' && $title)
|
if ($type != 'modal' && $title)
|
||||||
throw new Exception(sprintf('Titles are not required for %s',$type));
|
throw new SlackSyntaxException(sprintf('Titles are not required for %s',$type));
|
||||||
|
|
||||||
if ($title) {
|
if ($title) {
|
||||||
if ($title->type != 'plain_text')
|
if ($title->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$title->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$title->type));
|
||||||
|
|
||||||
if (strlen($title->text) > self::LIMITS['text'])
|
if (strlen($title->text) > self::LIMITS['text'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['text']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['text']));
|
||||||
|
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
}
|
}
|
||||||
@ -56,14 +55,14 @@ final class Modal extends BlockKit
|
|||||||
*
|
*
|
||||||
* @param Blocks $block
|
* @param Blocks $block
|
||||||
* @return $this
|
* @return $this
|
||||||
* @throws Exception
|
* @throws SlackSyntaxException
|
||||||
*/
|
*/
|
||||||
public function addBlock(Blocks $block): self
|
public function addBlock(Blocks $block): self
|
||||||
{
|
{
|
||||||
$this->blocks->push($block);
|
$this->blocks->push($block);
|
||||||
|
|
||||||
if ($x=$this->blocks->count() > self::MAX_BLOCKS)
|
if ($x=$this->blocks->count() > self::MAX_BLOCKS)
|
||||||
throw new Exception(sprintf('Modal can only have %d blocks',self::MAX_BLOCKS));
|
throw new SlackSyntaxException(sprintf('Modal can only have %d blocks',self::MAX_BLOCKS));
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -90,7 +89,7 @@ final class Modal extends BlockKit
|
|||||||
public function action(string $string)
|
public function action(string $string)
|
||||||
{
|
{
|
||||||
if (! in_array($string,['clear','update']))
|
if (! in_array($string,['clear','update']))
|
||||||
throw new Exception(sprintf('Unknown action %s',$string));
|
throw new SlackSyntaxException(sprintf('Unknown action %s',$string));
|
||||||
|
|
||||||
$this->action = $string;
|
$this->action = $string;
|
||||||
|
|
||||||
@ -100,7 +99,7 @@ final class Modal extends BlockKit
|
|||||||
public function clear_on_close(bool $bool): self
|
public function clear_on_close(bool $bool): self
|
||||||
{
|
{
|
||||||
if ($this->type != 'modal')
|
if ($this->type != 'modal')
|
||||||
throw new Exception(sprintf('clear_on_close is not required for %s',$type));
|
throw new SlackSyntaxException(sprintf('clear_on_close is not required for %s',$this->type));
|
||||||
|
|
||||||
$this->clear_on_close = $bool;
|
$this->clear_on_close = $bool;
|
||||||
|
|
||||||
@ -117,13 +116,13 @@ final class Modal extends BlockKit
|
|||||||
public function close(Text $text): self
|
public function close(Text $text): self
|
||||||
{
|
{
|
||||||
if ($this->type != 'modal')
|
if ($this->type != 'modal')
|
||||||
throw new Exception(sprintf('Close is not required for %s',$type));
|
throw new SlackSyntaxException(sprintf('Close is not required for %s',$this->type));
|
||||||
|
|
||||||
if ($text->type != 'plain_text')
|
if ($text->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$text->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$text->type));
|
||||||
|
|
||||||
if (strlen($text->text) > self::LIMITS['close'])
|
if (strlen($text->text) > self::LIMITS['close'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['close']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['close']));
|
||||||
|
|
||||||
$this->close = $text;
|
$this->close = $text;
|
||||||
|
|
||||||
@ -153,7 +152,7 @@ final class Modal extends BlockKit
|
|||||||
public function notify_on_close(bool $bool): self
|
public function notify_on_close(bool $bool): self
|
||||||
{
|
{
|
||||||
if ($this->type != 'modal')
|
if ($this->type != 'modal')
|
||||||
throw new Exception(sprintf('notify_on_close is not required for %s',$type));
|
throw new SlackSyntaxException(sprintf('notify_on_close is not required for %s',$this->type));
|
||||||
|
|
||||||
$this->notify_on_close = $bool;
|
$this->notify_on_close = $bool;
|
||||||
|
|
||||||
@ -178,13 +177,13 @@ final class Modal extends BlockKit
|
|||||||
public function submit(Text $text): self
|
public function submit(Text $text): self
|
||||||
{
|
{
|
||||||
if ($this->type != 'modal')
|
if ($this->type != 'modal')
|
||||||
throw new Exception(sprintf('Submit is not required for %s',$type));
|
throw new SlackSyntaxException(sprintf('Submit is not required for %s',$this->type));
|
||||||
|
|
||||||
if ($text->type != 'plain_text')
|
if ($text->type != 'plain_text')
|
||||||
throw new Exception(sprintf('Text must be plain_text not %s',$text->type));
|
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$text->type));
|
||||||
|
|
||||||
if (strlen($text->text) > self::LIMITS['submit'])
|
if (strlen($text->text) > self::LIMITS['submit'])
|
||||||
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['submit']));
|
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['submit']));
|
||||||
|
|
||||||
$this->submit = $text;
|
$this->submit = $text;
|
||||||
|
|
||||||
@ -194,24 +193,10 @@ final class Modal extends BlockKit
|
|||||||
public function submit_disabled(bool $bool): self
|
public function submit_disabled(bool $bool): self
|
||||||
{
|
{
|
||||||
if ($this->type != 'modal')
|
if ($this->type != 'modal')
|
||||||
throw new Exception(sprintf('submit_disabled is not required for %s',$type));
|
throw new SlackSyntaxException(sprintf('submit_disabled is not required for %s',$this->type));
|
||||||
|
|
||||||
$this->submit_disabled = $bool;
|
$this->submit_disabled = $bool;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a block to the modal
|
|
||||||
*
|
|
||||||
* @param Blocks $blocks
|
|
||||||
* @return $this
|
|
||||||
* @deprecated use addBlock() instead
|
|
||||||
*/
|
|
||||||
public function setBlocks(Blocks $blocks): self
|
|
||||||
{
|
|
||||||
$this->_data->put('blocks',$blocks);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -9,6 +9,7 @@ use React\EventLoop\Loop;
|
|||||||
use Slack\Client\SocketMode;
|
use Slack\Client\SocketMode;
|
||||||
use Slack\Command\Factory as SlackCommandFactory;
|
use Slack\Command\Factory as SlackCommandFactory;
|
||||||
use Slack\Event\Factory as SlackEventFactory;
|
use Slack\Event\Factory as SlackEventFactory;
|
||||||
|
use Slack\Exceptions\SlackException;
|
||||||
use Slack\Interactive\Factory as SlackInteractiveFactory;
|
use Slack\Interactive\Factory as SlackInteractiveFactory;
|
||||||
|
|
||||||
class SlackSocketClient extends Command
|
class SlackSocketClient extends Command
|
||||||
@ -33,13 +34,13 @@ class SlackSocketClient extends Command
|
|||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Exception
|
* @throws SlackException
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
// Make sure our socket_token is defined
|
// Make sure our socket_token is defined
|
||||||
if (! config('slack.socket_token'))
|
if (! config('slack.socket_token'))
|
||||||
throw new \Exception('SocketMode Client Token not defined.');
|
throw new SlackException('SocketMode Client Token not defined.');
|
||||||
|
|
||||||
$loop = Loop::get();
|
$loop = Loop::get();
|
||||||
|
|
||||||
|
7
src/Exceptions/SlackSyntaxException.php
Normal file
7
src/Exceptions/SlackSyntaxException.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Slack\Exceptions;
|
||||||
|
|
||||||
|
class SlackSyntaxException extends SlackException
|
||||||
|
{
|
||||||
|
}
|
@ -18,7 +18,6 @@ final class InteractiveOptionsController extends Controller
|
|||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \Illuminate\Http\Response|\Laravel\Lumen\Http\ResponseFactory
|
* @return \Illuminate\Http\Response|\Laravel\Lumen\Http\ResponseFactory
|
||||||
* @throws \Exception
|
|
||||||
*/
|
*/
|
||||||
public function fire(Request $request)
|
public function fire(Request $request)
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,6 @@ namespace Slack\Interactive;
|
|||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use Slack\Exceptions\SlackException;
|
|
||||||
use Slack\Models\Channel;
|
use Slack\Models\Channel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,7 +92,7 @@ final class BlockActions extends Base
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new SlackException('Unknown container type: '.$this->container_type);
|
throw new \Exception('Unknown container type: '.$this->container_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'container_type':
|
case 'container_type':
|
||||||
@ -143,7 +142,7 @@ final class BlockActions extends Base
|
|||||||
// @todo To Check
|
// @todo To Check
|
||||||
case 'overflow':
|
case 'overflow':
|
||||||
// @todo To Check
|
// @todo To Check
|
||||||
throw new SlackException('To be implemented: ',$x);
|
throw new \Exception('To be implemented: ',$x);
|
||||||
case 'static_select':
|
case 'static_select':
|
||||||
return count(object_get($this->action,'selected_option'));
|
return count(object_get($this->action,'selected_option'));
|
||||||
case 'multi_static_select':
|
case 'multi_static_select':
|
||||||
@ -162,7 +161,7 @@ final class BlockActions extends Base
|
|||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return string|null
|
* @return string|null
|
||||||
* @throws SlackException
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private function action(string $key): ?string
|
private function action(string $key): ?string
|
||||||
{
|
{
|
||||||
@ -185,7 +184,7 @@ final class BlockActions extends Base
|
|||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new SlackException('Unknown key: '.$key);
|
throw new \Exception('Unknown key: '.$key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,13 +2,9 @@
|
|||||||
|
|
||||||
namespace Slack\Interactive;
|
namespace Slack\Interactive;
|
||||||
|
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use Slack\Blockkit\Modal;
|
use Slack\Blockkit\Modal;
|
||||||
use Slack\Exceptions\SlackException;
|
|
||||||
use Slack\Models\Team;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Incoming modal view submission event.
|
* Incoming modal view submission event.
|
||||||
@ -56,7 +52,7 @@ class ViewSubmission extends Base
|
|||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return string|null
|
* @return string|null
|
||||||
* @throws SlackException
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private function callback(string $key): ?string
|
private function callback(string $key): ?string
|
||||||
{
|
{
|
||||||
@ -76,7 +72,7 @@ class ViewSubmission extends Base
|
|||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new SlackException('Unknown key: '.$key);
|
throw new \Exception('Unknown key: '.$key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +80,6 @@ class ViewSubmission extends Base
|
|||||||
* This method should be overridden by a local implementation
|
* This method should be overridden by a local implementation
|
||||||
*
|
*
|
||||||
* @return Modal
|
* @return Modal
|
||||||
* @throws \Exception
|
|
||||||
*/
|
*/
|
||||||
public function respond(): Modal
|
public function respond(): Modal
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@ final class DeleteResponse extends Job
|
|||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @throws \Exception
|
|
||||||
*/
|
*/
|
||||||
public function __construct(string $url)
|
public function __construct(string $url)
|
||||||
{
|
{
|
||||||
@ -26,7 +25,6 @@ final class DeleteResponse extends Job
|
|||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Exception
|
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
122
src/Message.php
122
src/Message.php
@ -12,8 +12,8 @@ use Illuminate\Support\Facades\Log;
|
|||||||
use Slack\Blockkit\Blocks;
|
use Slack\Blockkit\Blocks;
|
||||||
use Slack\Blockkit\Blocks\Context;
|
use Slack\Blockkit\Blocks\Context;
|
||||||
use Slack\Blockkit\Blocks\Elements\Text;
|
use Slack\Blockkit\Blocks\Elements\Text;
|
||||||
use Slack\Exceptions\SlackException;
|
use Slack\Exceptions\{SlackException,SlackSyntaxException};
|
||||||
use Slack\Jobs\DeleteChat;
|
use Slack\Jobs\{DeleteChat,DeleteResponse};
|
||||||
use Slack\Message\Attachment;
|
use Slack\Message\Attachment;
|
||||||
use Slack\Models\{Channel,User};
|
use Slack\Models\{Channel,User};
|
||||||
use Slack\Response\Generic;
|
use Slack\Response\Generic;
|
||||||
@ -34,7 +34,7 @@ final class Message extends BlockKit
|
|||||||
* Message constructor.
|
* Message constructor.
|
||||||
*
|
*
|
||||||
* @param Model|null $o Who the message will be to - Channel or User
|
* @param Model|null $o Who the message will be to - Channel or User
|
||||||
* @throws SlackException
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function __construct(Model $o=NULL)
|
public function __construct(Model $o=NULL)
|
||||||
{
|
{
|
||||||
@ -50,7 +50,7 @@ final class Message extends BlockKit
|
|||||||
$this->setUser($o);
|
$this->setUser($o);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new SlackException('Model not handled: '.get_class($o));
|
throw new \Exception('Model not handled: '.get_class($o));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->o = $o;
|
$this->o = $o;
|
||||||
@ -72,9 +72,9 @@ final class Message extends BlockKit
|
|||||||
/**
|
/**
|
||||||
* Add a block to the message
|
* Add a block to the message
|
||||||
*
|
*
|
||||||
* @param Blocks $blocks
|
* @param Attachment $attachment
|
||||||
* @return Message
|
* @return Message
|
||||||
* @todo to test
|
* @throws SlackSyntaxException
|
||||||
*/
|
*/
|
||||||
public function addAttachment(Attachment $attachment): self
|
public function addAttachment(Attachment $attachment): self
|
||||||
{
|
{
|
||||||
@ -84,7 +84,7 @@ final class Message extends BlockKit
|
|||||||
$this->attachments->push($attachment);
|
$this->attachments->push($attachment);
|
||||||
|
|
||||||
if (count($this->attachments) > self::MAX_ATTACHMENTS)
|
if (count($this->attachments) > self::MAX_ATTACHMENTS)
|
||||||
throw new Exception(sprintf('Messages should not have more than %d attachments',self::MAX_ATTACHMENTS));
|
throw new SlackSyntaxException(sprintf('Messages should not have more than %d attachments',self::MAX_ATTACHMENTS));
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ final class Message extends BlockKit
|
|||||||
*/
|
*/
|
||||||
public function isEmpty(): bool
|
public function isEmpty(): bool
|
||||||
{
|
{
|
||||||
return $this->jsonSerialize() ? FALSE : TRUE;
|
return ! $this->jsonSerialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,14 +157,17 @@ final class Message extends BlockKit
|
|||||||
if (! $delete && $this->selfdestruct)
|
if (! $delete && $this->selfdestruct)
|
||||||
$delete = $this->selfdestruct;
|
$delete = $this->selfdestruct;
|
||||||
|
|
||||||
if ($this->_data->has('ephemeral'))
|
|
||||||
abort('500','Cannot post ephemeral messages.');
|
|
||||||
|
|
||||||
if ($this->_data->get('blocks') && $this->_data->get('attachments'))
|
if ($this->_data->get('blocks') && $this->_data->get('attachments'))
|
||||||
throw new SlackException('Message cannot have blocks and attachments.');
|
throw new SlackSyntaxException('Message cannot have blocks and attachments.');
|
||||||
|
|
||||||
$api = $this->o->team->slackAPI();
|
$api = $this->o->team->slackAPI();
|
||||||
$response = $this->_data->has('ts') ? $api->updateMessage($this) : $api->postMessage($this);
|
|
||||||
|
if ($this->ephemeral) {
|
||||||
|
$response = $api->postEphemeral($this);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$response = $this->_data->has('ts') ? $api->updateMessage($this) : $api->postMessage($this);
|
||||||
|
}
|
||||||
|
|
||||||
if ($delete) {
|
if ($delete) {
|
||||||
Log::debug(sprintf('%s:Scheduling Delete of [%s:%s] on [%s]',static::LOGKEY,object_get($this->o,'channel_id',$this->o->id),$response->ts,$delete->format('Y-m-d')),['m'=>__METHOD__]);
|
Log::debug(sprintf('%s:Scheduling Delete of [%s:%s] on [%s]',static::LOGKEY,object_get($this->o,'channel_id',$this->o->id),$response->ts,$delete->format('Y-m-d')),['m'=>__METHOD__]);
|
||||||
@ -181,11 +184,15 @@ final class Message extends BlockKit
|
|||||||
*
|
*
|
||||||
* @note This URL can only be used 5 times in 30 minutes
|
* @note This URL can only be used 5 times in 30 minutes
|
||||||
* @param string $url
|
* @param string $url
|
||||||
|
* @param Carbon|null $delete
|
||||||
* @return string
|
* @return string
|
||||||
* @throws SlackException
|
* @throws SlackException
|
||||||
*/
|
*/
|
||||||
public function respond(string $url)
|
public function respond(string $url,Carbon $delete=NULL)
|
||||||
{
|
{
|
||||||
|
if (! $delete && $this->selfdestruct)
|
||||||
|
$delete = $this->selfdestruct;
|
||||||
|
|
||||||
$request = curl_init();
|
$request = curl_init();
|
||||||
|
|
||||||
curl_setopt($request,CURLOPT_URL,$url);
|
curl_setopt($request,CURLOPT_URL,$url);
|
||||||
@ -216,6 +223,13 @@ final class Message extends BlockKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($delete) {
|
||||||
|
Log::debug(sprintf('%s:Scheduling Delete of [%s:%s] on [%s]',static::LOGKEY,object_get($this->o,'channel_id',$this->o->id),$response->ts,$delete->format('Y-m-d')),['m'=>__METHOD__]);
|
||||||
|
|
||||||
|
// Queue the delete of the response if requested
|
||||||
|
dispatch((new DeleteResponse($url))->onQueue('slack')->delay($delete));
|
||||||
|
}
|
||||||
|
|
||||||
curl_close($request);
|
curl_close($request);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -251,6 +265,7 @@ final class Message extends BlockKit
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->selfdestruct = $time;
|
$this->selfdestruct = $time;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +301,6 @@ final class Message extends BlockKit
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Message
|
* @return Message
|
||||||
* @todo - Check this is a valid option
|
|
||||||
*/
|
*/
|
||||||
public function ephemeral(): self
|
public function ephemeral(): self
|
||||||
{
|
{
|
||||||
@ -323,8 +337,10 @@ final class Message extends BlockKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Replace the original message
|
||||||
|
*
|
||||||
|
* @param bool $bool
|
||||||
* @return Message
|
* @return Message
|
||||||
* @todo - Check this is a valid option
|
|
||||||
*/
|
*/
|
||||||
public function replace_original(bool $bool=TRUE): self
|
public function replace_original(bool $bool=TRUE): self
|
||||||
{
|
{
|
||||||
@ -391,78 +407,4 @@ final class Message extends BlockKit
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an attachment to a message
|
|
||||||
*
|
|
||||||
* @param Attachment $attachments
|
|
||||||
* @return Message
|
|
||||||
* @deprecated use addAttachment()
|
|
||||||
*/
|
|
||||||
public function setAttachments(Attachment $attachments): self
|
|
||||||
{
|
|
||||||
$this->_data->put('attachments',[$attachments]);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add blocks to the message
|
|
||||||
*
|
|
||||||
* @param Blocks $blocks
|
|
||||||
* @return Message
|
|
||||||
* @throws \Exception
|
|
||||||
* @deprecated use addBlocks()
|
|
||||||
*/
|
|
||||||
public function setBlocks(Blocks $blocks): self
|
|
||||||
{
|
|
||||||
if ($this->blocks->count())
|
|
||||||
throw new \Exception('Blocks already defined');
|
|
||||||
|
|
||||||
$this->blocks = $blocks;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message text
|
|
||||||
*
|
|
||||||
* @param string $string
|
|
||||||
* @return Message
|
|
||||||
* @deprecated use text()
|
|
||||||
*/
|
|
||||||
public function setText(string $string): self
|
|
||||||
{
|
|
||||||
$this->text = $string;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the timestamp, used when replacing messages
|
|
||||||
*
|
|
||||||
* @param string $string
|
|
||||||
* @return Message
|
|
||||||
* @deprecated use ts()
|
|
||||||
*/
|
|
||||||
public function setTS(string $string): self
|
|
||||||
{
|
|
||||||
$this->_data->put('ts',$string);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the thread timestamp, used when adding a threaded response
|
|
||||||
*
|
|
||||||
* @param string $string
|
|
||||||
* @return Message
|
|
||||||
* @deprecated use thead_ts()
|
|
||||||
*/
|
|
||||||
public function setThreadTS(string $string): self
|
|
||||||
{
|
|
||||||
$this->_data->put('thread_ts',$string);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Slack\Message;
|
namespace Slack\Message;
|
||||||
|
|
||||||
use \Exception;
|
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
use Slack\BlockKit;
|
use Slack\BlockKit;
|
||||||
|
@ -4,6 +4,7 @@ namespace Slack\Message;
|
|||||||
|
|
||||||
use Slack\BlockKit;
|
use Slack\BlockKit;
|
||||||
use Slack\Blockkit\Blocks\Elements\Text;
|
use Slack\Blockkit\Blocks\Elements\Text;
|
||||||
|
use Slack\Exceptions\SlackSyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MessageAttachmentAction - Slack Message Attachments Actions
|
* Class MessageAttachmentAction - Slack Message Attachments Actions
|
||||||
@ -33,7 +34,7 @@ final class AttachmentAction extends BlockKit
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
if (! in_array($type,self::TYPES))
|
if (! in_array($type,self::TYPES))
|
||||||
throw new Exception(sprintf('Type [%s] not valid',$type));
|
throw new SlackSyntaxException(sprintf('Type [%s] not valid',$type));
|
||||||
|
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
@ -80,7 +81,7 @@ final class AttachmentAction extends BlockKit
|
|||||||
public function data_source(string $string): self
|
public function data_source(string $string): self
|
||||||
{
|
{
|
||||||
if (! in_array($string,self::DATA_SOURCES))
|
if (! in_array($string,self::DATA_SOURCES))
|
||||||
throw new Exception(sprintf('Type [%s] not valid',$string));
|
throw new SlackSyntaxException(sprintf('Type [%s] not valid',$string));
|
||||||
|
|
||||||
$this->data_source = $string;
|
$this->data_source = $string;
|
||||||
|
|
||||||
@ -97,13 +98,14 @@ final class AttachmentAction extends BlockKit
|
|||||||
/**
|
/**
|
||||||
* Set the text displayed in the action
|
* Set the text displayed in the action
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $string
|
||||||
* @return $this
|
* @return $this
|
||||||
|
* @throws SlackSyntaxException
|
||||||
*/
|
*/
|
||||||
public function style(string $string): self
|
public function style(string $string): self
|
||||||
{
|
{
|
||||||
if (! in_array($string,self::STYLES))
|
if (! in_array($string,self::STYLES))
|
||||||
throw new Exception(sprintf('Type [%s] not valid',$string));
|
throw new SlackSyntaxException(sprintf('Type [%s] not valid',$string));
|
||||||
|
|
||||||
$this->style = $string;
|
$this->style = $string;
|
||||||
|
|
||||||
@ -115,6 +117,7 @@ final class AttachmentAction extends BlockKit
|
|||||||
*
|
*
|
||||||
* @param string $string
|
* @param string $string
|
||||||
* @return $this
|
* @return $this
|
||||||
|
* @throws SlackSyntaxException
|
||||||
*/
|
*/
|
||||||
public function value(string $string): self
|
public function value(string $string): self
|
||||||
{
|
{
|
||||||
|
@ -61,7 +61,6 @@ abstract class Base extends SlackBase
|
|||||||
* This function should be overwritten in the parent class, and finish by calling return Message::blank();
|
* This function should be overwritten in the parent class, and finish by calling return Message::blank();
|
||||||
*
|
*
|
||||||
* @return Message
|
* @return Message
|
||||||
* @throws \Exception
|
|
||||||
*/
|
*/
|
||||||
abstract public function respond(): Message;
|
abstract public function respond(): Message;
|
||||||
}
|
}
|
@ -26,7 +26,6 @@ final class Unknown extends Base
|
|||||||
* Interactive messages can return their output in the incoming HTTP post
|
* Interactive messages can return their output in the incoming HTTP post
|
||||||
*
|
*
|
||||||
* @return Message
|
* @return Message
|
||||||
* @throws \Exception
|
|
||||||
*/
|
*/
|
||||||
public function respond(): Message
|
public function respond(): Message
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user