Compare commits

...

10 Commits

37 changed files with 267 additions and 314 deletions

View File

@ -430,7 +430,7 @@ final class API
case 'hash_conflict': case 'hash_conflict':
if (App::environment() == 'local') if (App::environment() == 'local')
file_put_contents('/tmp/hash_conflict.'.$method,print_r(json_decode(json_decode($parameters)->view),TRUE)); file_put_contents('/tmp/hash_conflict.'.$method,print_r($response,TRUE));
throw new SlackHashConflictException('Hash Conflict',$request->status()); throw new SlackHashConflictException('Hash Conflict',$request->status());
@ -456,6 +456,8 @@ final class API
case 'thread_not_found': case 'thread_not_found':
throw new SlackThreadNotFoundException('Thread Not Found',$request->status()); throw new SlackThreadNotFoundException('Thread Not Found',$request->status());
case 'account_inactive':
// @todo Mark the token/team as inactive
default: default:
Log::error(sprintf('%s:Generic Error',static::LOGKEY),['m'=>__METHOD__,'t'=>$this->_token->team_id,'r'=>$response]); Log::error(sprintf('%s:Generic Error',static::LOGKEY),['m'=>__METHOD__,'t'=>$this->_token->team_id,'r'=>$response]);
throw new SlackException($response->error,$request->status()); throw new SlackException($response->error,$request->status());

View File

