Move messages into its own object, Change default Listeners to have a protected LOGKEY

This commit is contained in:
Deon George 2021-08-13 16:34:49 +10:00
parent d0b7038604
commit 03c6a5c426
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
14 changed files with 72 additions and 19 deletions

View File

@ -5,6 +5,7 @@ namespace Slack;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Slack\Response\Chat;
use Slack\Exceptions\{SlackAlreadyPinnedException, use Slack\Exceptions\{SlackAlreadyPinnedException,
SlackChannelNotFoundException, SlackChannelNotFoundException,
SlackException, SlackException,
@ -83,8 +84,9 @@ class API
/** /**
* Get Messages on a channel from a specific timestamp * Get Messages on a channel from a specific timestamp
* *
* @param $channel * @param $channel
* @param $timestamp * @param $timestamp
* @param int $limit
* @return Generic * @return Generic
* @throws \Exception * @throws \Exception
*/ */
@ -126,16 +128,16 @@ class API
/** /**
* Get all messages from a thread * Get all messages from a thread
* *
* @param $channel * @param string $channel
* @param $thread_ts * @param string $thread_ts
* @return Generic * @return Chat
* @throws \Exception * @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__]); 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]));
} }
/** /**

View File

@ -10,7 +10,7 @@ use Slack\Event\AppHomeOpened;
class AppHomeOpenedListener implements ShouldQueue class AppHomeOpenedListener implements ShouldQueue
{ {
private const LOGKEY = 'LAH'; protected const LOGKEY = 'LAH';
public $queue = 'high'; public $queue = 'high';

View File

@ -9,7 +9,7 @@ use Slack\Event\MemberJoinedChannel;
class ChannelJoinListener implements ShouldQueue class ChannelJoinListener implements ShouldQueue
{ {
private const LOGKEY = 'LCJ'; protected const LOGKEY = 'LCJ';
public $queue = 'high'; public $queue = 'high';

View File

@ -9,7 +9,7 @@ use Slack\Event\{Base,ChannelLeft,GroupLeft};
class ChannelLeftListener implements ShouldQueue class ChannelLeftListener implements ShouldQueue
{ {
private const LOGKEY = 'LCL'; protected const LOGKEY = 'LCL';
public $queue = 'high'; public $queue = 'high';

View File

@ -9,7 +9,7 @@ use Slack\Interactive\InteractiveMessage;
class InteractiveMessageListener implements ShouldQueue class InteractiveMessageListener implements ShouldQueue
{ {
private const LOGKEY = 'LIM'; protected const LOGKEY = 'LIM';
public $queue = 'high'; public $queue = 'high';

View File

@ -9,7 +9,7 @@ use Slack\Event\Message;
class MessageListener implements ShouldQueue class MessageListener implements ShouldQueue
{ {
private const LOGKEY = 'LM-'; protected const LOGKEY = 'LM-';
public $queue = 'high'; public $queue = 'high';

View File

@ -9,7 +9,7 @@ use Slack\Event\PinAdded;
class PinAddedListener implements ShouldQueue class PinAddedListener implements ShouldQueue
{ {
private const LOGKEY = 'LPA'; protected const LOGKEY = 'LPA';
public $queue = 'high'; public $queue = 'high';

View File

@ -9,7 +9,7 @@ use Slack\Event\PinRemoved;
class PinRemovedListener implements ShouldQueue class PinRemovedListener implements ShouldQueue
{ {
private const LOGKEY = 'LPR'; protected const LOGKEY = 'LPR';
public $queue = 'high'; public $queue = 'high';

View File

@ -9,7 +9,7 @@ use Slack\Event\ReactionAdded;
class ReactionAddedListener implements ShouldQueue class ReactionAddedListener implements ShouldQueue
{ {
private const LOGKEY = 'LRA'; protected const LOGKEY = 'LRA';
public $queue = 'high'; public $queue = 'high';

View File

@ -10,7 +10,7 @@ use Slack\Message;
class ShortcutListener //implements ShouldQueue class ShortcutListener //implements ShouldQueue
{ {
private const LOGKEY = 'LSC'; protected const LOGKEY = 'LSC';
// Block actions arent queued, since slack expects a response to the request // Block actions arent queued, since slack expects a response to the request
//public $queue = 'high'; //public $queue = 'high';

View File

@ -9,7 +9,7 @@ use Slack\Interactive\ViewClosed;
class ViewClosedListener implements ShouldQueue class ViewClosedListener implements ShouldQueue
{ {
private const LOGKEY = 'LVC'; protected const LOGKEY = 'LVC';
public $queue = 'high'; public $queue = 'high';

View File

@ -9,7 +9,7 @@ use Slack\Interactive\ViewSubmission;
class ViewSubmissionListener implements ShouldQueue class ViewSubmissionListener implements ShouldQueue
{ {
private const LOGKEY = 'LVC'; protected const LOGKEY = 'LVC';
public $queue = 'high'; public $queue = 'high';

View File

@ -50,10 +50,12 @@ class Base extends SlackBase implements \JsonSerializable
// For interactive post responses, the channel ID is "channel" // For interactive post responses, the channel ID is "channel"
return object_get($this->_data,$key) ?: object_get($this->_data,'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 'team_id':
case 'ts': case 'ts':
case 'user_id': case 'user_id':
case 'messages': // Used by getMessageHistory()
case 'type': // Needed by URL verification case 'type': // Needed by URL verification
return object_get($this->_data,$key); return object_get($this->_data,$key);
} }

49
src/Response/Chat.php Normal file
View 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;
}
}