Move messages into its own object, Change default Listeners to have a protected LOGKEY
This commit is contained in:
parent
d0b7038604
commit
03c6a5c426
16
src/API.php
16
src/API.php
@ -5,6 +5,7 @@ namespace Slack;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Slack\Response\Chat;
|
||||
use Slack\Exceptions\{SlackAlreadyPinnedException,
|
||||
SlackChannelNotFoundException,
|
||||
SlackException,
|
||||
@ -83,8 +84,9 @@ class API
|
||||
/**
|
||||
* Get Messages on a channel from a specific timestamp
|
||||
*
|
||||
* @param $channel
|
||||
* @param $timestamp
|
||||
* @param $channel
|
||||
* @param $timestamp
|
||||
* @param int $limit
|
||||
* @return Generic
|
||||
* @throws \Exception
|
||||
*/
|
||||
@ -126,16 +128,16 @@ class API
|
||||
/**
|
||||
* Get all messages from a thread
|
||||
*
|
||||
* @param $channel
|
||||
* @param $thread_ts
|
||||
* @return Generic
|
||||
* @param string $channel
|
||||
* @param string $thread_ts
|
||||
* @return Chat
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getMessageHistory($channel,$thread_ts): Generic
|
||||
public function getMessageHistory(string $channel,string $thread_ts): Chat
|
||||
{
|
||||
Log::debug(sprintf('%s:Get Message Threads for Message [%s] on Channel [%s]',static::LOGKEY,$thread_ts,$channel),['m'=>__METHOD__]);
|
||||
|
||||
return new Generic($this->execute('conversations.replies',['channel'=>$channel,'ts'=>$thread_ts]));
|
||||
return new Chat($this->execute('conversations.replies',['channel'=>$channel,'ts'=>$thread_ts]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,7 @@ use Slack\Event\AppHomeOpened;
|
||||
|
||||
class AppHomeOpenedListener implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LAH';
|
||||
protected const LOGKEY = 'LAH';
|
||||
|
||||
public $queue = 'high';
|
||||
|
||||
|
@ -9,7 +9,7 @@ use Slack\Event\MemberJoinedChannel;
|
||||
|
||||
class ChannelJoinListener implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LCJ';
|
||||
protected const LOGKEY = 'LCJ';
|
||||
|
||||
public $queue = 'high';
|
||||
|
||||
|
@ -9,7 +9,7 @@ use Slack\Event\{Base,ChannelLeft,GroupLeft};
|
||||
|
||||
class ChannelLeftListener implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LCL';
|
||||
protected const LOGKEY = 'LCL';
|
||||
|
||||
public $queue = 'high';
|
||||
|
||||
|
@ -9,7 +9,7 @@ use Slack\Interactive\InteractiveMessage;
|
||||
|
||||
class InteractiveMessageListener implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LIM';
|
||||
protected const LOGKEY = 'LIM';
|
||||
|
||||
public $queue = 'high';
|
||||
|
||||
|
@ -9,7 +9,7 @@ use Slack\Event\Message;
|
||||
|
||||
class MessageListener implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LM-';
|
||||
protected const LOGKEY = 'LM-';
|
||||
|
||||
public $queue = 'high';
|
||||
|
||||
|
@ -9,7 +9,7 @@ use Slack\Event\PinAdded;
|
||||
|
||||
class PinAddedListener implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LPA';
|
||||
protected const LOGKEY = 'LPA';
|
||||
|
||||
public $queue = 'high';
|
||||
|
||||
|
@ -9,7 +9,7 @@ use Slack\Event\PinRemoved;
|
||||
|
||||
class PinRemovedListener implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LPR';
|
||||
protected const LOGKEY = 'LPR';
|
||||
|
||||
public $queue = 'high';
|
||||
|
||||
|
@ -9,7 +9,7 @@ use Slack\Event\ReactionAdded;
|
||||
|
||||
class ReactionAddedListener implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LRA';
|
||||
protected const LOGKEY = 'LRA';
|
||||
|
||||
public $queue = 'high';
|
||||
|
||||
|
@ -10,7 +10,7 @@ use Slack\Message;
|
||||
|
||||
class ShortcutListener //implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LSC';
|
||||
protected const LOGKEY = 'LSC';
|
||||
|
||||
// Block actions arent queued, since slack expects a response to the request
|
||||
//public $queue = 'high';
|
||||
|
@ -9,7 +9,7 @@ use Slack\Interactive\ViewClosed;
|
||||
|
||||
class ViewClosedListener implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LVC';
|
||||
protected const LOGKEY = 'LVC';
|
||||
|
||||
public $queue = 'high';
|
||||
|
||||
|
@ -9,7 +9,7 @@ use Slack\Interactive\ViewSubmission;
|
||||
|
||||
class ViewSubmissionListener implements ShouldQueue
|
||||
{
|
||||
private const LOGKEY = 'LVC';
|
||||
protected const LOGKEY = 'LVC';
|
||||
|
||||
public $queue = 'high';
|
||||
|
||||
|
@ -50,10 +50,12 @@ class Base extends SlackBase implements \JsonSerializable
|
||||
// For interactive post responses, the channel ID is "channel"
|
||||
return object_get($this->_data,$key) ?: object_get($this->_data,'channel');
|
||||
|
||||
case 'messages': // Used by getMessageHistory()
|
||||
return collect(object_get($this->_data,$key));
|
||||
|
||||
case 'team_id':
|
||||
case 'ts':
|
||||
case 'user_id':
|
||||
case 'messages': // Used by getMessageHistory()
|
||||
case 'type': // Needed by URL verification
|
||||
return object_get($this->_data,$key);
|
||||
}
|
||||
|
49
src/Response/Chat.php
Normal file
49
src/Response/Chat.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Slack\Response;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* This is a Slack Response from a GetHistory API call which is a message Chat
|
||||
*/
|
||||
class Chat extends Base
|
||||
{
|
||||
protected const LOGKEY = 'RC-';
|
||||
|
||||
/**
|
||||
* Enable getting values for keys in the response
|
||||
*
|
||||
* @note: This method is limited to certain values to ensure integrity reasons
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
switch ($key) {
|
||||
default:
|
||||
return parent::__get($key);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTime(string $ts): Carbon
|
||||
{
|
||||
$t = strstr($ts,'.',TRUE);
|
||||
|
||||
return Carbon::createFromTimestamp($t);
|
||||
}
|
||||
|
||||
public function replies(): Collection
|
||||
{
|
||||
return $this->messages->skip(1);
|
||||
}
|
||||
|
||||
public function reply_count(): int
|
||||
{
|
||||
return $this->messages->first()->reply_count;
|
||||
}
|
||||
|
||||
public function user_count(): int
|
||||
{
|
||||
return $this->messages->first()->reply_users_count;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user