@ -64,6 +64,39 @@ abstract class Base
return $o->exists ? $o : NULL; return $o->exists ? $o : NULL;
} }
/**
* Separate out a callback command to the id that the command relates to
*
* @param string $key
* @param string|null $item
* @return string|null
* @throws \Exception
*/
final protected function keyitem(string $key,string $item=NULL): ?string
{
if (! $item)
return $item;
$regex = '/^([a-z_]+)\|([0-9]+)$/';
$id = NULL;
$value = NULL;
if (preg_match($regex,$item)) {
$id = preg_replace($regex,'$1',$item);
$value = preg_replace($regex,'$2',$item);
}
switch ($key) {
case 'id':
return $id ?: $item;
case 'value':
return $value;
default:
throw new \Exception('Unknown key: '.$key);
}
}
/** /**
* Return the Eneterprise object that a Response is related to * Return the Eneterprise object that a Response is related to
* *
@ -119,7 +152,7 @@ abstract class Base
if (! $o->exists) { if (! $o->exists) {
$o->team_id = $this->enterprise_id ? NULL : $this->team()->id; $o->team_id = $this->enterprise_id ? NULL : $this->team()->id;
$o->enterprise_id = ($x=$this->enterprise())->exists ? $x->id : NULL; $o->enterprise_id = ($x=$this->enterprise())->exists ? $x->id : NULL;
$o->active = TRUE; $o->active = FALSE;
$o->save(); $o->save();
Log::debug(sprintf('%s: User Created in DB [%s] (%s)',self::LOGKEY,$this->user_id,$o->id)); Log::debug(sprintf('%s: User Created in DB [%s] (%s)',self::LOGKEY,$this->user_id,$o->id));

View File

@ -10,9 +10,19 @@ use Slack\Exceptions\SlackSyntaxException;
/** /**
* Class BlockKit - Slack Blockit Objects * Class BlockKit - Slack Blockit Objects
* *
* @notes
* + callback_id is used to identify the source of any action (modal). (Message blocks do not have a callback_id, accept in legacy attachments).
* eg: hometab, add_product, ask_modal
* + block_id is used to identify the sub action(s) of any action (modal). (Messages with blocks can have a block_id, we need to use this to determine what to do.)
* eg: multiple blocks (list of something)
* + action_id is used to identify the action that was initiated
* eg: view, edit, review
* + value is the value of the action_id
* eg: 5 (question #), yes, no, skip, abort
*
* @package Slack * @package Slack
*/ */
abstract class BlockKit implements \JsonSerializable abstract class BlockKit implements \JsonSerializable,\Countable
{ {
protected Collection $_data; protected Collection $_data;

View File

@ -11,12 +11,12 @@ use Slack\Exceptions\SlackSyntaxException;
final class Overflow extends Element final class Overflow extends Element
{ {
protected const LIMITS = [ public const LIMITS = [
'action_id' => 255, 'action_id' => 255,
]; ];
private const MIN_OPTIONS = 1; public const MIN_OPTIONS = 1;
private const MAX_OPTIONS = 5; public const MAX_OPTIONS = 5;
/** /**
* @param string $action_id * @param string $action_id

View File

@ -10,13 +10,13 @@ use Slack\Exceptions\SlackSyntaxException;
final class Actions extends Blocks final class Actions extends Blocks
{ {
protected const LIMITS = [ public const LIMITS = [
'block_id' => 255, // @todo Should be unique for each message 'block_id' => 255, // @todo Should be unique for each message
]; ];
private const MAX_ELEMENTS = 5; public const MAX_ELEMENTS = 5;
private const VALID_ELEMENTS = [ public const VALID_ELEMENTS = [
Button::class, Button::class,
MultiStaticSelect::class, MultiStaticSelect::class,
Blocks\Accessories\Overflow::class, Blocks\Accessories\Overflow::class,

View File

@ -9,11 +9,11 @@ use Slack\Exceptions\SlackSyntaxException;
final class Context extends Blocks final class Context extends Blocks
{ {
protected const LIMITS = [ public const LIMITS = [
'block_id' => 255, // @todo Should be unique for each message 'block_id' => 255, // @todo Should be unique for each message
]; ];
private const MAX_ELEMENTS = 10; public const MAX_ELEMENTS = 10;
/** /**
* @param Collection $collection * @param Collection $collection

View File

@ -15,26 +15,19 @@ final class Button extends Element
'value' => 2000, 'value' => 2000,
]; ];
public function __construct(Text $text,string $value,string $action_id) public function __construct(string $text,string $value,string $action_id)
{ {
parent::__construct(); parent::__construct();
// Defaults // Defaults
$this->type = 'button'; $this->type = 'button';
if ($text->type != 'plain_text') $this->text = Text::item($this->validate('text',$text),'plain_text');
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$text->type));
if (strlen($text->text) > self::LIMITS['text'])
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['text']));
$this->text = $text;
$this->value = $this->validate('value',$value); $this->value = $this->validate('value',$value);
$this->action_id = $this->validate('action_id',$action_id); $this->action_id = $this->validate('action_id',$action_id);
} }
public static function item(Text $text,string $value,string $action_id): self public static function item(string $text,string $value,string $action_id): self
{ {
return new self($text,$value,$action_id); return new self($text,$value,$action_id);
} }

View File

@ -3,18 +3,39 @@
namespace Slack\Blockkit\Blocks\Elements; namespace Slack\Blockkit\Blocks\Elements;
use Slack\Blockkit\Element; use Slack\Blockkit\Element;
use Slack\Exceptions\SlackSyntaxException;
final class Confirm extends Element final class Confirm extends Element
{ {
public function __construct() protected const LIMITS = [
'title' => 100,
'text' => 300,
'confirm' => 30,
'deny' => 30,
];
public function __construct(string $title,Text $text,string $confirm,string $deny)
{ {
parent::__construct(); parent::__construct();
abort(500,'Not Implememted'); $this->title = Text::item($this->validate('title',$title),'plain_text');
$this->text = $this->validate('text',$text->text) ? $text : NULL;
$this->confirm = Text::item($this->validate('confirm',$confirm),'plain_text');
$this->deny = Text::item($this->validate('deny',$deny),'plain_text');
} }
public static function item(): self public static function item(string $title,Text $text,string $confirm,string $deny): self
{ {
return new self(); return new self($title,$text,$confirm,$deny);
}
public function style(string $string): self
{
if (! in_array($string,['default','primary','danger']))
throw new SlackSyntaxException(sprintf('Unknown style %s',$string));
$this->style = $string;
return $this;
} }
} }

View File

@ -13,29 +13,22 @@ final class ExternalSelect extends Element
]; ];
/** /**
* @param Text $placeholder * @param string $placeholder
* @param string $action_id * @param string $action_id
* @throws SlackSyntaxException * @throws SlackSyntaxException
*/ */
public function __construct(Text $placeholder,string $action_id) public function __construct(string $placeholder,string $action_id)
{ {
parent::__construct(); parent::__construct();
// Defaults // Defaults
$this->type = 'external_select'; $this->type = 'external_select';
if ($placeholder->type != 'plain_text') $this->placeholder = Text::item($this->validate('placeholder',$placeholder),'plain_text');
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$placeholder->type));
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
$this->placeholder = $placeholder;
$this->action_id = $this->validate('action_id',$action_id); $this->action_id = $this->validate('action_id',$action_id);
} }
public static function item(Text $placeholder,string $action_id): self public static function item(string $placeholder,string $action_id): self
{ {
return new self($placeholder,$action_id); return new self($placeholder,$action_id);
} }

View File

@ -9,40 +9,32 @@ use Slack\Exceptions\SlackSyntaxException;
final class MultiExternalSelect extends Element final class MultiExternalSelect extends Element
{ {
protected const LIMITS = [ public const LIMITS = [
'action_id' => 255, 'action_id' => 255,
'placeholder' => 150, 'placeholder' => 150,
]; ];
private const MAX_OPTIONS = 100; public const MAX_OPTIONS = 100;
// @todo option_group? (double check it is applicable to this item) // @todo option_group? (double check it is applicable to this item)
/** /**
* @param Text $placeholder * @param string $placeholder
* @param string $action_id * @param string $action_id
* @throws SlackSyntaxException * @throws SlackSyntaxException
* @todo We dont handle option_groups yet.
*/ */
public function __construct(Text $placeholder,string $action_id) public function __construct(string $placeholder,string $action_id)
{ {
parent::__construct(); parent::__construct();
// Defaults // Defaults
$this->type = 'multi_external_select'; $this->type = 'multi_external_select';
if ($placeholder->type != 'plain_text') $this->placeholder = Text::item($this->validate('placeholder',$placeholder),'plain_text');
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$placeholder->type));
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
$this->placeholder = $placeholder;
$this->action_id = $this->validate('action_id',$action_id); $this->action_id = $this->validate('action_id',$action_id);
} }
public static function item(Text $placeholder,string $action_id): self public static function item(string $placeholder,string $action_id): self
{ {
return new self($placeholder,$action_id); return new self($placeholder,$action_id);
} }

View File

@ -9,37 +9,30 @@ use Slack\Exceptions\SlackSyntaxException;
final class MultiStaticSelect extends Element final class MultiStaticSelect extends Element
{ {
protected const LIMITS = [ public const LIMITS = [
'action_id' => 255, 'action_id' => 255,
'placeholder' => 150, 'placeholder' => 150,
]; ];
private const MAX_OPTIONS = 100; public const MAX_OPTIONS = 100;
// @todo option_group? (double check it is applicable to this item) // @todo option_group? (double check it is applicable to this item)
/** /**
* @param Text $placeholder * @param string $placeholder
* @param string $action_id * @param string $action_id
* @param Collection $options * @param Collection $options
* @throws SlackSyntaxException * @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(string $placeholder,string $action_id,Collection $options)
{ {
parent::__construct(); parent::__construct();
// Defaults // Defaults
$this->type = 'multi_static_select'; $this->type = 'multi_static_select';
if ($placeholder->type != 'plain_text') $this->placeholder = Text::item($this->validate('placeholder',$placeholder),'plain_text');
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$placeholder->type));
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['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())
@ -53,7 +46,7 @@ final class MultiStaticSelect extends Element
}); });
} }
public static function item(Text $placeholder,string $action_id,Collection $options): self public static function item(string $placeholder,string $action_id,Collection $options): self
{ {
return new self($placeholder,$action_id,$options); return new self($placeholder,$action_id,$options);
} }
@ -74,7 +67,7 @@ final class MultiStaticSelect extends Element
return $this; return $this;
} }
public function initial_options(array $initial=NULL): self public function initial_options(Collection $initial=NULL): self
{ {
// No initial options. // No initial options.
if (count($initial)) { if (count($initial)) {
@ -84,7 +77,7 @@ final class MultiStaticSelect extends Element
if (count($initial) > self::MAX_OPTIONS) if (count($initial) > self::MAX_OPTIONS)
throw new SlackSyntaxException(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 $initial->contains($item['value']); });
} }
return $this; return $this;

View File

@ -36,15 +36,9 @@ final class Options extends Element
/* OPTIONAL ITEMS */ /* OPTIONAL ITEMS */
public function description(Text $text): self public function description(string $text): self
{ {
if ($text->type != 'plain_text') $this->description = Text::item($this->validate('description',$text),'plain_text');
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$text->type));
if (strlen($text->text) > self::LIMITS['description'])
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['description']));
$this->description = $text;
return $this; return $this;
} }

