Compare commits

...

4 Commits

8 changed files with 58 additions and 16 deletions

View File

@ -430,7 +430,7 @@ final class API
case 'hash_conflict':
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());

View File

@ -152,7 +152,7 @@ abstract class Base
if (! $o->exists) {
$o->team_id = $this->enterprise_id ? NULL : $this->team()->id;
$o->enterprise_id = ($x=$this->enterprise())->exists ? $x->id : NULL;
$o->active = TRUE;
$o->active = FALSE;
$o->save();
Log::debug(sprintf('%s: User Created in DB [%s] (%s)',self::LOGKEY,$this->user_id,$o->id));

View File

@ -67,7 +67,7 @@ final class MultiStaticSelect extends Element
return $this;
}
public function initial_options(array $initial=NULL): self
public function initial_options(Collection $initial=NULL): self
{
// No initial options.
if (count($initial)) {
@ -77,7 +77,7 @@ final class MultiStaticSelect extends Element
if (count($initial) > 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;

View File

@ -89,7 +89,7 @@ final class Modal extends BlockKit
return $this;
}
public function clear_on_close(bool $bool): self
public function clear_on_close(bool $bool=TRUE): self
{
if ($this->type != 'modal')
throw new SlackSyntaxException(sprintf('clear_on_close is not required for %s',$this->type));
@ -136,7 +136,7 @@ final class Modal extends BlockKit
return $this;
}
public function notify_on_close(bool $bool): self
public function notify_on_close(bool $bool=TRUE): self
{
if ($this->type != 'modal')
throw new SlackSyntaxException(sprintf('notify_on_close is not required for %s',$this->type));

View File

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

View File

@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Slack\Blockkit\Blocks;
use Slack\Blockkit\Blocks\Context;
use Slack\Blockkit\Blocks\{Context,Divider,Section};
use Slack\Blockkit\Blocks\Elements\Text;
use Slack\Exceptions\{SlackException,SlackSyntaxException};
use Slack\Jobs\{DeleteChat,DeleteResponse};
@ -124,6 +124,14 @@ final class Message extends BlockKit
return $this;
}
// This is a helper method
public function divider(): self
{
$this->blocks->push(Divider::item());
return $this;
}
public function forgetTS(): self
{
$this->_data->forget('ts');
@ -162,9 +170,6 @@ final class Message extends BlockKit
if (! $delete && $this->selfdestruct)
$delete = $this->selfdestruct;
if ($this->_data->get('blocks') && $this->_data->get('attachments'))
throw new SlackSyntaxException('Message cannot have blocks and attachments.');
if ((! isset($this->o)) || ((! $this->o->team) && (! $this->o->user_team)))
throw new SlackSyntaxException('Message needs to have a user or a channel to work out the team.');
@ -178,10 +183,18 @@ 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__]);
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]);
// Queue the delete of the message if requested
dispatch((new DeleteChat($this->o,$response->ts))->onQueue('slack')->delay($delete));
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
dispatch((new DeleteChat($this->o,$response->ts))->onQueue('slack')->delay($delete));
}
}
return $response;
@ -250,6 +263,7 @@ final class Message extends BlockKit
*
* @param Carbon $time
* @return Message
* @throws SlackSyntaxException
*/
public function selfdestruct(Carbon $time): self
{
@ -292,6 +306,14 @@ final class Message extends BlockKit
return $this;
}
// This is a helper method
public function spacer(): self
{
$this->blocks->push(Section::item(Text::item(' ')));
return $this;
}
/* CONFIGURATION METHODS */
/**
@ -396,6 +418,25 @@ final class Message extends BlockKit
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
{
$this->username = $user;

View File

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

View File

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