View File

@ -10,12 +10,12 @@ use Slack\Exceptions\SlackSyntaxException;
*/ */
final class PlainTextInput extends Element final class PlainTextInput extends Element
{ {
protected const LIMITS = [ public const LIMITS = [
'action_id' => 255, // @todo Should be unique for each message 'action_id' => 255, // @todo Should be unique for each message
'placeholder' => 150, 'placeholder' => 150,
]; ];
private const MAX_MIN_LENGTH = 3000; public const MAX_MIN_LENGTH = 3000;
// @todo dispatch_action_config // @todo dispatch_action_config
// @todo focus_on_load // @todo focus_on_load

View File

@ -9,37 +9,30 @@ use Slack\Exceptions\SlackSyntaxException;
final class StaticSelect extends Element final class StaticSelect extends Element
{ {
protected const LIMITS = [ public const LIMITS = [
'action_id' => 255, 'action_id' => 255,
'placeholder' => 150, 'placeholder' => 150,
]; ];
private const MAX_OPTIONS = 100; public const MAX_OPTIONS = 100;
// @todo option_group // @todo option_group
/** /**
* @param Text $placeholder * @param string $placeholder
* @param string $action_id * @param string $action_id
* @param Collection $options * @param Collection $options
* @throws SlackSyntaxException * @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(string $placeholder,string $action_id,Collection $options)
{ {
parent::__construct(); parent::__construct();
// Defaults // Defaults
$this->type = 'static_select'; $this->type = 'static_select';
if ($placeholder->type != 'plain_text') $this->placeholder = Text::item($this->validate('placeholder',$placeholder),'plain_text');
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$placeholder->type));
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['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())
@ -53,7 +46,7 @@ final class StaticSelect extends Element
}); });
} }
public static function item(Text $placeholder,string $action_id,Collection $options): self public static function item(string $placeholder,string $action_id,Collection $options): self
{ {
return new self($placeholder,$action_id,$options); return new self($placeholder,$action_id,$options);
} }

View File

@ -7,7 +7,7 @@ use Slack\Exceptions\SlackSyntaxException;
final class Text extends Element final class Text extends Element
{ {
private const TYPES = ['mrkdwn','plain_text']; public const TYPES = ['mrkdwn','plain_text'];
public function __construct(string $text,string $type) public function __construct(string $text,string $type)
{ {
@ -16,8 +16,8 @@ final class Text extends Element
if (! in_array($type,self::TYPES)) if (! in_array($type,self::TYPES))
throw new SlackSyntaxException(sprintf('Type [%s] not valid',$type)); throw new SlackSyntaxException(sprintf('Type [%s] not valid',$type));
$this->type = $type;
$this->text = $text; $this->text = $text;
$this->type = $type;
} }
public static function item(string $text,string $type='mrkdwn'): self public static function item(string $text,string $type='mrkdwn'): self
@ -29,8 +29,8 @@ final class Text extends Element
public function emoji(bool $bool): self public function emoji(bool $bool): self
{ {
if ($x=$this->type != 'plain_text') if ($this->type != 'plain_text')
throw new SlackSyntaxException(sprintf('Cannnot use emoji when type is [%s]',$x)); throw new SlackSyntaxException(sprintf('Cannnot use emoji when type is [%s]',$this->type));
$this->emoji = $bool; $this->emoji = $bool;

View File

@ -14,26 +14,20 @@ final class Header extends Blocks
]; ];
/** /**
* @param Text $text * @param string $text
* @throws SlackSyntaxException * @throws SlackSyntaxException
*/ */
public function __construct(Text $text) public function __construct(string $text)
{ {
parent::__construct(); parent::__construct();
// Defaults // Defaults
$this->type = 'header'; $this->type = 'header';
if ($text->type != 'plain_text') $this->text = Text::item($this->validate('text',$text),'plain_text');
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$text->type));
if (strlen($text->text) > self::LIMITS['text'])
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['text']));
$this->text = $text;
} }
public static function item(Text $text): self public static function item(string $text): self
{ {
return new self($text); return new self($text);
} }

View File

@ -2,18 +2,18 @@
namespace Slack\Blockkit\Blocks; namespace Slack\Blockkit\Blocks;
use Slack\Blockkit\{Blocks,Element}; use Slack\Blockkit\{Blocks,Blocks\Elements\Text,Element};
use Slack\Exceptions\SlackSyntaxException; use Slack\Exceptions\SlackSyntaxException;
final class Input extends Blocks final class Input extends Blocks
{ {
protected const LIMITS = [ public const LIMITS = [
'block_id' => 255, // @todo Should be unique for each message 'block_id' => 255, // @todo Should be unique for each message
'hint' => 2000, 'hint' => 2000,
'label' => 2000, 'label' => 2000,
]; ];
private const VALID_ELEMENTS = [ public const VALID_ELEMENTS = [
Elements\PlainTextInput::class, Elements\PlainTextInput::class,
Elements\MultiStaticSelect::class Elements\MultiStaticSelect::class
]; ];
@ -21,26 +21,20 @@ final class Input extends Blocks
// @todo dispatch_action // @todo dispatch_action
/** /**
* @param Elements\Text|null $label * @param string|null $label
* @throws SlackSyntaxException * @throws SlackSyntaxException
*/ */
public function __construct(Elements\Text $label=NULL) public function __construct(string $label=NULL)
{ {
parent::__construct(); parent::__construct();
if ($label->type != 'plain_text')
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']) $this->label = Text::item($this->validate('label',$label),'plain_text');
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['label']));
$this->label = $label;
} }
public static function item(Elements\Text $label=NULL): self public static function item(string $label=NULL): self
{ {
return new self($label); return new self($label);
} }

View File

@ -10,13 +10,13 @@ use Slack\Exceptions\SlackSyntaxException;
final class Section extends Blocks final class Section extends Blocks
{ {
protected const LIMITS = [ public const LIMITS = [
'block_id' => 255, // @todo Should be unique for each message 'block_id' => 255, // @todo Should be unique for each message
'text' => 3000, 'text' => 3000,
]; ];
private const MAX_FIELDS = 10; public const MAX_FIELDS = 10;
private const MAX_FIELDS_TEXT = 2000; public const MAX_FIELDS_TEXT = 2000;
/** /**
* @param Text|NULL $text not required if fields is provided * @param Text|NULL $text not required if fields is provided

View File

@ -13,40 +13,33 @@ use Slack\Exceptions\SlackSyntaxException;
*/ */
final class Modal extends BlockKit final class Modal extends BlockKit
{ {
protected const LIMITS = [ public const LIMITS = [
'callback_id' => 255, 'callback_id' => 255,
'close' => 24, 'close' => 24,
'private_metadata' => 3000, 'private_metadata' => 3000,
'submit' => 24, 'submit' => 24,
'text' => 24, 'title' => 24,
]; ];
private const MAX_BLOCKS = 100; public const MAX_BLOCKS = 100;
private $action = NULL; private $action = NULL;
public function __construct(Text $title=NULL,string $type='modal') public function __construct(string $title=NULL,string $type='modal')
{ {
parent::__construct(); parent::__construct();
if (! in_array($type,['modal','home'])) if (! in_array($type,['modal','home']))
throw new SlackSyntaxException(sprintf('Unknown type %s',$type)); throw new SlackSyntaxException(sprintf('Unknown type %s',$type));
if ($type != 'modal' && $title) if ($title) {
if ($type != 'modal')
throw new SlackSyntaxException(sprintf('Titles are not required for %s',$type)); throw new SlackSyntaxException(sprintf('Titles are not required for %s',$type));
if ($title) { $this->title = Text::item($this->validate('title',$title),'plain_text');
if ($title->type != 'plain_text')
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$title->type));
if (strlen($title->text) > self::LIMITS['text'])
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['text']));
$this->title = $title;
} }
$this->type = $type; $this->type = $type;
$this->blocks = collect(); $this->blocks = collect();
} }
@ -61,7 +54,7 @@ final class Modal extends BlockKit
{ {
$this->blocks->push($block); $this->blocks->push($block);
if ($x=$this->blocks->count() > self::MAX_BLOCKS) if ($this->blocks->count() > self::MAX_BLOCKS)
throw new SlackSyntaxException(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;
@ -96,7 +89,7 @@ final class Modal extends BlockKit
return $this; return $this;
} }
public function clear_on_close(bool $bool): self public function clear_on_close(bool $bool=TRUE): self
{ {
if ($this->type != 'modal') if ($this->type != 'modal')
throw new SlackSyntaxException(sprintf('clear_on_close is not required for %s',$this->type)); throw new SlackSyntaxException(sprintf('clear_on_close is not required for %s',$this->type));
@ -113,18 +106,12 @@ final class Modal extends BlockKit
return $this; return $this;
} }
public function close(Text $text): self public function close(string $text): self
{ {
if ($this->type != 'modal') if ($this->type != 'modal')
throw new SlackSyntaxException(sprintf('Close is not required for %s',$this->type)); throw new SlackSyntaxException(sprintf('Close is not required for %s',$this->type));
if ($text->type != 'plain_text') $this->close = Text::item($this->validate('close',$text),'plain_text');
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$text->type));
if (strlen($text->text) > self::LIMITS['close'])
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['close']));
$this->close = $text;
return $this; return $this;
} }
@ -149,7 +136,7 @@ final class Modal extends BlockKit
return $this; return $this;
} }
public function notify_on_close(bool $bool): self public function notify_on_close(bool $bool=TRUE): self
{ {
if ($this->type != 'modal') if ($this->type != 'modal')
throw new SlackSyntaxException(sprintf('notify_on_close is not required for %s',$this->type)); throw new SlackSyntaxException(sprintf('notify_on_close is not required for %s',$this->type));
@ -174,18 +161,12 @@ final class Modal extends BlockKit
return $this; return $this;
} }
public function submit(Text $text): self public function submit(string $text): self
{ {
if ($this->type != 'modal') if ($this->type != 'modal')
throw new SlackSyntaxException(sprintf('Submit is not required for %s',$this->type)); throw new SlackSyntaxException(sprintf('Submit is not required for %s',$this->type));
if ($text->type != 'plain_text') $this->submit = Text::item($this->validate('submit',$text),'plain_text');
throw new SlackSyntaxException(sprintf('Text must be plain_text not %s',$text->type));
if (strlen($text->text) > self::LIMITS['submit'])
throw new SlackSyntaxException(sprintf('Text must be %d chars or less',self::LIMITS['submit']));
$this->submit = $text;
return $this; return $this;
} }

View File

@ -35,6 +35,7 @@ abstract class Base extends SlackBase
* + user_id * + user_id
* @param string $key * @param string $key
* @return mixed|object * @return mixed|object
* @throws \Exception
*/ */
public function __get(string $key) public function __get(string $key)
{ {
@ -46,6 +47,12 @@ abstract class Base extends SlackBase
case 'user_id': case 'user_id':
return object_get($this->_data,'user.id'); return object_get($this->_data,'user.id');
case 'callback_key':
return $this->keyitem('id',$this->callback_id);
case 'callback_value':
return $this->keyitem('value',$this->callback_id);
case 'callback_id': case 'callback_id':
case 'trigger_id': case 'trigger_id':
case 'type': case 'type':

View File

@ -64,20 +64,25 @@ final class BlockActions extends Base
case 'action': case 'action':
return Arr::get(object_get($this->_data,'actions'),$this->index); return Arr::get(object_get($this->_data,'actions'),$this->index);
case 'action_id':
return object_get(Arr::get($this->actions,$this->index),$key);
// An event can have more than 1 action, each action can have 1 value. // An event can have more than 1 action, each action can have 1 value.
case 'action_key': case 'action_key':
return $this->action('action'); return $this->keyitem('id',$this->action_id);
case 'action_value': case 'action_value':
return $this->action('value'); return $this->keyitem('value',$this->action_id);
// Interactive Messages have a block_id.
case 'block_key':
return $this->keyitem('id',$this->block_id);
case 'block_value':
return $this->keyitem('value',$this->block_id);
case 'actions': case 'actions':
case 'response_url': case 'response_url':
return object_get($this->_data,$key); return object_get($this->_data,$key);
case 'action_id':
case 'block_id': case 'block_id':
return object_get($this->action,$key); return object_get($this->action,$key);
@ -99,7 +104,7 @@ final class BlockActions extends Base
return object_get($this->_data,'container.type'); return object_get($this->_data,'container.type');
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->keyitem('value',object_get($this->action,'action_id')))->channel_id;
case 'keys': case 'keys':
return collect(object_get($this->_data,'view.blocks'))->pluck('accessory.action_id'); return collect(object_get($this->_data,'view.blocks'))->pluck('accessory.action_id');
@ -156,38 +161,6 @@ final class BlockActions extends Base
} }
} }
/**
* Separate out an action command to the id that the command relates to
*
* @param string $key
* @return string|null
* @throws \Exception
*/
private function action(string $key): ?string
{
$regex = '/^([a-z_]+)\|([0-9]+)$/';
$action = NULL;
$value = NULL;
// We only take the action up to the pipe symbol
$action_key = object_get($this->action,'action_id');
if (preg_match($regex,$action_key)) {
$action = preg_replace($regex,'$1',$action_key);
$value = preg_replace($regex,'$2',$action_key);
}
switch ($key) {
case 'action':
return $action ?: $action_key;
case 'value':
return $value;
default:
throw new \Exception('Unknown key: '.$key);
}
}
/** /**
* Some block actions are triggered by messages, and thus dont have a callback_id * Some block actions are triggered by messages, and thus dont have a callback_id
* *

View File

@ -99,26 +99,8 @@ class InteractiveMessage extends Base
public function respond(): Message public function respond(): Message
{ {
Log::info(sprintf('%s:Interactive Message - Callback [%s] Name [%s] Type [%s]',static::LOGKEY,$this->callback_id,$this->name,$this->type),['m'=>__METHOD__]); Log::info(sprintf('%s:Interactive Message - Callback [%s] Name [%s] Type [%s]',static::LOGKEY,$this->callback_id,$this->name,$this->type),['m'=>__METHOD__]);
Log::notice(sprintf('%s:Unhandled action [%s]',static::LOGKEY,$this->callback_id),['m'=>__METHOD__]);
$action = NULL;
$id = NULL;
if (preg_match('/^(.*)\|([0-9]+)/',$this->callback_id)) {
[$action,$id] = explode('|',$this->callback_id,2);
} elseif (preg_match('/^[a-z_]+$/',$this->callback_id)) {
$id = $this->name;
$action = $this->callback_id;
} else {
// If we get here, its an action that we dont know about.
Log::notice(sprintf('%s:Unhandled CALLBACK [%s]',static::LOGKEY,$this->callback_id),['m'=>__METHOD__]);
}
switch ($action) {
default:
Log::notice(sprintf('%s:Unhandled ACTION [%s]',static::LOGKEY,$action),['m'=>__METHOD__]);
return (new Message)->text('That didnt work, I didnt know what to do with your button - you might like to tell '.$this->team()->owner->slack_user); return (new Message)->text('That didnt work, I didnt know what to do with your button - you might like to tell '.$this->team()->owner->slack_user);
} }
} }
}

View File

@ -24,14 +24,14 @@ class ViewSubmission extends Base
case 'blocks': case 'blocks':
return collect(object_get($this->_data,'view.'.$key)); return collect(object_get($this->_data,'view.'.$key));
case 'callback': case 'callback_id':
return object_get($this->_data,'view.callback_id'); return object_get($this->_data,'view.callback_id');
case 'callback_id': case 'callback_key':
return $this->callback('id'); return $this->keyitem('id',$this->callback_id);
case 'callback_value': case 'callback_value':
return $this->callback('value'); return $this->keyitem('value',$this->callback_id);
case 'meta': case 'meta':
return object_get($this->_data,'view.private_metadata'); return object_get($this->_data,'view.private_metadata');
@ -47,35 +47,6 @@ class ViewSubmission extends Base
} }
} }
/**
* Separate out an callback command to the id that the command relates to
*
* @param string $key
* @return string|null
* @throws \Exception
*/
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 \Exception('Unknown key: '.$key);
}
}
/** /**
* This method should be overridden by a local implementation * This method should be overridden by a local implementation
* *
@ -85,31 +56,20 @@ class ViewSubmission extends Base
{ {
// Do some magic with event data // Do some magic with event data
Log::info(sprintf('%s:View Submission for Callback [%s] User [%s] in [%s]',self::LOGKEY,$this->callback_id,$this->user_id,$this->team_id),['m'=>__METHOD__]); Log::info(sprintf('%s:View Submission for Callback [%s] User [%s] in [%s]',self::LOGKEY,$this->callback_id,$this->user_id,$this->team_id),['m'=>__METHOD__]);
Log::notice(sprintf('%s:Unhandled action [%s]',self::LOGKEY,$this->callback_key),['m'=>__METHOD__]);
$action = NULL;
$id = NULL;
if (preg_match('/^(.*)\|([0-9]+)/',$this->callback_id)) {
[$action,$cid] = explode('|',$this->callback_id,2);
} elseif (preg_match('/^[a-z_]+$/',$this->callback_id)) {
$action = $this->callback_id;
} else {
// If we get here, its an action that we dont know about.
Log::notice(sprintf('%s:Unhandled CALLBACK [%s]',static::LOGKEY,$this->callback_id),['m'=>__METHOD__]);
}
switch ($action) {
default:
Log::notice(sprintf('%s:Unhandled ACTION [%s]',self::LOGKEY,$action),['m'=>__METHOD__]);
}
return new Modal; return new Modal;
} }
public function value(string $block_id,string $action_id): ?string public function value(string $block_id,string $action_id=NULL): ?string
{ {
// If there is no state we need to search out blocks for the block_id
if (! $this->state->count()) {
$block = $this->blocks->search(function($item) use ($block_id) { return $item->block_id == $block_id; });
return $block !== FALSE ? object_get($this->blocks->get($block),$action_id) : NULL;
} else {
return object_get($this->state->get($block_id),$action_id.'.value'); return object_get($this->state->get($block_id),$action_id.'.value');
} }
} }
}

View File

@ -20,7 +20,7 @@ class BlockActionListener //implements ShouldQueue
{ {
protected const LOGKEY = 'LBA'; protected const LOGKEY = 'LBA';
public $queue = 'slack'; // public $queue = 'slack';
/** /**
* Handle the event. * Handle the event.

View File

@ -24,6 +24,7 @@ class BlockSuggestionListener implements ShouldQueue
public function handle(BlockSuggestion $event): void public function handle(BlockSuggestion $event): void
{ {
// Do some magic with event data // Do some magic with event data
Log::info(sprintf('%s:Block Suggestion for Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['e'=>$event]); Log::info(sprintf('%s:Block Suggestion Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['e'=>$event]);
Log::notice(sprintf('%s:Ignoring Block Suggestion [%s]',static::LOGKEY,$event->callback_id),['m'=>__METHOD__]);
} }
} }

View File

@ -22,11 +22,7 @@ class InteractiveMessageListener implements ShouldQueue
public function handle(InteractiveMessage $event): void public function handle(InteractiveMessage $event): void
{ {
// Do some magic with event data // Do some magic with event data
Log::info(sprintf('%s:Interactive Message for Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]); Log::info(sprintf('%s:Interactive Message Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]);
Log::notice(sprintf('%s:Ignoring Interactive Message [%s]',static::LOGKEY,$event->callback_id),['m'=>__METHOD__]);
switch ($event->callback_id) {
default:
Log::notice(sprintf('%s:Unhandled CALLBACK [%s]',self::LOGKEY,$event->callback_id),['m'=>__METHOD__]);
}
} }
} }

View File

@ -23,7 +23,6 @@ class ReactionAddedListener implements ShouldQueue
{ {
// Do some magic with event data // Do some magic with event data
Log::info(sprintf('%s:Reaction [%s] added to message in [%s]',self::LOGKEY,$event->reaction,$event->team_id),['m'=>__METHOD__]); Log::info(sprintf('%s:Reaction [%s] added to message in [%s]',self::LOGKEY,$event->reaction,$event->team_id),['m'=>__METHOD__]);
Log::notice(sprintf('%s:Ignoring Reaction Add [%s] on [%s]',static::LOGKEY,$event->reaction,$event->ts),['m'=>__METHOD__]);
Log::debug(sprintf('%s:Ignoring Reaction Add [%s] on [%s]',static::LOGKEY,$event->reaction,$event->ts),['m'=>__METHOD__]);
} }
} }

View File

@ -9,7 +9,6 @@ use Slack\Blockkit\Blocks\Elements\Text;
use Slack\Blockkit\Blocks\{Header,Section}; use Slack\Blockkit\Blocks\{Header,Section};
use Slack\Blockkit\Modal; use Slack\Blockkit\Modal;
use Slack\Interactive\Shortcut; use Slack\Interactive\Shortcut;
use Slack\Message;
class ShortcutListener //implements ShouldQueue class ShortcutListener //implements ShouldQueue
{ {
@ -28,9 +27,9 @@ class ShortcutListener //implements ShouldQueue
public function handle(Shortcut $event): void public function handle(Shortcut $event): void
{ {
if (! $event->channel() || ! $event->channel()->active) { if (! $event->channel() || ! $event->channel()->active) {
$modal = new Modal(Text::item(config('app.name'),'plain_text')); $modal = new Modal(config('app.name'));
$modal->addBlock(Header::item(Text::item(':robot_face: Bot not in this channel','plain_text'))) $modal->addBlock(Header::item(':robot_face: Bot not in this channel'))
->addBlock(Section::item(Text::item('Please add the BOT to this channel and try this again.'))); ->addBlock(Section::item(Text::item('Please add the BOT to this channel and try this again.')));
try { try {
@ -43,10 +42,6 @@ class ShortcutListener //implements ShouldQueue
// Do some magic with event data // Do some magic with event data
Log::info(sprintf('%s:Shortcut [%s] triggered for: [%s]',self::LOGKEY,$event->callback_id,$event->team_id),['m'=>__METHOD__]); Log::info(sprintf('%s:Shortcut [%s] triggered for: [%s]',self::LOGKEY,$event->callback_id,$event->team_id),['m'=>__METHOD__]);
Log::notice(sprintf('%s:Ignoring Shortcut [%s] in team [%s]',static::LOGKEY,$event->callback_id,$event->team_id),['m'=>__METHOD__]);
switch ($event->callback_id) {
default:
Log::notice(sprintf('%s:Unhandled CALLBACK [%s]',self::LOGKEY,$event->callback_id),['m'=>__METHOD__]);
}
} }
} }

View File

@ -22,11 +22,7 @@ class ViewClosedListener implements ShouldQueue
public function handle(ViewClosed $event): void public function handle(ViewClosed $event): void
{ {
// Do some magic with event data // Do some magic with event data
Log::info(sprintf('%s:Block Action for Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]); Log::info(sprintf('%s:View Closed Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]);
Log::notice(sprintf('%s:Ignoring View Closed [%s]',static::LOGKEY,$event->callback_id),['m'=>__METHOD__]);
switch ($event->callback_id) {
default:
Log::notice(sprintf('%s:Unhandled CALLBACK [%s]',self::LOGKEY,$event->callback_id),['m'=>__METHOD__]);
}
} }
} }

View File

@ -22,11 +22,7 @@ class ViewSubmissionListener implements ShouldQueue
public function handle(ViewSubmission $event): void public function handle(ViewSubmission $event): void
{ {
// Do some magic with event data // Do some magic with event data
Log::info(sprintf('%s:View Submission for Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]); Log::info(sprintf('%s:View Submission Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]);
Log::notice(sprintf('%s:Ignoring View Closed [%s]',static::LOGKEY,$event->callback_id),['m'=>__METHOD__]);
switch ($event->callback_id) {
default:
Log::notice(sprintf('%s:Unhandled CALLBACK [%s]',self::LOGKEY,$event->callback_id),['m'=>__METHOD__]);
}
} }
} }

View File

@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Slack\Blockkit\Blocks; use Slack\Blockkit\Blocks;
use Slack\Blockkit\Blocks\Context; use Slack\Blockkit\Blocks\{Context,Divider,Section};
use Slack\Blockkit\Blocks\Elements\Text; use Slack\Blockkit\Blocks\Elements\Text;
use Slack\Exceptions\{SlackException,SlackSyntaxException}; use Slack\Exceptions\{SlackException,SlackSyntaxException};
use Slack\Jobs\{DeleteChat,DeleteResponse}; use Slack\Jobs\{DeleteChat,DeleteResponse};
@ -26,7 +26,8 @@ final class Message extends BlockKit
{ {
private const LOGKEY = 'SM-'; private const LOGKEY = 'SM-';
private const MAX_ATTACHMENTS = 20; public const MAX_ATTACHMENTS = 20;
public const MAX_BLOCKS = 50;
private Model $o; private Model $o;
private ?Carbon $selfdestruct = NULL; private ?Carbon $selfdestruct = NULL;
@ -97,6 +98,9 @@ final class Message extends BlockKit
$this->blocks->push($block); $this->blocks->push($block);
if (count($this->blocks) > self::MAX_BLOCKS)
throw new SlackSyntaxException(sprintf('Messages should not have more than %d blocks',self::MAX_BLOCKS));
return $this; return $this;
} }
@ -120,6 +124,14 @@ final class Message extends BlockKit
return $this; return $this;
} }
// This is a helper method
public function divider(): self
{
$this->blocks->push(Divider::item());
return $this;
}
public function forgetTS(): self public function forgetTS(): self
{ {
$this->_data->forget('ts'); $this->_data->forget('ts');
@ -143,7 +155,7 @@ final class Message extends BlockKit
public function jsonSerialize() public function jsonSerialize()
{ {
// For interactive messages that generate a dialog, we need to return NULL // For interactive messages that generate a dialog, we need to return NULL
return $this->_data->count() ? parent::jsonSerialize() : NULL; return count($this) ? parent::jsonSerialize() : NULL;
} }
/** /**
@ -158,13 +170,10 @@ final class Message extends BlockKit
if (! $delete && $this->selfdestruct) if (! $delete && $this->selfdestruct)
$delete = $this->selfdestruct; $delete = $this->selfdestruct;
if ($this->_data->get('blocks') && $this->_data->get('attachments')) if ((! isset($this->o)) || ((! $this->o->team) && (! $this->o->user_team)))
throw new SlackSyntaxException('Message cannot have blocks and attachments.');
if ((! isset($this->o)) || (! $this->o->team))
throw new SlackSyntaxException('Message needs to have a user or a channel to work out the team.'); throw new SlackSyntaxException('Message needs to have a user or a channel to work out the team.');
$api = $this->o->team->slackAPI(); $api = $this->o->team ? $this->o->team->slackAPI() : $this->o->user_team->slackAPI();
if ($this->ephemeral) { if ($this->ephemeral) {
$response = $api->postEphemeral($this); $response = $api->postEphemeral($this);
@ -174,11 +183,19 @@ final class Message extends BlockKit
} }
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 H:i')),['m'=>__METHOD__,'r'=>$response,'message_ts'=>$response->ts]);
if ($this->o instanceof User) {
Log::error(sprintf('%s:Cannot schedule delete of [%s:%s] on user channels [%s]',static::LOGKEY,object_get($this->o,'channel_id',$this->o->id),$response->ts,$this->o->user_id),['m'=>__METHOD__]);
} elseif ($this->ephemeral) {
Log::error(sprintf('%s:Ignoring delete of [%s:%s] on ephemeral messages',static::LOGKEY,object_get($this->o,'channel_id',$this->o->id),$response->ts),['m'=>__METHOD__]);
} else {
// Queue the delete of the message if requested // Queue the delete of the message if requested
dispatch((new DeleteChat($this->o,$response->ts))->onQueue('slack')->delay($delete)); dispatch((new DeleteChat($this->o,$response->ts))->onQueue('slack')->delay($delete));
} }
}
return $response; return $response;
} }
@ -246,6 +263,7 @@ final class Message extends BlockKit
* *
* @param Carbon $time * @param Carbon $time
* @return Message * @return Message
* @throws SlackSyntaxException
*/ */
public function selfdestruct(Carbon $time): self public function selfdestruct(Carbon $time): self
{ {
@ -288,6 +306,14 @@ final class Message extends BlockKit
return $this; return $this;
} }
// This is a helper method
public function spacer(): self
{
$this->blocks->push(Section::item(Text::item(' ')));
return $this;
}
/* CONFIGURATION METHODS */ /* CONFIGURATION METHODS */
/** /**
@ -392,6 +418,25 @@ final class Message extends BlockKit
return $this; return $this;
} }
/**
* Post the message to user
*
* @param string $user
* @return $this
*/
public function user(string $user): self
{
$this->user = $user;
return $this;
}
/**
* Set bot username (used with as_user)
*
* @param string $user
* @return $this
*/
public function username(string $user): self public function username(string $user): self
{ {
$this->username = $user; $this->username = $user;

View File

@ -9,7 +9,7 @@ use Slack\Blockkit\Blocks;
final class Attachment extends BlockKit final class Attachment extends BlockKit
{ {
protected const LIMITS = [ public const LIMITS = [
'footer' => 300, 'footer' => 300,
]; ];

View File

@ -8,7 +8,7 @@ use Slack\Exceptions\SlackSyntaxException;
/** /**
* Class MessageAttachmentAction - Slack Message Attachments Actions * Class MessageAttachmentAction - Slack Message Attachments Actions
* Represents an Single Action for a Slack Message Attachment * Represents a Single Action for a Slack Message Attachment
* *
* @package App\Slack\Message * @package App\Slack\Message
* @note These are now legacy - use blocks instead * @note These are now legacy - use blocks instead
@ -16,14 +16,14 @@ use Slack\Exceptions\SlackSyntaxException;
*/ */
final class AttachmentAction extends BlockKit final class AttachmentAction extends BlockKit
{ {
protected const LIMITS = [ public const LIMITS = [
'text' => 30, 'text' => 30,
'value' => 2000, 'value' => 2000,
]; ];
private const DATA_SOURCES = ['static','users','channels','conversastions','external']; public const DATA_SOURCES = ['static','users','channels','conversastions','external'];
private const STYLES = ['default','danger','primary']; public const STYLES = ['default','danger','primary'];
private const TYPES = ['button','select']; public const TYPES = ['button','select'];
// @todo options // @todo options
// @todo option_groups // @todo option_groups

View File

@ -4,9 +4,9 @@ namespace Slack\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Slack\Traits\ScopeActive;
use App\Models\Slack\Team as AppTeam; use App\Models\Slack\Team as AppTeam;
use Slack\Traits\ScopeActive;
class Channel extends Model class Channel extends Model
{ {

View File

@ -61,8 +61,6 @@ class User extends Model
*/ */
public function getUserTeamAttribute(): ?Team public function getUserTeamAttribute(): ?Team
{ {
Log::debug(sprintf('%s:User [%s], Team [%s], Enterprise [%s]',self::LOGKEY,$this->id,$this->team_id,$this->enterprise_id),['m'=>__METHOD__]);
return $this->team_id ? $this->team : (($x=$this->enterprise->teams) ? $x->first() : NULL); return $this->team_id ? $this->team : (($x=$this->enterprise->teams) ? $x->first() : NULL);
} }

View File

@ -5,6 +5,7 @@ namespace Slack\Options;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Slack\Base as SlackBase; use Slack\Base as SlackBase;
use Slack\Exceptions\SlackException;
use Slack\Message; use Slack\Message;
abstract class Base extends SlackBase abstract class Base extends SlackBase
@ -35,6 +36,7 @@ abstract class Base extends SlackBase
* + user_id * + user_id
* @param string $key * @param string $key
* @return mixed|object * @return mixed|object
* @throws \Exception
*/ */
public function __get(string $key) public function __get(string $key)
{ {
@ -48,11 +50,20 @@ abstract class Base extends SlackBase
case 'user_id': case 'user_id':
return object_get($this->_data,'user.id'); return object_get($this->_data,'user.id');
case 'callback_key':
return $this->keyitem('id',$this->callback_id);
case 'callback_value':
return $this->keyitem('value',$this->callback_id);
case 'callback_id': case 'callback_id':
//case 'action_ts': //case 'action_ts':
//case 'message_ts': //case 'message_ts':
case 'type': case 'type':
return object_get($this->_data,$key); return object_get($this->_data,$key);
default:
throw new SlackException('Unknown key: '.$key);
} }
} }

View File

@ -55,8 +55,9 @@ abstract class Base extends SlackBase implements \JsonSerializable
case 'scheduled_messages': // Used by scheduledMessagesList() case 'scheduled_messages': // Used by scheduledMessagesList()
return collect(object_get($this->_data,$key)); return collect(object_get($this->_data,$key));
case 'team_id':
case 'ts': case 'ts':
return object_get($this->_data,$key) ?: object_get($this->_data,'message_ts');
case 'team_id':
case 'user_id': case 'user_id':
case 'type': // Needed by URL verification case 'type': // Needed by URL verification
return object_get($this->_data,$key); return object_get($this->_data,$key);